linalg/mmm: take the chunking slack only where the cache absorbs it - #2570
Draft
czoli1976 wants to merge 1 commit into
Draft
linalg/mmm: take the chunking slack only where the cache absorbs it#2570czoli1976 wants to merge 1 commit into
czoli1976 wants to merge 1 commit into
Conversation
chunk_grid aimed for four chunks per thread everywhere. Each extra chunk re-reads a band of a packed operand, which is a cache hit on a part with a last-level cache big enough to hold it and a DRAM round trip on one with only a small cluster L2 (Cortex-A7/A9/A53). Gate the count on the detected last-level cache and take one chunk per thread below it, overridable with TRACT_MMM_CHUNKS_PER_THREAD. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
Author
|
@kali maybe will save A53 |
czoli1976
marked this pull request as draft
August 3, 2026 22:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2534: the a53
inceptionv3 · pass_mtregression looks like thechunk count, and this gates that count on whether the machine has a cache that
can absorb the re-reads it costs.
Why a53 and not the rest of the fleet
The a53 number is identical to three digits across the 09:12 and 11:02 runs on
#2534 — 1.12 s → 1.26 s both times. The L2-sharers commit only does anything when
l2_sharers > 1, so it was a no-op there. Ifcache_info().l2 == 0on thatrunner,
inner_tier_paysshort-circuits,blkandblk_outerare bothusize::MAX, andrun_blockedis a plain naive walk — which leaveschunk_gridas the only thing that changed on that device.
Replaying old vs merged over InceptionV3's 94 threaded convs at
nth = 4,arm64simd_mmm_f32_12x8_a53(m = Cout, k = Cin·kh·kw, n = Hout·Wout):+248 MB at 1.5–2.5 GB/s of effective DRAM bandwidth is +100 to +165 ms against a
measured +140 ms.
The cause is two rules meeting rather than the
sqrtshaping. The oldnchunks < 4·nthwas a re-plan trigger, and what it re-planned to wasnth.On grids below the old 16-panel cap — nearly all of InceptionV3 — the merged code
therefore asks for 4× the chunks the old code chose, and on a part with a 512 KB
cluster L2 and no L3 each extra chunk is a full re-read of a packed operand from
DRAM. That is also why a53 and not a55: a55 sits in a DynamIQ cluster with a DSU
L3 behind it, so the same re-reads hit cache.
The change
chunks_per_thread()gatesCHUNKS_PER_THREADon the detected last-level cache —falling back to L2 where no LLC is exposed, which is the case on Apple — and takes
one chunk per thread below 2 MB.
TRACT_MMM_CHUNKS_PER_THREADoverrides it,resolved once like the cache probe it reads, so the fleet can sweep 1/2/4 without a
rebuild.
Above 2 MB of last-level cache the chunk grid is bit-for-bit what it is today, so
this cannot move the m1-max, i9 or Orin numbers. Below it, the grid returns to the
old chunk count:
It covers the a53 whichever way the cache probe goes there: if L2 is undetected,
cache_info().l2 == 0drives the count to 1 anyway.Tests
cargo test -p tract-linalg --features multithread-mmpasses 4420 tests across alltargets.
harness/nnef-test-cases/parallel-matmulpasses at--approx exactfor 2,3 and 8 threads, run both on the default path and under
TRACT_MMM_CHUNKS_PER_THREAD=1— the second is the one that matters, since forcingthe constant is the only way to exercise the a53 chunk counts on Apple hardware.
cargo test --workspacegives 29 suites clean plus test-f16's own 4747, with onefailure —
nnef_f16::onnx::node::v1_19_1::test_averagepool_2d_ceil_last_window_starts_on_pad— which fails identically on
a6c4243c6with the diff reverted, so it ispre-existing and unrelated.
test-tflite,tract-proxy,tract-proxy-sysandtest-cudacould not build or run on this host (no OpenSSL, no FFI dylib, no CUDAdriver) and were excluded. Nothing outside
linalgcan see this change in any case:it is entirely inside
#[cfg(feature = "multithread-mm")], which is off by default.What I could not check
No wall clock. On a 12 MB-L2 M1 Pro
chunks_per_thread()resolves to 4, so thisdiff is inert on every machine I have; the traffic numbers above are arithmetic
over canonical InceptionV3 conv geometry, not measurements. A bench run is the
thing that would settle it, and
inceptionv3 · pass_mton cortex-a53 is the metricto watch.
CHUNK_SLACK_LLC_BYTES = 2 MBis a calibration guess, chosen to put Orin's 2 MB L3on the slack side and A7/A9/A53 off it. The env knob is there so a sweep can answer
where that boundary belongs rather than a rebuild per value — and if the constant
survives its bench run it should become a proper
declare_knob!.🍍