Repository navigation
ggml-cpu : add Q8_0 IME1 matrix kernel for SpacemiT X60 - #28479
Conversation
|
@alex-spacemit this is ready for review when you have time. It adds the Q8_0 IME1 kernel for X60 (prefill 10.7 -> 95.3 t/s on Qwen2.5-0.5B, Jupiter board), and Q4_0 is unchanged. |
|
Re-ran a quant-exact correctness check on the PR head (8b519fd) on the Jupiter board. It goes through the public ggml API, with the weights in the
Happy to share the test file if it's useful. The test harness was written with AI assistance, same as the kernel. |
On the SpacemiT X60, IME matrix acceleration only covered Q4_0/Q4_1/Q4_K. Q8_0 had no IME1 kernel, and since the SpacemiT build sets GGML_CPU_REPACK=OFF there was no repack path compiled in either, so Q8_0 had no accelerated path at all and ran roughly ten times slower than Q4_0 for prefill on the same board. - add make_block_q8_0x16 and the Q8_0 repack entry: interleave the weights into the 16-column layout the IME1 vmadot sequence expects - add ime1::gemm_kernel_i8i8, an int8 x int8 IME1 kernel with a single-row and a 4-row A path; the 4-row path loads each B panel once and reuses it across 4 rows of A - add quantize_a_4row_i8 for the 4-row activation quantization - wire both into forward_mul_mat and the repack factory for Q8_0 - docs: mark Q8_0 as supported on X60 Correctness was checked against a quant-exact integer reference for K = 32 up to 4096, with a max relative error of about 1e-6, and by checking that generation stays coherent across several prompts. Tested on Milk-V Jupiter (SpacemiT X60), Bianbu 2.1.1, gcc 14.2, with Qwen2.5-0.5B-Instruct Q8_0. llama-bench -t 4 under taskset -c 0-3, 5 repetitions on an idle board: pp128 goes from 10.70 to 93.87 t/s. Q4_0 is unchanged at 106.40 -> 107.51 t/s, as expected since this does not touch that path.
a7e099d to
684dfd5
Compare
|
Reviewed this commit, and verified on a K1 dev board: the prefill speedup holds, and Qwen3-0.6B conversation quality is good with the new kernel in place. Approving and requesting merge. @ggerganov |
* ggml-cpu : add Q8_0 IME1 matrix kernel for SpacemiT X60 On the SpacemiT X60, IME matrix acceleration only covered Q4_0/Q4_1/Q4_K. Q8_0 had no IME1 kernel, and since the SpacemiT build sets GGML_CPU_REPACK=OFF there was no repack path compiled in either, so Q8_0 had no accelerated path at all and ran roughly ten times slower than Q4_0 for prefill on the same board. - add make_block_q8_0x16 and the Q8_0 repack entry: interleave the weights into the 16-column layout the IME1 vmadot sequence expects - add ime1::gemm_kernel_i8i8, an int8 x int8 IME1 kernel with a single-row and a 4-row A path; the 4-row path loads each B panel once and reuses it across 4 rows of A - add quantize_a_4row_i8 for the 4-row activation quantization - wire both into forward_mul_mat and the repack factory for Q8_0 - docs: mark Q8_0 as supported on X60 Correctness was checked against a quant-exact integer reference for K = 32 up to 4096, with a max relative error of about 1e-6, and by checking that generation stays coherent across several prompts. Tested on Milk-V Jupiter (SpacemiT X60), Bianbu 2.1.1, gcc 14.2, with Qwen2.5-0.5B-Instruct Q8_0. llama-bench -t 4 under taskset -c 0-3, 5 repetitions on an idle board: pp128 goes from 10.70 to 93.87 t/s. Q4_0 is unchanged at 106.40 -> 107.51 t/s, as expected since this does not touch that path. * ggml-cpu : move q8_0_16x32 decl to IME1 section * ggml-cpu : align q8_0 IME1 kernel assignments (cherry picked from commit 9f12cd4)
Sync 1575 upstream commits since fork point 79bba02 (2026-07-16). Highlights brought in from upstream: - MiniCPM-V 4.7 support (ggml-org#29416) and minicpmv46 downsample (ggml-org#25993) - 22 new model architectures (kimi-k3, glm5-next, qwen4exp, qwen3tts, minimax-01/m3, granite-switch, k2-horizon, ...) - mtmd refactors: internal headers, helper split, new vision/audio models - server: MCP support, decision contexts, batch_ext migration - common: chat parsers split into common/parsers/, json split - llama: load_mode AUTO + lazy_mode on-demand tensor loading - ggml-cpu spacemit upstream updates (Q8_0 IME1 ggml-org#28479, Q5_0 dispatch fix) Merge resolutions (keeping our side): - ggml-spacemit standalone backend registration (CMake, ggml-cpu.c) - GGML_BUILD_PROFILE in ggml/src/CMakeLists.txt - SMT media backend: --media-backend/--smt-config-dir args, media chunk wrapper (server_media_chunk), SMT prefill in process_mtmd_chunk, media worker routing for encode, multi-ASR service init - Kaldi fbank + LFR helpers in mtmd-audio - TTS server mode entry in llama-server main - llama-media link and server-media/server-tts sources in server CMake Merge resolutions (taking upstream): - load_mode/lazy_mode evolution (our cherry-picked older revision was superseded by upstream's final AUTO/mmap+mlock/lazy-mode design) - qwen3 pooled-embeddings LM head skip (ggml-org#30445 supersedes our guard) - upstream server_tokens serialize/deserialize, adapted to wrap server_media_chunk (SMT embd chunks throw on serialize for now) - check_no_mtmd removed (upstream removed all call sites) Co-Authored-By: Claude Code <[email protected]>
* ggml-cpu : add Q8_0 IME1 matrix kernel for SpacemiT X60 On the SpacemiT X60, IME matrix acceleration only covered Q4_0/Q4_1/Q4_K. Q8_0 had no IME1 kernel, and since the SpacemiT build sets GGML_CPU_REPACK=OFF there was no repack path compiled in either, so Q8_0 had no accelerated path at all and ran roughly ten times slower than Q4_0 for prefill on the same board. - add make_block_q8_0x16 and the Q8_0 repack entry: interleave the weights into the 16-column layout the IME1 vmadot sequence expects - add ime1::gemm_kernel_i8i8, an int8 x int8 IME1 kernel with a single-row and a 4-row A path; the 4-row path loads each B panel once and reuses it across 4 rows of A - add quantize_a_4row_i8 for the 4-row activation quantization - wire both into forward_mul_mat and the repack factory for Q8_0 - docs: mark Q8_0 as supported on X60 Correctness was checked against a quant-exact integer reference for K = 32 up to 4096, with a max relative error of about 1e-6, and by checking that generation stays coherent across several prompts. Tested on Milk-V Jupiter (SpacemiT X60), Bianbu 2.1.1, gcc 14.2, with Qwen2.5-0.5B-Instruct Q8_0. llama-bench -t 4 under taskset -c 0-3, 5 repetitions on an idle board: pp128 goes from 10.70 to 93.87 t/s. Q4_0 is unchanged at 106.40 -> 107.51 t/s, as expected since this does not touch that path. * ggml-cpu : move q8_0_16x32 decl to IME1 section * ggml-cpu : align q8_0 IME1 kernel assignments
Overview
I have a Milk-V Jupiter board and wanted Q8_0 to run properly on the SpacemiT X60. The X60 already
had IME acceleration, but only for Q4_0/Q4_1/Q4_K. Q8_0 had no IME1 kernel at all, and because the
SpacemiT build sets
GGML_CPU_REPACK=OFF, there was no repack path compiled in either — so Q8_0had no accelerated path whatsoever and ran at about a tenth of Q4_0's prefill speed on the same
board. This PR adds the missing Q8_0 IME1 kernel.
This replaces #28025, which I closed. That version was M1-only and reached 39.97 t/s prefill;
this one adds the 4-row path, which roughly doubles it again.
Additional information
Changes:
make_block_q8_0x16and the repack entry inrepack.cpp: interleave Q8_0 weights into the16-column layout the IME1
vmadotsequence expects.ime1::gemm_kernel_i8i8inime1_kernels.cpp: the int8 x int8 IME1 kernel, with both a single-rowand a 4-row A path. The 4-row path loads each B panel once and reuses it across 4 rows of A, which
is where most of the gain over the M1-only version comes from.
quantize_a_4row_i8: the 4-row activation quantization the M4 path needs. In ggml-cpu : add Q8_0 IME1 matrix kernel for SpacemiT X60 #28025 this wasnullptrandgemm_m >= 4was forced back through the single-row path.forward_mul_matand the repack factory forblock_q8_0.Testing
Milk-V Jupiter (SpacemiT X60, 8 cores / 4 preferred, RVV1.0, VLEN=256), Bianbu 2.1.1, gcc 14.2.
Qwen2.5-0.5B-Instruct,
llama-bench,-t 4undertaskset -c 0-3, 5 repetitions, board otherwiseidle.
Correctness: I compared the kernel against a quant-exact reference (dequantizing the same blocks and
doing the multiply in integer arithmetic, rather than against a float reference) for K = 32 up to
4096. Max relative error is ~1e-6, which is the expected float accumulation difference. I also
checked that generation stays coherent across several prompts.
Note that
test-backend-opsdoes not exercise this kernel on a CPU-only build: it skips the CPUbackend and reports OK, so it cannot be used to validate this change.
Performance, pp128 prefill, before and after this change on the same build settings (both with IME1
enabled, so the only variable is the kernel):
The commit message quotes another run (Q8_0 93.87 t/s, Q4_0 107.51 t/s); the difference is
run-to-run variation.
For reference, Q4_0 on the same board measures 107.81 t/s with this change applied, against 106.40 t/s
before it, i.e. unchanged within run-to-run variation, which is what I would expect since this PR
does not touch that path.
I am only claiming prefill here. Token generation does improve, but Q4_0 token generation moved by
about 1.19x between the two builds despite that path being untouched, so I do not trust the
token-generation numbers enough to quote them as a result of this change.
Requirements
message is my own; this PR description is mine, with some wording edits made with AI assistance.