Repository navigation
U32 division and remainder halve the dividend only on Metal; the host and CUDA divide directly - #1277
Merged
Merged
Conversation
…2 fold of a constant dividend near 2^32 they work around (bendlang#824); the host and CUDA divide directly Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.
The change
U32
/and%compile throughU32_QUO, which halves the dividend, divides, and then fixes the odd bit. ef1328f (#824) added it because Metal folds a constant dividend within 128 of 2^32 through an f32. The macro was emitted for every backend, though, so the host and CUDA paid for a Metal workaround on every division.U32_QUOnow keeps that form only under__METAL_VERSION__; the host and CUDA divide directly. The Metal build compiles the same code as before.bend2/comp.ts+19 ttok (+5 −4 lines).Main vs this branch
Paired A/B on the cluster. Each bench and mode ran on one mini: both builds use the perf gate's cc line and flags, with one warm run each, then 5 alternating timed runs, and each value is the median. Every output matches. The 16
bench/runtimebenches plus the histogram bench from #1278:On the histogram's key fill alone, the old form cost 0.25 s of a 1.15 s single-threaded fill.
The other benches are within ±1%. A few SEQ cells moved by a small but significant amount where the change isn't on the hot path: tree-bitonic +0.9%, and kmeans, raytrace and terrain about +0.4%. No PAR-GPU cell's 95% interval excludes 1.
Gates
gates/test.tspasses, 1528 / 1528, including the Metal runs of every!test, which keep the Metal: U32 remainder returns 4294967295 for 4294967294 % 3 #824 form.bend2/comp.ts's cap, as main does today: main is at 64,274 ttok, this branch at 64,293. Main went over when The host's column grows to a LINE of tasks a thread again, a drain splits its rows into units of 32 a thread, and rings rewind between turns (stacked on #1092) #1269 merged; a trim is needed separately.Not run
🤖 Generated with Claude Code