Skip to content

ggml-cpu : add Q8_0 IME1 matrix kernel for SpacemiT X60 - #28479

Merged
ggerganov merged 3 commits into
ggml-org:masterfrom
alanhc:repost-q8-ime1-v2
Oct 5, 2026
Merged

ggerganov merged 3 commits into
ggml-org:masterfrom
alanhc:repost-q8-ime1-v2

Conversation

@alanhc

@alanhc alanhc commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

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_0
had 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_0x16 and the repack entry in repack.cpp: interleave Q8_0 weights into the
    16-column layout the IME1 vmadot sequence expects.
  • ime1::gemm_kernel_i8i8 in ime1_kernels.cpp: the int8 x int8 IME1 kernel, with both 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, 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 was
    nullptr and gemm_m >= 4 was forced back through the single-row path.
  • wiring in forward_mul_mat and the repack factory for block_q8_0.
  • docs: mark Q8_0 as supported on X60.

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 4 under taskset -c 0-3, 5 repetitions, board otherwise
idle.

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-ops does not exercise this kernel on a CPU-only build: it skips the CPU
backend 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):

model before after speedup
Qwen2.5-0.5B Q8_0 10.70 t/s 95.27 t/s 8.9x

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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: the kernel code was written with the help of an AI coding agent. The commit
    message is my own; this PR description is mine, with some wording edits made with AI assistance.

@github-actions github-actions Bot added documentation Improvements or additions to documentation ggml changes relating to the ggml tensor library for machine learning labels Sep 6, 2026
@alanhc
alanhc marked this pull request as ready for review September 21, 2026 14:37
@alanhc

alanhc commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

@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.

cc @taronaeo since you reviewed #27961.

@alanhc

alanhc commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

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 CPU_RISCV64_SPACEMIT buffer, so the q8_0_16x32 repack and the MUL_MAT dispatch are covered too. Each 32-value block of A is an integer in [-127, 127] times 2^e with max |q| = 127, so the int8 quantization of A is lossless and the reference can be computed exactly in double.

  • 270/270 cases pass (K = 32..4096, N = 16/48/896, M = 1..33), worst normwise relative error 6.0e-7
  • checked with gdb that both the M1 (count_m=1) and M4 (count_m=4..16) paths of gemm_kernel_i8i8 are hit

Happy to share the test file if it's useful. The test harness was written with AI assistance, same as the kernel.

Comment thread ggml/src/ggml-cpu/spacemit/ime.cpp Resolved
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.
@alex-spacemit

Copy link
Copy Markdown
Collaborator

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

@taronaeo taronaeo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Comment thread ggml/src/ggml-cpu/spacemit/ime.cpp Resolved
@taronaeo taronaeo added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 3, 2026
@ggerganov
ggerganov merged commit 9f12cd4 into ggml-org:master Oct 5, 2026
35 of 37 checks passed
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 8, 2026
* 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)
alex-spacemit pushed a commit to spacemit-com/llama.cpp that referenced this pull request Oct 15, 2026
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]>
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 24, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants