Skip to content

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

Closed
alanhc wants to merge 1 commit into
ggml-org:masterfrom
alanhc:feat-spacemit-ime1-q8_0-pr
Closed

alanhc wants to merge 1 commit into
ggml-org:masterfrom
alanhc:feat-spacemit-ime1-q8_0-pr

Conversation

@alanhc

@alanhc alanhc commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Overview

I have a Milk-V Jupiter board and wanted to add a Q8_0 matrix-multiply kernel for the SpacemiT X60 (IME1). The X60 already had IME acceleration, but only for Q4_0/Q4_1/Q4_K — Q8_0 fell back to the generic scalar path. This PR adds the missing Q8_0 IME1 kernel, giving ~3.7x faster prefill.

Additional information

Changes:

  • make_block_q8_0x16 + repack: interleave Q8_0 weights into the layout the IME1 vmadot sequence expects.
  • ime1::gemm_kernel_i8i8: an int8 x int8 IME1 kernel.
  • wiring in forward_mul_mat and the repack factory for block_q8_0.
  • docs: mark Q8_0 as supported on X60.

Limitation: this is an M1-only kernel. For gemm_m >= 4, A activations are forced through the single-row quantization path (quantize_a_4row_i8 = nullptr). A dedicated M4 kernel is a planned follow-up.

Depends on #27961 — without that build fix, the SpacemiT backend does not compile on gcc < 15.

Tested on Milk-V Jupiter (SpacemiT X60), gcc 14.2, Qwen2.5-0.5B-Q8_0, -t 4 (taskset -c 0-3):

test before (scalar) after (IME1)
pp128 10.71 t/s 39.97 t/s
tg64 6.63 t/s 9.96 t/s

Output is correct, e.g. "The capital of France is Paris."

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: The code was written with the help of an AI coding agent. I wrote this PR description and the commit message myself.

On the SpacemiT X60, the IME matrix acceleration only covered
Q4_0/Q4_1/Q4_K. Q8_0 fell back to the generic scalar path, which is much
slower for prefill. This adds an IME1 Q8_0 kernel so Q8_0 also uses the
matrix engine.

- add make_block_q8_0x16: interleave Q8_0 weights into the layout the
  IME1 vmadot sequence expects
- add ime1::gemm_kernel_i8i8: an int8 x int8 IME1 kernel
- wire it into forward_mul_mat / the repack factory for Q8_0

This is an M1-only kernel for now. For gemm_m >= 4 the A activations are
forced through the single-row quantization path
(quantize_a_4row_i8 = nullptr); an M4 kernel is left as a follow-up.

Tested on Milk-V Jupiter (SpacemiT X60), gcc 14.2, Qwen2.5-0.5B Q8_0:
output is correct, and llama-bench (-t 4) improves from
pp128 10.7 -> 40.0 t/s and tg64 6.6 -> 10.0 t/s.
@github-actions github-actions Bot added documentation Improvements or additions to documentation ggml changes relating to the ggml tensor library for machine learning labels Aug 30, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Aug 30, 2026

Copy link
Copy Markdown

Hi @alanhc, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.

  • AI-generated content: While code is allowed to be generated by AI, please write the PR description and commit messages on your own without the help of AI.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant