# vllm-project/vllm-xpu-kernels architecture

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

- Interactive diagram: https://gitdiagram.com/vllm-project/vllm-xpu-kernels
- Repository: https://github.com/vllm-project/vllm-xpu-kernels

## Overview

1. **What this repository is**
   - `vllm-xpu-kernels` is a native extension package for **vLLM on Intel XPU GPUs**.
   - Its main job is to provide **PyTorch custom ops** implemented in **C++/SYCL/DPC++**, so vLLM can dispatch to Intel-specific kernels transparently at runtime.

2. **Top-level runtime boundary**
   - The Python package `vllm_xpu_kernels` is the import surface.
   - Importing it triggers native extension loading and **op registration into the PyTorch dispatcher**.
   - vLLM depends on that registration rather than calling these kernels directly, which keeps the integration boundary clean.

3. **Native extension core**
   - The `csrc/` tree contains the compiled implementation.
   - `csrc/torch_bindings.cpp`, `csrc/xpu/torch_bindings.cpp`, and the `registration.h` / `ops.h` headers are the main bridge between Python/PyTorch and native kernels.
   - This is where custom operators are exposed, typed, and wired to device-specific implementations.

4. **Kernel family breakdown**
   - The repo groups kernels by model function:
     - **Normalization:** RMSNorm, LayerNorm, fused add-RMSNorm
     - **Activation:** SiLU/mul variants, GeLU variants, Swiglu variants
     - **Attention:** flash attention, GDN attention, paged decode, chunk prefill
     - **Positional encoding:** rotary embedding and DeepSeek scaling RoPE
     - **Mixture-of-Experts:** TopK, grouped TopK, fused grouped TopK, expert remap/gather/align-sum
     - **LoRA:** expand/shrink operators
     - **Quantization/GEMM:** FP8, MxFP4, INT4, grouped GEMM
     - **Misc:** top-k per row, cache/memory utilities, sampling, random distributions

5. **Attention subsystem**
   - Attention has its own namespace under `csrc/flash_attn/` and `csrc/xpu/attn/`.
   - The repo includes both **generic attention ops** and **XPU-specific XE2 implementations** for:
     - chunk prefill
     - paged decode
     - flash attention-like paths
   - This subsystem is one of the main performance-critical boundaries, especially for prefill vs decode execution.

6. **MoE subsystem**
   - MoE support is split into scoring, routing, and tensor movement steps.
   - Files under `csrc/moe/` implement TopK selection, grouped TopK, fused prologue paths, expert mapping, hidden-state remapping, gather, and alignment helpers.
   - The structure suggests a pipeline: **score tokens → select experts → rearrange data → run expert GEMMs → gather outputs**.

7. **Quantization and GEMM**
   - Quantization code lives under `csrc/quantization/` with separate FP8 and FP4/MxFP4 paths.
   - GEMM acceleration is split between:
     - **oneDNN-backed matmul/runtime** in `csrc/xpu/onednn/`
     - **custom grouped GEMM** under `csrc/xpu/grouped_gemm/`
   - This is a key architectural boundary: some matrix ops are delegated to oneDNN, while others use custom collective/tiled kernels tuned for MoE and low-precision inference.

8. **XPU device specialization**
   - The `csrc/xpu/` subtree is the Intel-GPU-specific layer.
   - It contains device-facing implementations for attention, grouped GEMM, LoRA, sampling, random generation, rotary/scaling ops, and oneDNN integration.
   - There are separate subpaths for **`xe_2`** and **`xe_default`**, indicating architecture-specific kernel variants and compile-time dispatch.

9. **LoRA and adapter support**
   - LoRA is implemented as a native operator pair: expand and shrink.
   - This keeps adapter application in the kernel layer rather than in Python, which matters for throughput during inference.

10. **Sampling, randomness, and utility kernels**
   - The XPU subtree also includes top-k/top-p sampling, exponential/random distribution helpers, memory copy/allocation helpers, and tensor utilities.
   - These are supporting building blocks used by higher-level inference flow, not standalone features.

11. **Testing strategy**
   - `tests/` is organized by kernel family, mirroring the implementation layout.
   - Tests validate numerical correctness and parity for attention, MoE, LoRA, quantization, cache, RoPE, activation, sampling, and memory utilities.
   - The repo also includes op-level wrappers in `tests/ops/` to compare custom kernels against reference Python/Torch behavior.

12. **Benchmarks and performance validation**
   - `benchmark/` contains standalone scripts for timing individual kernels and kernel variants.
   - The benchmark harness includes helper interfaces in `benchmark/src/` and model/config utilities, showing that performance work is measured at the operator level rather than only end-to-end.

13. **Build and packaging**
   - The project is a Python package with a compiled extension, built via **setuptools/pyproject**, **CMake**, and **Ninja**.
   - `Dockerfile.xpu` and the GitHub workflows indicate a CI-driven native build/test pipeline.
   - `third_party/oneDNN` is vendored as an external dependency, reinforcing that the runtime stack is a mix of custom SYCL kernels and optimized library primitives.

14. **How to read the architecture diagram**
   - The cleanest diagram is:
     - **vLLM/Python** on the left
     - **`vllm_xpu_kernels` import and registration layer** in the middle
     - **PyTorch dispatcher** as the routing mechanism
     - **XPU native kernels** on the right, split into attention, MoE, GEMM/quantization, normalization/activation, LoRA, and utilities
   - Cross-cutting dependencies to show: **oneAPI/SYCL runtime**, **oneDNN**, and **PyTorch XPU**.

Main entry points: [`tests/__init__.py`](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/tests/__init__.py) (Tests), [`csrc/torch_bindings.cpp`](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/torch_bindings.cpp) (Core bindings), [`csrc/flash_attn/flash_api.cpp`](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/flash_attn/flash_api.cpp) (Attention), [`csrc/moe/torch_bindings.cpp`](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/moe/torch_bindings.cpp) (MoE)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_python["Python surface"]
  node_n_vllm["vLLM<br/>consumer"]
  node_n_py_pkg["Python API<br/>[__init__.py]"]
  node_n_flash_iface_py["Flash API<br/>python shim"]
  node_n_moe_iface_py["MoE API<br/>python shim"]
  node_n_quant_py["Quant API<br/>python shim"]
end

subgraph group_g_native["Native bridge"]
  node_n_dispatch(("PyTorch dispatcher<br/>runtime registry"))
  node_n_bind_core["Core bindings<br/>native bridge<br/>[torch_bindings.cpp]"]
  node_n_reg_hdr["Registration<br/>headers<br/>[registration.h]"]
  node_n_ops_hdr["Ops schema<br/>headers<br/>[ops.h]"]
  node_n_xpu_bind["XPU bindings<br/>native bridge<br/>[torch_bindings.cpp]"]
end

subgraph group_g_kernels["Kernel families"]
  node_n_attn["Attention<br/>kernel family<br/>[flash_api.cpp]"]
  node_n_moe["MoE<br/>kernel family<br/>[torch_bindings.cpp]"]
  node_n_norm_act["Norm + act<br/>kernel family<br/>[layernorm.cpp]"]
  node_n_quant_gemm["Quant + GEMM<br/>kernel family<br/>[fp8_quant.cpp]"]
  node_n_lora_misc["LoRA + misc<br/>kernel family"]
end

subgraph group_g_xpu["XPU specialization"]
  node_n_attn_xpu["XPU attention<br/>xpu backend<br/>[attn_interface.cpp]"]
  node_n_gemm_xpu["XPU GEMM<br/>xpu backend<br/>[onednn_runtime.cpp]"]
  node_n_moe_xpu["XPU MoE GEMM<br/>xpu backend"]
  node_n_sycl_rt(("SYCL / oneDNN<br/>runtime backend<br/>[sycl_first.h]"))
end

subgraph group_g_validation["Validation"]
  node_n_tests["Tests<br/>validation<br/>[__init__.py]"]
  node_n_bench["Benchmarks<br/>validation"]
end

node_n_vllm -->|"imports"| node_n_py_pkg
node_n_py_pkg -->|"loads"| node_n_bind_core
node_n_py_pkg -->|"loads"| node_n_xpu_bind
node_n_bind_core -->|"uses"| node_n_reg_hdr
node_n_bind_core -->|"uses"| node_n_ops_hdr
node_n_bind_core -->|"registers ops"| node_n_dispatch
node_n_xpu_bind -->|"registers ops"| node_n_dispatch
node_n_flash_iface_py -->|"wraps"| node_n_attn
node_n_moe_iface_py -->|"wraps"| node_n_moe
node_n_quant_py -->|"wraps"| node_n_quant_gemm
node_n_attn -->|"specializes to"| node_n_attn_xpu
node_n_attn_xpu -->|"depends on"| node_n_sycl_rt
node_n_moe -->|"specializes to"| node_n_moe_xpu
node_n_moe_xpu -.->|"shares backend"| node_n_gemm_xpu
node_n_quant_gemm -->|"uses"| node_n_gemm_xpu
node_n_gemm_xpu -->|"depends on"| node_n_sycl_rt
node_n_norm_act -.->|"runs on"| node_n_sycl_rt
node_n_lora_misc -.->|"runs on"| node_n_sycl_rt
node_n_tests -->|"validates"| node_n_attn
node_n_tests -->|"validates"| node_n_moe
node_n_tests -->|"validates"| node_n_quant_gemm
node_n_tests -->|"validates"| node_n_lora_misc
node_n_bench -->|"measures"| node_n_attn
node_n_bench -->|"measures"| node_n_moe
node_n_bench -->|"measures"| node_n_quant_gemm

click node_n_py_pkg "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/vllm_xpu_kernels/__init__.py"
click node_n_flash_iface_py "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/vllm_xpu_kernels/flash_attn_interface.py"
click node_n_moe_iface_py "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/vllm_xpu_kernels/fused_moe_interface.py"
click node_n_quant_py "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/vllm_xpu_kernels/quantization/_quantize_convert.py"
click node_n_bind_core "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/torch_bindings.cpp"
click node_n_reg_hdr "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/core/registration.h"
click node_n_ops_hdr "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/ops.h"
click node_n_xpu_bind "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/xpu/torch_bindings.cpp"
click node_n_attn "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/flash_attn/flash_api.cpp"
click node_n_moe "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/moe/torch_bindings.cpp"
click node_n_norm_act "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/layernorm.cpp"
click node_n_quant_gemm "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/quantization/fp8/fp8_quant.cpp"
click node_n_lora_misc "https://github.com/vllm-project/vllm-xpu-kernels/tree/main/csrc/xpu/lora"
click node_n_attn_xpu "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/xpu/attn/attn_interface.cpp"
click node_n_gemm_xpu "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/xpu/onednn/onednn_runtime.cpp"
click node_n_moe_xpu "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/xpu/grouped_gemm/grouped_gemm_interface.cpp"
click node_n_sycl_rt "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/sycl_first.h"
click node_n_tests "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/tests/__init__.py"
click node_n_bench "https://github.com/vllm-project/vllm-xpu-kernels/blob/main/benchmark/benchmark_layernorm.py"

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_n_vllm,node_n_py_pkg,node_n_flash_iface_py,node_n_moe_iface_py,node_n_quant_py toneBlue
class node_n_dispatch,node_n_bind_core,node_n_reg_hdr,node_n_ops_hdr,node_n_xpu_bind toneAmber
class node_n_attn,node_n_moe,node_n_norm_act,node_n_quant_gemm,node_n_lora_misc toneMint
class node_n_attn_xpu,node_n_gemm_xpu,node_n_moe_xpu,node_n_sycl_rt toneRose
class node_n_tests,node_n_bench toneIndigo
```

## Components

### Python surface

Import and high-level Python entrypoints

- **vLLM**: consumer · Upstream inference stack that imports the package
- [Python API](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/vllm_xpu_kernels/__init__.py): package · Import surface for extension loading and operator exposure · `vllm_xpu_kernels/__init__.py`
- [Flash API](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/vllm_xpu_kernels/flash_attn_interface.py): python shim · Python-facing attention interface · `vllm_xpu_kernels/flash_attn_interface.py`
- [MoE API](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/vllm_xpu_kernels/fused_moe_interface.py): python shim · Python-facing fused MoE interface · `vllm_xpu_kernels/fused_moe_interface.py`
- [Quant API](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/vllm_xpu_kernels/quantization/_quantize_convert.py): python shim · Python quantization conversion helpers · `vllm_xpu_kernels/quantization/_quantize_convert.py`

### Native bridge

PyTorch registration and extension loading

- **PyTorch dispatcher**: runtime registry · Custom op registry used by vLLM at runtime
- [Core bindings](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/torch_bindings.cpp): native bridge · Top-level C++ extension entrypoint and registration wiring · `csrc/torch_bindings.cpp`
- [Registration](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/core/registration.h): headers · Operator registration and binding declarations · `csrc/core/registration.h`
- [Ops schema](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/ops.h): headers · Shared operator declarations · `csrc/ops.h`
- [XPU bindings](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/xpu/torch_bindings.cpp): native bridge · Device-specific extension entrypoint · `csrc/xpu/torch_bindings.cpp`

### Kernel families

Major native operator families

- [Attention](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/flash_attn/flash_api.cpp): kernel family · Flash attention, paged decode, chunk prefill, and GDN attention · `csrc/flash_attn/flash_api.cpp`
- [MoE](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/moe/torch_bindings.cpp): kernel family · TopK routing, remap, gather, and fused MoE plumbing · `csrc/moe/torch_bindings.cpp`
- [Norm + act](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/layernorm.cpp): kernel family · LayerNorm, RMSNorm, activation, and RoPE-style math · `csrc/layernorm.cpp`
- [Quant + GEMM](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/quantization/fp8/fp8_quant.cpp): kernel family · FP8, FP4/MxFP4, and grouped GEMM paths · `csrc/quantization/fp8/fp8_quant.cpp`
- [LoRA + misc](https://github.com/vllm-project/vllm-xpu-kernels/tree/main/csrc/xpu/lora): kernel family · LoRA, sampling, cache, random, and utility kernels · `csrc/xpu/lora`

### XPU specialization

Intel GPU-specific implementations and library backends

- [XPU attention](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/xpu/attn/attn_interface.cpp): xpu backend · Intel-specific attention implementations and XE2 variants · `csrc/xpu/attn/attn_interface.cpp`
- [XPU GEMM](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/xpu/onednn/onednn_runtime.cpp): xpu backend · oneDNN-backed matmul and custom grouped GEMM · `csrc/xpu/onednn/onednn_runtime.cpp`
- [XPU MoE GEMM](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/xpu/grouped_gemm/grouped_gemm_interface.cpp): xpu backend · Grouped GEMM kernels specialized for MoE · `csrc/xpu/grouped_gemm/grouped_gemm_interface.cpp`
- [SYCL / oneDNN](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/csrc/sycl_first.h): runtime backend · Device runtime and vendor math library support · `csrc/sycl_first.h`

### Validation

Tests and benchmarks

- [Tests](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/tests/__init__.py): validation · Kernel parity and correctness tests · `tests/__init__.py`
- [Benchmarks](https://github.com/vllm-project/vllm-xpu-kernels/blob/main/benchmark/benchmark_layernorm.py): validation · Operator-level performance benchmarking · `benchmark/benchmark_layernorm.py`

## Connections

- vLLM → Python API: imports · vLLM consumes the Python package as its integration boundary
- Python API → Core bindings: loads · Import triggers native extension loading
- Python API → XPU bindings: loads · Python package also exposes XPU-specific extension entrypoints
- Core bindings → Registration: uses · Core extension relies on registration declarations
- Core bindings → Ops schema: uses · Core extension shares operator schemas
- Core bindings → PyTorch dispatcher: registers ops · Custom ops are registered into the PyTorch dispatcher
- XPU bindings → PyTorch dispatcher: registers ops · Device-specific implementations are also dispatcher-registered
- Flash API → Attention: wraps · Python attention API forwards to native kernels
- MoE API → MoE: wraps · Python MoE API forwards to native kernels
- Quant API → Quant + GEMM: wraps · Python quantization helpers support native quantization paths
- Attention → XPU attention: specializes to · Attention has Intel XPU-specific backends and XE2 variants
- XPU attention → SYCL / oneDNN: depends on · Attention kernels rely on SYCL runtime support
- MoE → XPU MoE GEMM: specializes to · MoE uses custom grouped GEMM on XPU
- XPU MoE GEMM → XPU GEMM: shares backend · MoE grouped GEMM sits alongside broader XPU GEMM support
- Quant + GEMM → XPU GEMM: uses · Low-precision GEMM paths delegate to XPU math backends
- XPU GEMM → SYCL / oneDNN: depends on · GEMM implementations depend on SYCL and oneDNN runtime support
- Norm + act → SYCL / oneDNN: runs on · Normalization and activation kernels are device-executed native ops
- LoRA + misc → SYCL / oneDNN: runs on · Supporting kernels use the same XPU runtime layer
- Tests → Attention: validates · Tests cover attention correctness and parity
- Tests → MoE: validates · Tests cover MoE routing and gather paths
- Tests → Quant + GEMM: validates · Tests cover quantization and GEMM behavior
- Tests → LoRA + misc: validates · Tests cover LoRA and utility kernels
- Benchmarks → Attention: measures · Benchmarks time attention variants
- Benchmarks → MoE: measures · Benchmarks time routing and fused MoE kernels
- Benchmarks → Quant + GEMM: measures · Benchmarks time quantized matmul and GEMM paths
