quant.cpp icon indicating copy to clipboard operation
quant.cpp copied to clipboard

Add ARM SVE backend stub

Open unamedkr opened this issue 7 months ago • 1 comments

The CPU backend (src/backend/cpu/) has optimized paths for NEON and AVX2, but no SVE (Scalable Vector Extension) support. SVE is needed for AWS Graviton3/4 and other modern ARM servers.

What to do:

  • Create src/backend/cpu/tq_sve.c with stub implementations of the key kernel functions (quantize, dequantize, dot product).
  • Each stub should simply call the existing generic C fallback — this sets up the scaffolding for future SVE intrinsics.
  • Add SVE feature detection in the backend dispatch logic and wire up the stubs.
  • Guard with #if defined(__ARM_FEATURE_SVE).

Files to touch: src/backend/cpu/tq_sve.c (new), src/backend/cpu/tq_dispatch.c or equivalent dispatch file.

unamedkr avatar Apr 03 '26 14:04 unamedkr

Added ARM SVE backend stub:

  • src/backend/cpu/tq_sve.c (new): Stub implementations for all 6 kernel functions (uniform_4b quantize/dequantize, polar quantize/dequantize, qjl quantize/attention). Each delegates to the generic reference implementation, ready for SVE intrinsic optimization.
  • src/backend/cpu/tq_cpu_dispatch.c: SVE dispatch registration (takes priority over NEON when __ARM_FEATURE_SVE is defined), SVE feature detection in tq_get_dispatch_backend().
  • Guarded by #if defined(__ARM_FEATURE_SVE) — no impact on non-SVE builds.
  • CMake auto-discovers via file(GLOB src/backend/cpu/*.c).

To add real SVE kernels: replace the _ref() calls in tq_sve.c with svptrue/svld1/svmin/svmax/svcompact intrinsics.

unamedkr avatar Apr 12 '26 03:04 unamedkr