Skip to content

x60: vectorize M1 int8 GEMV kernel on RVV#5

Open
hmeiland wants to merge 1 commit into
opensolvers:x60-ime-rvvfrom
hmeiland:x60-ime-rvv-m1gemv
Open

x60: vectorize M1 int8 GEMV kernel on RVV#5
hmeiland wants to merge 1 commit into
opensolvers:x60-ime-rvvfrom
hmeiland:x60-ime-rvv-m1gemv

Conversation

@hmeiland

Copy link
Copy Markdown

Summary

Replaces the pure-scalar SQ8BitGemmM1Kernel_CompInt8_ScaleFp16_Impl (the i8i8 M1 path used for <=3 remainder rows and batch=1 token generation) with an RVV-vectorized kernel.

Approach

  • Vectorizes across the 16 columns of each repacked-B group.
  • Inner loop: stride-8 int8 gather (vlse8) over the IME1 tile layout → widening vwmacc accumulation.
  • Final scale via a fused vfmacc that matches GCC's FMA-contraction of the scalar acc += a_scale*b_scale*isum, so output is bit-exact with the scalar path (non-fused mul+add drifts ~1e-4).
  • B-scales read through a small scalar (zfh) scratch to avoid a zvfh build dependency.

Verification (on X60 / SpaceMiT hardware)

  • Standalone skeleton: 9/9 shape cases bit-exact (max_abs = 0.0), RVV 9.36× faster than scalar.
  • llama-bench tg64 on qwen2.5-0.5b-q8_0: 0.82 → 5.29 t/s (6.45×).
  • llama-cli: coherent generation ("Paris is the capital of France…"), IME path active (use_ime1=1).

Risk

Behavior-preserving (bit-exact) hot-path optimization; no API/layout change. Diff is 29+/19-, single file.

Replace the pure-scalar SQ8BitGemmM1Kernel_CompInt8_ScaleFp16_Impl
(used for <=3 remainder rows and batch=1 token generation) with an
RVV kernel that vectorizes across the 16 columns of each repacked-B
group.

Inner loop uses a stride-8 int8 gather (vlse8) over the IME1 tile
layout, widening vwmacc accumulation, then a fused vfmacc that matches
GCC's FMA-contraction of the scalar 'acc += a_scale*b_scale*isum' so
results are bit-exact with the scalar path.

Verified on X60 (SpaceMiT):
- standalone skeleton: 9/9 cases bit-exact (max_abs 0.0), 9.36x faster
- llama-bench tg64 on qwen2.5-0.5b-q8_0: 0.82 -> 5.29 t/s (6.45x)
- llama-cli generation coherent (IME path, use_ime1=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant