How vllm-project/vllm-xpu-kernels works
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: __init__.py Tests · csrc/torch_bindings.cpp Core bindings · flash_api.cpp Attention · moe/torch_bindings.cpp MoE
Components 21
Python surface
Import and high-level Python entrypoints
- vLLM · Upstream inference stack that imports the package
- Python API · Import surface for extension loading and operator exposure
vllm_xpu_kernels/__init__.py - Flash API · Python-facing attention interface
vllm_xpu_kernels/flash_attn_interface.py - MoE API · Python-facing fused MoE interface
vllm_xpu_kernels/fused_moe_interface.py - Quant API · Python quantization conversion helpers
vllm_xpu_kernels/quantization/_quantize_convert.py
Native bridge
PyTorch registration and extension loading
- PyTorch dispatcher · Custom op registry used by vLLM at runtime
- Core bindings · Top-level C++ extension entrypoint and registration wiring
csrc/torch_bindings.cpp - Registration · Operator registration and binding declarations
csrc/core/registration.h - Ops schema · Shared operator declarations
csrc/ops.h - XPU bindings · Device-specific extension entrypoint
csrc/xpu/torch_bindings.cpp
Kernel families
Major native operator families
- Attention · Flash attention, paged decode, chunk prefill, and GDN attention
csrc/flash_attn/flash_api.cpp - MoE · TopK routing, remap, gather, and fused MoE plumbing
csrc/moe/torch_bindings.cpp - Norm + act · LayerNorm, RMSNorm, activation, and RoPE-style math
csrc/layernorm.cpp - Quant + GEMM · FP8, FP4/MxFP4, and grouped GEMM paths
csrc/quantization/fp8/fp8_quant.cpp - LoRA + misc · LoRA, sampling, cache, random, and utility kernels
csrc/xpu/lora
XPU specialization
Intel GPU-specific implementations and library backends
- XPU attention · Intel-specific attention implementations and XE2 variants
csrc/xpu/attn/attn_interface.cpp - XPU GEMM · oneDNN-backed matmul and custom grouped GEMM
csrc/xpu/onednn/onednn_runtime.cpp - XPU MoE GEMM · Grouped GEMM kernels specialized for MoE
csrc/xpu/grouped_gemm/grouped_gemm_interface.cpp - SYCL / oneDNN · Device runtime and vendor math library support
csrc/sycl_first.h
Validation
Tests and benchmarks
- Tests · Kernel parity and correctness tests
tests/__init__.py - Benchmarks · Operator-level performance benchmarking
benchmark/benchmark_layernorm.py
Connections 25
- 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