ISARef Multi-ISA & Silicon Reference
45,419 ISA items · 105,907 timings · 913 microarchs · 15,555 chips · 105 sources
Arch:
Tier:

ANE XPC Daemon (aned) & Descriptors

T3 apple-ane guide guide
Apple ANE XPC Daemon (aned), Entitlements & Attention Descriptors (mdaiter/ane)
SourceApple ANE Private APIs, MIL & Custom Training Graphs (maderix/ANE + mdaiter/ane) (apple_ane_maderix)
Reliability TierT3 — Hardware-Verified
ISA / Silicon ScopeApple Silicon M1–M4 (macOS ANE stack)
Apple Silicon M1–M4 macOS/iOS ANE
License & VersionMIT
main
Upstreamhttps://github.com/maderix/ANE
Note: Documents undocumented private macOS AppleNeuralEngine.framework, aned XPC, and MIL compiler internals.

Summary

Reverse engineering artifacts for Apple's Neural Engine stack: ANECompiler, Espresso, and AppleNeuralEngine frameworks.

Syntax / Encoding

_ANEClient / _ANECompiler / aned / MIL

Reference Notes

# Apple Neural Engine (ANE) Reverse Engineering

Reverse engineering artifacts for Apple's Neural Engine stack: **ANECompiler**, **Espresso**, and **AppleNeuralEngine** frameworks.

> **Target Audience**: Performance engineers and security researchers working with Apple silicon ML acceleration.

## Table of Contents

- [Key Findings](#key-findings)
- [Architecture Overview](#architecture-overview)
- [Repository Structure](#repository-structure)
- [Espresso Engine Teardown](#espresso-engine-teardown)
- [Compiler Engine Teardown](#compiler-engine-teardown)
- [ANE Runtime Details](#ane-runtime-details)
- [Security Analysis](#security-analysis)
- [Performance Analysis](#performance-analysis)
- [Example Runthrough](#example-runthrough)
- [Comprehensive Reference](#comprehensive-reference)

---

## Key Findings

| Discovery | Details | Significance |
|-----------|---------|--------------|
| **SDPA Layer** | `ANECSDPALayerDesc` is only 8 bytes | Native transformer attention in ANE hardware |
| **40+ Optimization Passes** | `Pass_fuse_conv_batchnorm`, `Pass_fold_constants`, etc. | Full Espresso compiler pipeline discoverable |
| **XPC Daemon Architecture** | `aned` at `/usr/libexec/aned` | Privilege boundary for ANE access |
| **Entitlement Bypass** | Struct init functions work without signing | Can probe all layer descriptor layouts |
| **PBZE Format** | LZFSE-compressed espresso.net | System models decodable with libcompression |
| **Silent Failures** | `compileModel:` returns NULL without error | Operations fail silently without entitlements |
| **IOSurface Memory** | `EspressoANEIOSurface` (21 methods) | Zero-copy tensor sharing with Metal |
| **Quantization Modes** | `quantization_mode:2` on inner_product | ANE-specific quantization discovered |
| **CoreML ANE Path** | `MLComputeUnitsAll` enables ANE | Working path for ANE execution via public API |
| **HWX Binary Format** | Magic `0xBEEFFACE`, Mach-O-like | Pre-compiled ANE instructions per chip generation |
| **16 ANE Cores** | M3 Pro has 16 neural engine cores | Confirmed via `MLNeuralEngineComputeDevice` |

### Quick Reference: What Works Without Entitlements

| Operation | Works? | Notes |
|-----------|--------|-------|
| Load ANECompiler.framework | Yes | All frameworks load |
| Call `ANEC*Initialize()` | Yes | Can probe struct sizes |
| Create `EspressoContext` (CPU) | Yes | Platform 0 works |
| Load `EspressoNetwork` | Yes | CPU inference works |
| Create `_ANEClient` | Yes | Object created but... |
| Call `compileModel:` | No | Returns NULL silently |
| Call `loadModel:` | No | Returns NULL silently |
| ANE inference | No | Requires entitlements |
| **CoreML with ANE** | **Yes** | **Use `MLComputeUnitsAll` - working path!** |
| **XPC to aned** | Yes | Connection succeeds, ops need entitlements |
| **MLComputePlan** | Yes | Can inspect device availability |

---

## Architecture Overview

```
┌─────────────────────────────────────────────────────────────────┐
│                       User Application                           │
│                  (Core ML, Create ML, BNNS)                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  ┌─────────────────────────┐    ┌─────────────────────────────┐ │
│  │   Espresso.framework    │    │ AppleNeuralEngine.framework │ │
│  │   ─────────────────     │    │ ─────────────────────────── │ │
│  │  • EspressoContext      │    │  • _ANEClient               │ │
│  │  • EspressoNetwork      │    │  • _ANEModel                │ │
│  │  • 40+ Pass_* classes   │    │  • _ANERequest              │ │
│  │  • CPU/GPU/ANE dispatch │    │  • _ANEDaemonConnection     │ │
│  └───────────┬─────────────┘    └──────────────┬──────────────┘ │
│              │                                  │                │
├──────────────┴──────────────────────────────────┴────────────────┤
│                     ANECompiler.framework                        │
│                     ─────────────────────                        │
│  • ANECConvLayerDesc (176 bytes)    • ANECSDPALayerDesc (8 bytes)│
│  • ANECPoolLayerDesc (96 bytes)     • ANECLinearLayerDesc (64 B) │
│  • ANECTensorDims (40 bytes)        • 30+ layer descriptors      │
├─────────────────────────────────────────────────────────────────┤
│                    XPC Transport Layer                           │
│            Service: com.apple.appleneuralengine                  │
├─────────────────────────────────────────────────────────────────┤
│                    aned (/usr/libexec/aned)                      │
│                    ───────────────────────                       │
│  • ANEProgramCreate()          • Model cache management          │
│  • ANEProgramInstanceCreate()  • Garbage collection              │
│  • Sandbox extension handling  • Telemetry                       │
├─────────────────────────────────────────────────────────────────┤
│                    ANE Hardware (M1/M2/M3+)                      │
│                    ───────────────────────                       │
│  • 16 neural engine cores      • Dedicated SRAM                  │
│  • Up to 15.8 TOPS (M1)        • IOSurface DMA                   │
└─────────────────────────────────────────────────────────────────┘
```

### Data Flow: Model Compilation

```
.mlmodelc/                      aned daemon                 Hardware
────────────                    ───────────                 ────────
     │                               │                          │
     │  1. _ANEModel create          │                          │
     ├──────────────────────────────►│                          │
     │                               │                          │
     │  2. compileModel: (XPC)       │                          │
     ├──────────────────────────────►│                          │
     │                               │  3. ANECompiler          │
     │                               ├─────────────────────────►│
     │                               │                          │
     │                               │  4. ANEProgramCreate()   │
     │                               ├─────────────────────────►│
     │                               │                          │
     │  5. Return program handle     │                          │
     │◄──────────────────────────────┤                          │
     │                               │                          │
     │  6. loadModel: (XPC)          │                          │
     ├──────────────────────────────►│                          │
     │                               │  7. Map to ANE memory    │
     │                               ├─────────────────────────►│
     │                               │                          │
     │  8. evaluateWithModel:        │  9. Execute on ANE       │
     ├──────────────────────────────►├─────────────────────────►│
     │                               │                          │
```

---

## Repository Structure

```
ane/
├── __init__.py          # Package exports, builds API tree for tooling
├── compiler.py          # ANECompiler.framework ctypes bindings
│                        #   - Layer descriptor structs
│                        #   - ANEC*Initialize() wrappers
│                        #   - Struct size probing
│
├── espresso.py          # Espresso model format parser
│                        #   - EspressoNet, EspressoLayer classes
│                        #   - Layer type documentation
│                        #   - CPU vs ANE model comparison
│
├── runtime.py           # Espresso/ANE runtime bindings
│                        #   - EspressoContext creation
│                        #   - EspressoNetwork loading
│                        #   - ObjC class introspection
│
├── xpc.py               # ANE XPC protocol documentation
│                        #   - _ANEDaemonConnection methods
│                        #   - _ANEClient methods
│                        #   - XPC operation categories
│
├── pbze.py              # PBZE (compressed espresso.net) decoder
│                        #   - LZFSE decompression via libcompression
│                        #   - Header parsing
│                        #   - Compression statistics
│
├── sample.py            # Example graph building code
│                        #   - SimpleANEGraph class
│                        #   - CNN and Transformer examples
│
├── tests/
│   └── test_ane.py      # Comprehensive pytest suite (623 lines)
│
└── helper/
    ├── ane_helper.m     # Objective-C helper for privileged ANE access
    ├── ane_helper.entitlements
    └── build.sh         # Build script
```

---

## Espresso Engine Teardown

Espresso is Apple's internal ML inference runtime that powers Core ML. It handles model execution across CPU, GPU, and ANE.

### Model Format (`.espresso.net`)

Two formats exist:

1. **JSON** (human-readable):
```json
{
  "format_version": 200,
  "storage": "model.espresso.weights",
  "layers": [
    {
      "name": "conv1",
      "type": "convolution",
      "bottom": "input",
      "top": "conv1_output",
      "kernel_size": 3,
      "stride": 1,
      "pad": 1,
      "C": 64
    }
  ],
  "analyses": {},
  "properties": {}
}
```

2. **PBZE** (binary, LZFSE-compressed):
```
Offset  Size  Description
──────  ────  ───────────
0x00    4     Magic: b'pbze'
0x04    4     Version (usually 0)
0x08    8     Unknown (header size?)
0x10    4     Uncompressed size (BIG ENDIAN!)
0x14    4     Unknown
0x18    4     Padding
0x1C    ...   LZFSE data (starts with b'bvx2')
```

### Layer Types

#### Compute Layers

| Type | Description | Key Attributes |
|------|-------------|----------------|
| `inner_product` | Dense/fully-connected | `nB`, `nC`, `quantization_mode`, `is_lookup`, `has_biases` |
| `convolution` | 2D convolution | `kernel_size`, `stride`, `pad`, `C`, `groups` |
| `batch_matmul` | Batched matrix multiply | `transpose_a`, `transpose_b` |
| `elementwise` | Binary/unary operations | `operation` (see operation codes below) |
| `activation` | Nonlinearities | `type` (relu, gelu, tanh, sigmoid, etc.) |
| `softmax` | Softmax normalization | `axis` |
| `reduce` | Reduction operations | `mode` (sum, mean, max, min, prod) |

#### Memory/Shape Layers

| Type | Description | Key Attributes |
|------|-------------|----------------|
| `reshape` | Tensor reshape | `shape` |
| `transpose` | Permute dimensions | `axes` |
| `concat` | Concatenate tensors | `axis` |
| `general_concat` | N-D concatenation | `axis`, flexible inputs |
| `split_nd` | Split along axis | `axis`, `num_splits` or `split_sizes` |
| `general_slice` | Slice tensor | `starts`, `ends`, `strides` |
| `expand_dims` | Add dimension | `axes` |
| `load_constant` | Load constant tensor | `blob_weights` |

#### Quantization Layers

| Type | Description | Notes |
|------|-------------|-------|
| `dynamic_quantize` | Runtime quantization | Converts FP to INT8 |
| `dynamic_dequantize` | Runtime dequantization | Converts INT8 to FP |

#### Special Layers

| Type | Description |
|------|-------------|
| `instancenorm_1d` | Instance normalization |
| `get_shape` | Returns tensor shape |
| `nonzero` | Find nonzero indices |
| `scatter_nd` | Scatter operation |
| `tile` | Tile/repeat tensor |

### Elementwise Operation Codes

```
Code   Operation          Code   Operation
────   ─────────          ────   ─────────
0      add                25     pow
1      sub                26     exp
2      mul                27     log
3      div                28     abs
4      floor_div          
                          101    select (ternary: a ? b : c)
10     max                105    less_than
11     min                106    less_equal
                          107    not_equal
20     sqrt               108    equal
21     rsqrt              109    greater_equal
22     square             110    greater_than
23     neg                
24     reciprocal         117    floor