Repository navigation
Conversation
- Dimensions along which the output (or, if it has stride zero, the first input that moves) has a negative stride are reversed before planning, so that arrays reversed along the same dimensions can be fused and traversed with unit strides. - The costs and the memory region use absolute strides, and the costs ignore zero strides. With negative strides, the memory region came out tiny, so that transposes with a reversed array were not blocked, and the costs were negative; with zero strides, a dimension got cost 1 as soon as any array had stride zero along it. - Inputs are only blocked if some array visits cache lines again after the inner loops moved on: through a smaller stride along an outer loop (always blocked), or through a stride zero with more reused data than fits in the block size. Arrays whose strides increase along the loops load every cache line once, and blocking only shortened their contiguous runs. - The threads may split any dimension of size > 1 with a nonzero cost. Before, they never split a dimension of at most 1024 that fit within a block, so that unblocked plans with such dimensions ran on one thread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
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.
Work in progress. Builds on #105 (and thereby #104), and targets its branch
jh/recursive-kernel; it can be retargeted once those are merged.An investigation of the planning of
_mapreduce_block!, i.e. for inputs aboveMAXNAIVELENGTH. Running the planning itself costs 20–200 ns, at most 2% of the kernel at these sizes, so there is little to gain from a cheaper implementation. The decisions it takes mattered much more: on a set of 22 varied cases (maps with simple and complicatedf, 3-input maps with mixed layouts, broadcasts, reductions, the nativemul!), the blocking was often worse than not blocking at all, by up to 2.4×.Changes so far:
mul!.The small-input path (
_mapreduce_order!) is unchanged: the loops are only reversed inside_mapreduce_block!.Benchmarks against #105 (Apple M4 Max, Julia 1.13.1; minimum of three interleaved runs):
dims=(1,3), 64^4dims=(2,4), 64^4C .= A .+ b', 1000²mul!200³ / 256×64×512All other cases (transposes, 4D and 6D permutations, maps with 3 inputs,
expof a transpose, further reductions) are within ±8%, the run-to-run noise. Small inputs are unchanged.Still to investigate:
permutedimsof 32^4 withp = (4, 3, 2, 1), the best blocks found by a search take 370 µs, against 830 µs for the chosen ones. For 2D transposes, the best blocks have one cache line along the innermost dimension and a large extent along the other one, whereas the heuristic chooses square-ish blocks. A rule along these lines helped transposes but made reductions andmul!2–4× slower, so this needs a better cost model, without tuning for a single machine.dims=(2,4)could take 2.2 instead of 3.3 ms). Not letting them vote at all breaks the accumulation in a register for reductions overdims=1.🤖 Generated with Claude Code