Skip to content

U32 division and remainder halve the dividend only on Metal; the host and CUDA divide directly - #1277

Merged
nicolas-abril merged 1 commit into
bendlang:mainfrom
nicolas-abril:u32-quo-host
Oct 2, 2026
Merged

nicolas-abril merged 1 commit into
bendlang:mainfrom
nicolas-abril:u32-quo-host

Conversation

@nicolas-abril

@nicolas-abril nicolas-abril commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

The change

U32 / and % compile through U32_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_QUO now keeps that form only under __METAL_VERSION__; the host and CUDA divide directly. The Metal build compiles the same code as before.

  • Size: 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/runtime benches plus the histogram bench from #1278:

bench SEQ-CPU PAR-CPU PAR-GPU
histogram 1.722 → 1.474 s (−14.5%) 0.365 → 0.318 s (−12.8%) unchanged
lexer 2.189 → 2.100 s (−4.2%) 0.382 → 0.367 s (−3.8%) unchanged
hashmap 2.432 → 2.372 s (−2.5%) 0.397 → 0.391 s (−1.6%) unchanged
bfs −0.7% −1.9% unchanged
geomean, all 17 0.987 0.989 1.001

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

Not run

  • CUDA, Linux and x86.

🤖 Generated with Claude Code

…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant