build: Linux/aarch64 branch in the Makefile — probe DOTPROD/I8MM instead of trusting native (#631) - #755
Conversation
…'t trust native (JustVugg#631) On Linux ARM the Makefile fell through to the x86-64 else: -march=native on a gcc that doesn't know the core (gcc 13 vs Cortex-X925) silently degrades to plain armv8-a, the SDOT/SMMLA int8-int4 kernels compile out, and int4 S=1 decode lands on the f32 fallback (g_i4s=2 without DOTPROD). New branch, default ARCH=native: keep -mcpu=native if it already defines __ARM_FEATURE_MATMUL_INT8; otherwise re-add the features /proc/cpuinfo reports (asimddp -> +dotprod, i8mm -> +i8mm) as -march=armv8-a+..., kept only if the compiler accepts the modifiers (gcc < 10 has no +i8mm), else fall back to -mcpu=native with a warning. Explicit ARCH= respected: armv* -> -march, core names -> -mcpu, same convention as the Darwin branch. GB10 default build: 0 -> 22 smmla, banner idot: neon-i8mm, int4 S=1 decode kernel ~2.5x. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Merging. This is a good catch on a failure mode that is worse than being slow: it is being slow silently.
What I checked:
Reading Nice first contribution, and thank you for the datapoints on #165 as well. If you have the GB10 in front of you, a before/after |
Problem
#631 reported it precisely: on Linux/aarch64 there is no dedicated branch in
c/Makefile, so ARM falls through to the x86-64elseand gets-march=native. On a gcc that does not recognise the core — gcc 13.3 vsCortex-X925 on a DGX Spark GB10, but any gcc older than its silicon qualifies —
nativesilently degrades to plainarmv8-a: neither__ARM_FEATURE_DOTPRODnor
__ARM_FEATURE_MATMUL_INT8is defined, the SDOT/SMMLA int8-int4 kernelscompile out with no warning, and the banner reads
idot: neon.The nastiest part is quiet: without
DOTPROD,g_i4sinitialises to 2(
c/quant.h:531-541), so theS>=g_i4sgate atc/colibri.c:883sendsint4 S=1 decode — the token-generation hot path — to the f32 fallback.
-mcpu=nativewould not help: as #631's table shows, it degrades identicallyon this toolchain, so extending the Darwin branch's approach to Linux is not
enough.
Fix
A Linux/*BSD aarch64 branch next to the PowerPC one. For the default
ARCH=nativeit probes the compiler once:-mcpu=nativealready defines__ARM_FEATURE_MATMUL_INT8, use itunchanged (a gcc that knows the core keeps full native tuning).
/proc/cpuinfo(asimddp→+dotprod,i8mm→+i8mm) as-march=armv8-a+…— kept only if this compiler accepts the modifiers(gcc < 10 has no
+i8mm; composing blindly would turn a slow build into abroken one). If it doesn't, fall back to
-mcpu=nativeand say so with a$(warning)— the current behaviour, minus the silence.An explicit
ARCH=is respected verbatim:armv*values go to-march,core names to
-mcpu(same convention as the Darwin branch). On *BSD there isno
/proc/cpuinfo, so the probe degrades gracefully to-mcpu=native.Cross-compilers keep passing an explicit
ARCH=exactly as before — the probeonly fires on the
nativedefault, where host = target is already assumed.x86-64, Darwin, Windows and PowerPC branches are untouched.
Validation (DGX Spark GB10, Ubuntu 24.04, gcc 13.3.0, on top of current
dev)Flag selection, all paths:
make(default)-march=armv8-a+dotprod+i8mm(probe)make ARCH=armv8.6-a+i8mm-march=armv8.6-a+i8mmmake ARCH=cortex-a76-mcpu=cortex-a76makewith a gcc that rejects+i8mm(simulated gcc 9)-mcpu=native+ explicit warningResulting default binary, same source, same compiler as #631's evidence:
make checkgreen on this branch on top of currentdev: all C testbinaries + 273 Python tests OK (34 skipped) — every test binary visibly
compiled with the probed
-march=armv8-a+dotprod+i8mm.Kernel-level effect of the recovered instructions at the GLM-5.2 744B expert
shapes (
matmul_qt_ex, 2048×6144 / 6144×2048, best-of-3 windows, idlemachine, 2 interleaved rounds — generic-armv8-a build vs this patch's default):
As #631 notes, the published GB10 rows in
docs/benchmarks.mdwere measuredmatmul-bound and likely predate (or missed) the i8mm kernels; happy to
contribute a re-measured row from this box in a follow-up if useful.
Credit: the root-cause analysis is @james-fwai's in #631 — this PR adds the
fix that issue was closed without.
Closes #631.