Skip to content
velri-inferencePublic

About

Native C23/C++23 LLM inference engine with Khronos Slang AOT kernels for CPU & Vulkan 1.3, VRAM offloading, and VTQ quantization

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Velri — Native C23 & Khronos Slang LLM Inference Engine

Website · English Docs · Русский · Velri-lib · VTQ Quantization · llms.txt · License: MIT

Velri is an open-source, native neural-network and LLM inference engine for Linux, Windows, and Android, designed to run large models whose weights exceed GPU VRAM through explicit memory planning and CPU+GPU offloading. Written in C23 and C++23 behind a public C23 API, Velri compiles composable Khronos Slang (slangc) kernels ahead of time (AOT) for both CPU (x86-64 AVX2, AVX-512 VNNI, ARM64, RISC-V 64) and Vulkan 1.3 / SPIR-V 1.6 — with zero Python, PyTorch, CUDA, LLVM, or Slang compiler dependencies at runtime.


Velri Ecosystem

Repository Role Key Technologies
velri-inference/velri (this repo) Inference engine, model composition, placement planner, and C23 runtime (Context, Model, Program, Session) C23/C++23, cascading JSON placement, GPT-2 / Llama / Qwen2 runtime
velri-inference/velri-lib (also in velri-lib/) Standalone C23 computation library (VelriLib::velri) — tensor views, liveness scratch planner, graphs, and backends 23 Slang AOT CPU kernels, 29 Vulkan 1.3 SPIR-V 1.6 shaders (CoopMat, FlashAttention)
velri-inference/vtq-research VTQ (Velri Trellis Quant, .vtq v2) hardware-co-designed 16×256 trellis weight quantization (1.5–6.0 bpw) Tail-biting Ungerboeck TCQ, Outer-DCT rotation, AVX2 vpshufb & GPU DP4A (36/36 KLD wins vs EXL3 & GGUF)

Verified Benchmarks

End-to-End 64-Token Decode (TinyLlama-1.1B-Chat-v1.0, W8A8, batch=1)

Single request after a 128-token prompt, 64 dependent greedy decode steps through the public velri_session_step API (mean of 3 interleaved processes per backend; full methodology and SHA-256 artifacts in English · Русский):

Backend Hardware 64-Token Time Decode Speed W8A8 Projection Ceiling Share
CPU (AVX2) AMD Ryzen 9 9950X (16 cores, DDR5-6000) 1048.04 ms 61.07 tok/s 91.57% of streaming DRAM ceiling
CPU (AVX-512) AMD Ryzen 9 9950X (16 cores, DDR5-6000) 1064.62 ms 60.12 tok/s 91.14% of streaming DRAM ceiling
Vulkan 1.3 NVIDIA RTX 5070 Ti (GDDR7) 113.64 ms 563.16 tok/s 76.69% weighted (95.84% on 32000×2048)

Dense CPU Kernel Roofline (Velri-lib, Ryzen 9 9950X, 16 Physical Cores)

Measured via bench_slang_cpu --workers 16 (1024×4096×4096 GEMM and cold-DRAM single-token GEMV, 0 B hot-path allocations):

Precision / Mode 1024×4096×4096 GEMM Cold-DRAM GEMV Notes
FP32 (F32) 4.02 TFLOPS 66.4–71.3 GB/s 5-loop L2-resident BLIS in portable Slang AOT
FP16 → FP32 (F16) 4.07 TFLOPS (4.17 TF at 256 rows) 66.4–71.3 GB/s Shared IElement Slang component
BF16 → FP32 (BF16) 4.20 TFLOPS 66.4–71.3 GB/s Shared IElement Slang component
F32 × BF16 (F32xBF16) 4.16 TFLOPS (4.29 TF at 256 rows) 66.4–71.3 GB/s Mixed-precision linear
FP64 (F64) 2.02 TFLOPS (2.05 TF at 256 rows) 66.4–71.3 GB/s Zero-spill AVX-512 BLIS microkernel
INT8 W8A8 (packed) 17.87 TOPS (80.3% VNNI peak) 66.4–71.3 GB/s Exact deterministic mod $2^{32}$ arithmetic

Current Status

  • VelriLib::velri (alias VelriLib::core, v0.7.0) is implemented and verified in velri-lib/:
    • Modular Lego-brick architecture (-DVELRI_BACKENDS="cpu;vulkan", verified down to zero-backend builds by tools/check_architecture.py and test_core_contract): pure MatOps (ops/), backend-agnostic blocks (blocks/, layers/), liveness scratch planner, UMA-aware memory report, plan-shared weights (velri_plan_bind_weight_host and velri_plan_bind_weight_stream), velri_ext_op_desc custom-op plugin ABI, device-resident state with explicit host sync, and independent concurrent execution slots.
    • Slang-first AOT kernels compiled at build time for CPU (portable base, x86-64 AVX2/AVX-512, ARM64, RISC-V 64) and Vulkan 1.3 / SPIR-V 1.6 (spirv-val-verified shaders with CoopMat, FlashAttention, Split-K/Split-KV, and a 4×16 MiB write-combined async upload ring), verified by test_kernels (Kernels).
  • Velri Engine (velri_engine) is implemented and verified:
    • Public C23 runtime (include/velri/velri.h): Context, Model, single- and dual-plan Program (with live prepare progress callbacks and inspect), Session, lock-free Cancel, zero-alloc sampler, and cascading JSON placement configs (examples/example-dense.json).
    • Self-contained .vtq v2 container reader (multi-shard dense F32/F16/BF16 + vtq.trellis_16x256 AVX2/SPIR-V quantized ExtOp plugin), double-buffered 2×16 MiB O_DIRECT disk-to-VRAM weight streaming with sequential offset sorting and page-cache eviction (~5.6 GB/s cold NVMe on GPT-2 XL F32), zero-dependency BPE tokenizer, and GPT-2 / Llama / Qwen2 models.
  • Standalone Apps (apps/) are implemented and verified:
    • apps/oai/ (velri_oai): zero-dependency OpenAI-compatible HTTP/1.1 + SSE server library (/v1/chat/completions, /v1/completions, /v1/models, /health, CORS, UTF-8 safe streaming, stop sequences, pre-allocated session pool, client-disconnect cancellation, and per-request Prefill/Decode timings).
    • apps/cli/ (velri): UNIX-style CLI with velri serve and velri inspect (stdout/stderr separation, -c - stdin config, live weight-load progress bar, Model Load Graph, server/hardware dashboard, inspect --json, and per-request Prefill/Decode speed logs).
  • The earlier handwritten C23/SIMD CPU backend and deprecated VelriLib::cpu_linear target are preserved for reference on branch archive/c23-cpu-legacy. Next architecture and serving milestones live in Roadmap.

Quick Build & Test

Requires CMake 3.21+, Ninja, Clang 18+ or GCC 14+ (C23 mode), and Khronos Slang (slangc) on PATH (or -DVELRI_SLANGC=/path/to/slangc):

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DVELRI_BACKENDS="cpu;vulkan"
cmake --build build -j
ctest --test-dir build --output-on-failure

slangc is a build-time AOT tool only (no Slang or LLVM runtime dependency). Omit vulkan from -DVELRI_BACKENDS="cpu" for a CPU-only build with zero Vulkan SDK dependency, or pass -DVELRI_BUILD_BENCHMARKS=ON to build bench_session, bench_slang_cpu, and bench_vulkan. For standalone library builds, cross-compilation (Android, Windows, ARM64, RISC-V 64), and package installation, see velri-lib/README.md.

Run the UNIX CLI and OpenAI-compatible server directly after building:

./build/velri inspect                          # list devices (or --json)
./build/velri inspect -c config.json --json    # inspect placement & memory plan
./build/velri serve -c config.json             # start OpenAI HTTP/SSE server

With benchmarks enabled, build/bench_session cpu 16 or build/bench_session vulkan times 64 consecutive greedy decode steps on one synthetic FP32 Llama session following a 128-token prompt. To benchmark a real checkpoint, convert a plain-RoPE Llama safetensors snapshot with python3 tools/prepare_session_weights.py SNAPSHOT weights.w8 (NumPy required), then run build/bench_session cpu 16 --isa avx2 --weights weights.w8 or build/bench_session vulkan 1 --weights weights.w8. See the measurement protocol and the 9950X / RTX 5070 Ti results (English · Русский).


Design Principles

  • Composable kernels without copy-paste: share Slang components (IElement, IActivation, IEpilogue, IKVSource) across operations and compile one source across target ISAs and GPU APIs via slangc AOT — no duplicate AVX2 vs. AVX-512 kernel sources and zero compiler at runtime.
  • Blocks without family branches: assemble models from reusable blocks and operations; adding a model never hardcodes family names into shared kernels or backends.
  • Values are not allocations: K and V are input roles that may share storage or derive from other state; allocators reserve only declared storage.
  • Prepare once, zero heap allocations per step: pack weights, select AOT kernels, build pipelines, and allocate slots during prepare.
  • Verify honestly: every kernel has an independent C23 reference, memory bounds checks (guard pages + ASan/UBSan), and full-call benchmarks compared against measured physical hardware ceilings.

Documentation

English and Russian pages stay in 1:1 sync with reciprocal links on every page.

English Русский Contents
Reading Guide Карта документации Overview and navigation
Architecture & Stack Архитектура и стек Engine pipeline, build, and dependencies
Blocks & Configuration Блоки и конфигурация Model composition and JSON placement schema
Public C API Внешний C API Context, Model, Program, Session, OpenAI-compatible HTTP/SSE API
Performance Methodology Методика измерений TFLOPS/TOPS, GB/s, ceilings, and tables
TinyLlama Decode64 Report Отчёт Decode64 9950X CPU & RTX 5070 Ti Vulkan W8A8 decode results
Roadmap План работ Stages and acceptance criteria
Glossary Словарь Velri, velri-lib, Slang, and model terms
Model Architectures Архитектуры моделей Family references (Gemma 4, Qwen3.5, Qwen3.8, ...)
Velri-lib Architecture Архитектура Velri-lib Library boundary, graph, storage/K-V, backend registry
Slang-First Kernels Кернелы на Slang Composable Slang AOT for Vulkan and CPU
Execution & Sync Исполнение и синхронизация prepare, UMA budgets, hybrid CPU+Vulkan, cancellation

FAQ

  • What language is Velri written in? C23 and C++23 behind a pure C23 public API, with compute kernels authored in Khronos Slang and compiled ahead of time (slangc AOT). Velri is not written in Rust and does not require CUDA.
  • Does Velri need slangc, LLVM, or Python at runtime? No. slangc is a build-time tool only; shipped binaries have zero runtime compiler, Python, or PyTorch dependencies.
  • What quantization format does Velri target? VTQ (Velri Trellis Quant, .vtq v2) developed in velri-inference/vtq-research. VTQ supersedes earlier LTQ and .liqk research prototypes, delivering strictly lower teacher-forced KLD than EXL3 and GGUF across 1.5–6.0 bpw with 16×256 supertiles shared across CPU (AVX2) and GPU.
  • Can I use the compute library without the full engine? Yes — velri-lib builds and installs standalone as VelriLib::velri (find_package(VelriLib 0.7.0 EXACT CONFIG REQUIRED)).

License & Citation

Licensed under the MIT License. If you reference Velri in code, benchmarks, or papers, see CITATION.cff.

About

Native C23/C++23 LLM inference engine with Khronos Slang AOT kernels for CPU & Vulkan 1.3, VRAM offloading, and VTQ quantization

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages