Files
leleka/docs/upstream-ggml.md
T
Pavlo RatushnyiandClaude Sonnet 5.5 c1444d98ac perf: run the CPU kernels from Rust std::arch instead of C (STRA-214)
The MXFP4, Q8_0, int8 and int4 kernels, the Q8_0 quantizer and the half conversions are now Rust
(cpu-sys/src/simd.rs), written operation for operation after the C versions. The C code stays only behind
the test-only feature c-reference, and tests/rust_vs_c.rs checks bit-identical results at the portable,
AVX2 and AVX-VNNI levels. A runtime build compiles no C.

Paired decode on gpt-oss-20b (40 tokens, 10 threads, 5 alternating rounds): median 98 ms per token for
both builds, identical tokens and first-step log-probabilities.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 18:32:31 +02:00

4.5 KiB

ggml / llama.cpp upstream use in the CPU runtime (STRA-211)

ggml (the tensor library of llama.cpp, MIT) is an upstream source and a test oracle for the Leleka CPU runtime. It is not a dependency: no runtime build compiles, links or loads it. The pin below is the one that already exists in this repository; this file adds no new download.

Pin

Field Value
Upstream ggml-org/llama.cpp, directory ggml/
Commit 3cf03257f219afbe7334045ff7c6a06ac68c627d (the same commit the imported Strata engine pins)
Licence MIT, copyright 2023-2026 The ggml authors
Local copy control-plane/third_party/ggml/ (unmodified files, hashes in its SHA256SUMS, provenance in its UPSTREAM.md)

Files the CPU runtime's tests use

They are compiled only when the ggml-oracle feature of leleka-cpu-sys is on (a dev-dependency of leleka-cpu-kernels), together with four stub functions in crates/cpu-sys/csrc/ggml_oracle.c that stand in for ggml.c.

File SHA-256 (from SHA256SUMS) Used for
ggml-quants.c 07143d7068936ae46b3c528b2f3d4bbb666e74d88992165716174d243573965d dequantize_row_mxfp4, dequantize_row_q8_0, quantize_row_mxfp4_ref, quantize_row_q8_0_ref
ggml-quants.h 28ae5fca1f3be636b36cd6c4fa2ca74fd42d229bfbd5352eaf66f3727bb8a6da declarations
ggml-common.h 0061131b615c5721fc88a78feeb22c1f8c450f1c2646a317d80796a653bf595c block_mxfp4, block_q8_0, kvalues_mxfp4
ggml-impl.h 43564db0238aebb7ed68501e346c194866b5dac218d1d37b26baff9f458c00d3 ggml_e8m0_to_fp32_half
ggml.h 12ee71f99db7db9b353bc02b1fbb57c344ee17c01ac5fb7952b41a637a747ea9 type enum and declarations

Port ledger

Leleka file Upstream relation Oracle and result
crates/cpu-sys/csrc/leleka_mx.h Table kvalues_mxfp4 and the E8M0 half-scale rule are the values and rule defined in ggml-common.h and ggml-impl.h; the half-to-float conversion is written here The table is read back from ggml in the tests (ggml_kvalues); all 256 E8M0 codes and all non-NaN, finite half scales are compared exactly with ggml
crates/cpu-sys/csrc/mxfp4_scalar.c Written for Leleka after ggml's published format and its generic dot loop; not a copy Per-block integer sums equal a naive integer computation; float result within the stated tolerance of an f64 reference built from ggml's dequantizers
crates/cpu-sys/csrc/mxfp4_avx2.c, mxfp4_avxvnni.c Same algorithm family as ggml's x86 vec_dot for MXFP4 x Q8_0 (nibble split, byte shuffle through the table, abs/sign multiply). ggml's own x86 kernel file (ggml-cpu/arch/x86/quants.c) is NOT vendored and was not read for this port Same tests, at every level the host has

| crates/cpu-sys/csrc/q8_scalar.c, q8_avx2.c, q8_avxvnni.c | Q8_0 block format and the rule scale = amax / 127, quant = round(x / scale) are ggml's; the SIMD structure (max-abs scan, round to nearest even, saturating packs, lane fix-up, abs/sign multiply) follows the algorithm family of ggml's x86 quantizer and vec_dot. Written for Leleka; ggml's x86 files were not read or vendored | Quantizer: every level bit-identical to scalar; equal to ggml's portable reference (scale exactly, quants except on exact .5 ties, where ggml's reference rounds away from zero and llama.cpp's x86 SIMD path rounds to even, as this quantizer does). Dot: per-block integer sums exact; float within the stated tolerance | | crates/cpu-sys/csrc/leleka_mx.h leleka_f32_to_f16 | Float to half, round to nearest even, after the public-domain float_to_half_rtne method | Equal to the F16C instruction on every half value, its midpoints and neighbours, and 400,000 random floats |

Since 2026-10-14 the rows above describe the first (C) implementation. The runtime runs the Rust port in crates/cpu-sys/src/simd.rs, which is bit-identical to it (crates/cpu-sys/tests/rust_vs_c.rs, feature c-reference), so the oracle results above carry over; the ggml-oracle tests in crates/cpu-kernels/tests were rerun against the Rust kernels and pass. The half-to-float conversion, kvalues_mxfp4 and the E8M0 rule are now simd::f16_to_f32, simd::KVALUES_MXFP4 and simd::e8m0_half.

Not claimed: bit-identical float results to llama.cpp's SIMD kernels. The integer block sums are exact; the float combination order differs, and the tests state the tolerance (blocks + 16) x 2^-23 x sum of absolute terms.

Revision history

Date Change
2026-10-14 First record (STRA-211, slice 1: MXFP4 x Q8_0 dot).