Repository navigation
Conversation
`validindex` combined the per-dimension comparisons with `all`, which Julia 1.10-1.12 lower to a branch per dimension (1.13 to a single one). With several branches PoCL doesn't hoist the index computation out of its loop over the work-items. That made kernels with a linear launch (e.g. a 4-D ndrange on the CPU backend) several times slower on those Julia versions: a 64x64x64x3 kernel took 583 us on Julia 1.12 against 133 us on 1.13. Use `&` instead, which is branch-free everywhere. Add a codegen check that the bounds check leaves a single conditional branch, for a 3-D and a 4-D ndrange. Assisted-by: Claude Code
Contributor
Benchmark ResultsShow table
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #844 +/- ##
=======================================
Coverage 79.75% 79.75%
=======================================
Files 25 25
Lines 2139 2139
=======================================
Hits 1706 1706
Misses 433 433 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
validindexcombines the per-dimension bounds comparisons withall. Julia 1.10–1.12 lower that to one conditional branch per dimension; 1.13 emits a single and-chain. With the bounds check spread over several branches, PoCL does not hoist the index computation out of its loop over the work-items. For a linear launch that means theudiv/uremreconstructing the Cartesian index run once per work-item instead of once per workgroup.This PR uses
reduce(&, ...; init = true)instead, which is branch-free on every Julia version.initkeeps the 0-dimensional case returningtrue, asall(())did.Impact
This showed up while re-measuring the WaterLily CPU reports (#696, #644) against main. WaterLily's
BDIM!andscale_u!loop over a 4-D range (nx, ny, nz, 3). PoCL's grid is 3-D, so these kernels take theLinearLaunchpath.Kernel
u[I] = u[I]*s + v[I]over a 64×64×64×3 range, workgroup size 64, 4 threads, Ryzen 9 5950X:WaterLily v1.6.1 tgv 2^6 at 4 threads on Julia 1.12 goes from 0.748 to 0.555 s per 25 steps (KA 0.9.43: 0.656 s). That run used the same change without
init = true; the generated code is the same for N ≥ 1.Test
A new codegen check in
test/codegen_checks.jlasserts that a kernel with a dynamic 3-D and 4-Dndrangehas exactly one conditional branch. On main the 4-D check fails on Julia 1.10, 1.11 and 1.12, and passes on 1.13; with this change it passes on all four. The full test suite passes locally on Julia 1.10 and 1.12.🤖 Generated with Claude Code