# google/xnnpack architecture

> Architecture diagram of the GitHub repository google/xnnpack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google/xnnpack
- Repository: https://github.com/google/xnnpack

## Overview

XNNPACK is a low-level neural-network inference library that supplies optimized operators to higher-level frameworks. A typical graph-based workflow defines tensor values and operator nodes, builds a runtime, then reshapes, sets up, and executes the selected operators to produce output tensors. The repository also contains direct operator APIs, architecture-specific kernels, weight packing, and a LiteRT tensor backend. The README documents broad operator and architecture coverage; sampled code verifies the average-pooling path, while several wider runtime links remain unverified.

Main entry points: [`include/xnnpack.h`](https://github.com/google/xnnpack/blob/master/include/xnnpack.h) (XNNPACK API), [`src/subgraph.c`](https://github.com/google/xnnpack/blob/master/src/subgraph.c) (Subgraph Definition), [`src/configs`](https://github.com/google/xnnpack/tree/master/src/configs) (Kernel Configurations), [`src/operators/average-pooling-nhwc.c`](https://github.com/google/xnnpack/blob/master/src/operators/average-pooling-nhwc.c) (Average Pooling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_api_surface["XNNPACK API<br/>[xnnpack.h]"]
  node_experimental["Experimental API<br/>[experimental.h]"]
end

subgraph group_graph["Graph Runtime"]
  node_subgraph["Subgraph Definition<br/>[subgraph.c]"]
  node_node_avgpool["Average Pool Node"]
  node_runtime["Runtime Execution<br/>[subgraph.h]"]
end

subgraph group_ops["Operator Implementations"]
  node_operator_api["Operator API<br/>[xnnpack.h]"]
  node_avgpool_impl["Average Pooling"]
  node_operator_state["Operator State<br/>[operator.h]"]
  node_operator_catalog["Operator Coverage"]
end

subgraph group_kernels["Kernels And Dispatch"]
  node_configs["Kernel Configurations"]
  node_gemm_kernels["Dense And Quantized GEMM"]
  node_sparse_kernels["Sparse Matrix Kernels"]
  node_weight_packing["Weight Packing<br/>[packing.cc]"]
end

subgraph group_integrations["Framework Integrations"]
  node_lite_tensor["LiteRT Tensor API<br/>[arithmetic.h]"]
  node_lite_xnn["LiteRT XNNPACK Backend<br/>[arithmetic.cc]"]
  node_lite_runner["LiteRT Runner<br/>[runner.cc]"]
end

node_framework(("ML Framework"))

node_framework -->|"calls library"| node_api_surface
node_framework -.->|"defines graph"| node_subgraph
node_api_surface -->|"defines nodes"| node_subgraph
node_experimental -->|"extends graph API"| node_subgraph
node_subgraph -->|"dispatches node"| node_node_avgpool
node_node_avgpool -->|"creates and sets up"| node_avgpool_impl
node_api_surface -->|"exposes operations"| node_operator_api
node_operator_api -.->|"creates and runs"| node_avgpool_impl
node_runtime -.->|"manages lifecycle"| node_operator_state
node_avgpool_impl -.->|"selects kernels"| node_configs
node_configs -.->|"dispatches kernels"| node_gemm_kernels
node_configs -.->|"dispatches kernels"| node_sparse_kernels
node_weight_packing -.->|"prepares weights"| node_gemm_kernels
node_api_surface -->|"documents operators"| node_operator_catalog
node_lite_tensor -.->|"delegates arithmetic"| node_lite_xnn
node_lite_xnn -.->|"executes backend"| node_lite_runner

click node_api_surface "https://github.com/google/xnnpack/blob/master/include/xnnpack.h"
click node_experimental "https://github.com/google/xnnpack/blob/master/include/experimental.h"
click node_subgraph "https://github.com/google/xnnpack/blob/master/src/subgraph.c"
click node_node_avgpool "https://github.com/google/xnnpack/blob/master/src/subgraph/average-pooling-2d.c"
click node_runtime "https://github.com/google/xnnpack/blob/master/src/xnnpack/subgraph.h"
click node_operator_api "https://github.com/google/xnnpack/blob/master/include/xnnpack.h"
click node_avgpool_impl "https://github.com/google/xnnpack/blob/master/src/operators/average-pooling-nhwc.c"
click node_operator_state "https://github.com/google/xnnpack/blob/master/src/xnnpack/operator.h"
click node_configs "https://github.com/google/xnnpack/tree/master/src/configs"
click node_gemm_kernels "https://github.com/google/xnnpack/blob/master/src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-8x32-minmax-neoni8mm.c"
click node_sparse_kernels "https://github.com/google/xnnpack/blob/master/src/f16-spmm/gen/f16-spmm-32x1-minmax-neonfp16arith-pipelined.c"
click node_weight_packing "https://github.com/google/xnnpack/blob/master/src/reference/packing.cc"
click node_lite_tensor "https://github.com/google/xnnpack/blob/master/litert/tensor/arithmetic.h"
click node_lite_xnn "https://github.com/google/xnnpack/blob/master/litert/tensor/backends/xnnpack/arithmetic.cc"
click node_lite_runner "https://github.com/google/xnnpack/blob/master/litert/tensor/runners/xnnpack/runner.cc"
click node_operator_catalog "https://github.com/google/xnnpack/tree/master/src/operators"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_surface,node_experimental toneBlue
class node_subgraph,node_node_avgpool,node_runtime toneAmber
class node_operator_api,node_avgpool_impl,node_operator_state,node_operator_catalog toneMint
class node_configs,node_gemm_kernels,node_sparse_kernels,node_weight_packing toneRose
class node_lite_tensor,node_lite_xnn,node_lite_runner,node_framework toneIndigo
```

## Components

### Public API

- [XNNPACK API](https://github.com/google/xnnpack/blob/master/include/xnnpack.h): `include/xnnpack.h`
- [Experimental API](https://github.com/google/xnnpack/blob/master/include/experimental.h): `include/experimental.h`

### Graph Runtime

- [Subgraph Definition](https://github.com/google/xnnpack/blob/master/src/subgraph.c): `src/subgraph.c`
- [Average Pool Node](https://github.com/google/xnnpack/blob/master/src/subgraph/average-pooling-2d.c): `src/subgraph/average-pooling-2d.c`
- [Runtime Execution](https://github.com/google/xnnpack/blob/master/src/xnnpack/subgraph.h): `src/xnnpack/subgraph.h`

### Operator Implementations

- [Operator API](https://github.com/google/xnnpack/blob/master/include/xnnpack.h): `include/xnnpack.h`
- [Average Pooling](https://github.com/google/xnnpack/blob/master/src/operators/average-pooling-nhwc.c): `src/operators/average-pooling-nhwc.c`
- [Operator State](https://github.com/google/xnnpack/blob/master/src/xnnpack/operator.h): `src/xnnpack/operator.h`
- [Operator Coverage](https://github.com/google/xnnpack/tree/master/src/operators): `src/operators`

### Kernels And Dispatch

- [Kernel Configurations](https://github.com/google/xnnpack/tree/master/src/configs): `src/configs`
- [Dense And Quantized GEMM](https://github.com/google/xnnpack/blob/master/src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-8x32-minmax-neoni8mm.c): `src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-8x32-minmax-neoni8mm.c`
- [Sparse Matrix Kernels](https://github.com/google/xnnpack/blob/master/src/f16-spmm/gen/f16-spmm-32x1-minmax-neonfp16arith-pipelined.c): `src/f16-spmm/gen/f16-spmm-32x1-minmax-neonfp16arith-pipelined.c`
- [Weight Packing](https://github.com/google/xnnpack/blob/master/src/reference/packing.cc): `src/reference/packing.cc`

### Framework Integrations

- [LiteRT Tensor API](https://github.com/google/xnnpack/blob/master/litert/tensor/arithmetic.h): `litert/tensor/arithmetic.h`
- [LiteRT XNNPACK Backend](https://github.com/google/xnnpack/blob/master/litert/tensor/backends/xnnpack/arithmetic.cc): `litert/tensor/backends/xnnpack/arithmetic.cc`
- [LiteRT Runner](https://github.com/google/xnnpack/blob/master/litert/tensor/runners/xnnpack/runner.cc): `litert/tensor/runners/xnnpack/runner.cc`

### Other components

- **ML Framework**

## Connections

- ML Framework → XNNPACK API: calls library
- ML Framework → Subgraph Definition: defines graph
- XNNPACK API → Subgraph Definition: defines nodes (evidence: `src/subgraph.c`)
- Experimental API → Subgraph Definition: extends graph API (evidence: `src/subgraph.c`)
- Subgraph Definition → Average Pool Node: dispatches node (evidence: `src/subgraph/average-pooling-2d.c`)
- Average Pool Node → Average Pooling: creates and sets up (evidence: `src/subgraph/average-pooling-2d.c`)
- XNNPACK API → Operator API: exposes operations (evidence: `include/xnnpack.h`)
- Operator API → Average Pooling: creates and runs (evidence: `src/operators/average-pooling-nhwc.c`)
- Runtime Execution → Operator State: manages lifecycle
- Average Pooling → Kernel Configurations: selects kernels
- Kernel Configurations → Dense And Quantized GEMM: dispatches kernels
- Kernel Configurations → Sparse Matrix Kernels: dispatches kernels
- Weight Packing → Dense And Quantized GEMM: prepares weights
- XNNPACK API → Operator Coverage: documents operators (evidence: `src/operators/average-pooling-nhwc.c`)
- LiteRT Tensor API → LiteRT XNNPACK Backend: delegates arithmetic
- LiteRT XNNPACK Backend → LiteRT Runner: executes backend
