quant.cpp
quant.cpp copied to clipboard
Add ARM SVE backend stub
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.cwith 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.
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_SVEis defined), SVE feature detection intq_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.