Repository navigation
Conversation
Inside 'use gpu', d.u32(a / b) compiles to u32(f32(a) / f32(b)). Past 2^24, or on drivers whose f32 division is not correctly rounded, the quotient lands on the wrong row. Every kernel now uses std.intdiv, and the 2^24 cases that were it.fails pass.
…lock counts that are not a power of two colWord is called with literals, so std.intdiv on its i32 argument returned i32 where d.u32 returned u32. The toHwc4/toChw round-trip and channelAffine cases use c = 10 (c4 = 3), which fails on main on GPUs whose f32 division is not exact for such divisors.
MiniX16
marked this pull request as ready for review
November 14, 2026 14:33
This branch has not been deployed
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.
Description
Inside
'use gpu',/compiles to f32 division, sod.u32(a / b)isu32(f32(a) / f32(b)), not integer division. Everyd.u32(a / b)left insrc/core/kernels(116 sites in 15 files) is nowstd.intdiv(a, b), asrows.ts,transpose.tsandattnFlash.tsalready do. The six 2^24 cases that wereit.failspass now and are plainit.The bug is not limited to large tensors. On an AMD Radeon 610M (RDNA2, Mesa 26.2.1 RADV, Chromium 156),
u32(f32(a) / f32(b))comes out one too low for every exact multiple of a divisor that is not a power of two:3 / 3 = 0,96 / 96 = 0. On that GPUmainfails 97 GPU tests, small shapes included, plus the MobileNetV4 and Higgs encoder zoo tests.Introduces a breaking change?
Type of change
Testing instructions
pnpm --filter runntime test:gpu(local GPU). New hwc4 cases withc = 10(c4 = 3) for thetoHwc4/toChwround-trip andchannelAffine: they fail onmainon the AMD GPU and pass with the fix. On that GPU the suite goes from 97 failures to 1, the existingtanhit.failsfor a Metal bug.pnpm --filter runntime bench:ab kernelsA/B against
main(Radeon 610M): 201 cases, 10 faster, 2tiledVec4rows slower in the first run that came outsamein two reruns. Non-zero output differences aremaincomputing wrong on this GPU.Screenshots
N/A
Related issues
Closes #57
Checklist
Additional notes
colWordinmoeQuantW.tsis called with literals, so its argument goes throughd.u32to keep the resultu32.