Skip to content

Request the RNG initialization with GPUCompiler.deferred_codegen! - #998

Merged
maleadt merged 1 commit into
mainfrom
tb/deferred-codegen
Dec 2, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/deferred-codegen

Conversation

@maleadt

@maleadt maleadt commented Nov 27, 2026

Copy link
Copy Markdown
Member

GPUCompiler 2.25 adds deferred_codegen!(builder, job) (JuliaGPU/GPUCompiler.jl#1128), for back-ends that need a function compiled along with a kernel when they generate code for it in finish_module!. This uses it for initialize_rng_state().

Until now, the RNG initialization was requested by registering the job in GPUCompiler.deferred_codegen_jobs under length + 1 and emitting the deferred_codegen marker call by hand. Concurrent compilations, which Julia 1.12+ no longer serializes, can pick the same id, so a kernel can end up calling another compilation's function. deferred_codegen! registers the request without that race and emits the marker and the pointer conversion for every supported Julia version.

The GPUCompiler compat is bumped to 2.25. The old mechanism keeps working in GPUCompiler, so released versions are not affected; it will be deprecated once the back-ends have moved.

This is for the POCL back-end. Tested locally with Julia 1.13 and CI=true (so GPUCompiler verifies the IR): the full test suite passes.

Instead of registering the job in `deferred_codegen_jobs` under `length + 1`, which races
with concurrent compilations, and emitting the marker by hand. This needs GPUCompiler 2.25.
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with a585449d8, the merge base.
The environment differs from the baseline's: OS Linux 6.8.0-124-generic → Linux 6.8.0-151-generic, CompilerCaching 0.5.4 → 0.6.0, GPUCompiler 2.24.0 → 2.25.0, GPUToolbox 3.6.0 → 3.7.0, LLVM 10.7.0 → 10.8.1, LLVMExtra_jll 0.0.60+0 → 0.0.61+0, SPIRV_LLVM_Backend_jll 23.1.4+5 → 23.1.4+6.

Times are the minimum time of every benchmark. A change is unusual when it exceeds both three times the benchmark's typical change between consecutive runs on the default branch and a minimum per category (performance 3%, latency 5%, applications 3%, other 3%). A benchmark that starts or stops allocating is listed however few the allocations. A single run can still be a fluke, so rerun before drawing conclusions.

Geometric mean Unusual: slower Unusual: faster Compared
Performance +0.0% 1 0 32
Latency −0.0% 0 0 13
Applications +1.9% 0 0 5
Benchmark Baseline This PR Change
Performance
pocl/parallel/indexing/linear3d 39.9 µs 46.6 µs +16.7% 🔴 slower
All benchmarks
Benchmark Baseline This PR Change
Performance
julia/serial/arithmetic/muladd-reference 655 µs 655 µs −0.0%
julia/serial/math/exp-f64-reference 284 µs 284 µs −0.0%
julia/serial/narrow/masked-reference 715 µs 719 µs +0.6%
pocl/parallel/atomics/histogram 5.21 ms 5.25 ms +0.9%
pocl/parallel/groupreduce/add-f64 1.09 ms 1.09 ms +0.1%
pocl/parallel/groupreduce/fallback 4.38 ms 4.38 ms +0.0%
pocl/parallel/groupscan/add-i32 393 µs 392 µs −0.1%
pocl/parallel/indexing/cartesian3d 39.5 µs 40.1 µs +1.5%
pocl/parallel/indexing/linear3d 39.9 µs 46.6 µs +16.7% 🔴 slower
pocl/parallel/indexing/ntuple3d 40.5 µs 42.5 µs +4.8%
pocl/parallel/indexing/ntuple4d 127 µs 130 µs +2.0%
pocl/parallel/localmem/transpose-naive 433 µs 440 µs +1.7%
pocl/parallel/localmem/transpose-tiled 65.9 µs 64.6 µs −1.9%
pocl/parallel/private/across-barrier 42.5 µs 42.3 µs −0.5%
pocl/parallel/scheduling/default 117 µs 117 µs +0.1%
pocl/parallel/scheduling/explicit 117 µs 117 µs +0.1%
pocl/parallel/stream/copy/cache 663 ns 647 ns −2.4%
pocl/parallel/stream/copy/dram 6.50 ms 6.48 ms −0.4%
pocl/parallel/stream/triad/cache 1.29 µs 1.11 µs −13.7%
pocl/parallel/stream/triad/dram 9.54 ms 9.29 ms −2.5%
pocl/parallel/util/copyto-small 25.0 ns 24.0 ns −4.0%
pocl/parallel/util/zeros-large 941 µs 929 µs −1.2%
pocl/parallel/util/zeros-small 627 ns 651 ns +3.8%
pocl/serial/arithmetic/contract 1.85 ms 1.85 ms +0.0%
pocl/serial/arithmetic/muladd 705 µs 705 µs −0.0%
pocl/serial/const/marked 668 µs 668 µs −0.0%
pocl/serial/const/unmarked 860 µs 861 µs +0.0%
pocl/serial/math/exp-f64 123 µs 123 µs −0.2%
pocl/serial/math/sin-f64 167 µs 167 µs +0.3%
pocl/serial/narrow/masked 635 µs 635 µs +0.0%
pocl/serial/narrow/unmasked 635 µs 630 µs −0.9%
pocl/serial/stream/triad/dram 8.62 ms 8.58 ms −0.5%
Latency
host/import/ka 764 ms 771 ms +0.9%
host/precompile/ka 27.1 s 27.3 s +0.4%
host/startup 130 ms 128 ms −1.5%
pocl/parallel/launch/dynamic-default 165 ns 167 ns +1.2%
pocl/parallel/launch/groupreduce-f64 770 ns 770 ns +0.0%
pocl/parallel/launch/many-args 662 ns 660 ns −0.3%
pocl/parallel/launch/partial-workgroup 234 ns 235 ns +0.4%
pocl/serial/compile/groupreduce 1.51 s 1.48 s −1.8%
pocl/serial/compile/localmem-barrier 674 ms 672 ms −0.3%
pocl/serial/compile/new-kernel 127 ms 127 ms −0.3%
pocl/serial/compile/new-workgroupsize 8.73 ms 8.88 ms +1.7%
pocl/serial/first-kernel/cold-cache 395 ms 395 ms +0.1%
pocl/serial/first-kernel/warm-cache 321 ms 319 ms −0.7%
Applications
pocl/parallel/dgsem/fluxdiff-node 246 µs 245 µs −0.0%
pocl/parallel/dgsem/weak-element 90.7 µs 89.9 µs −0.8%
pocl/parallel/dgsem/weak-node-localmem 93.1 µs 93.5 µs +0.4%
pocl/parallel/stencil/timestep 7.29 ms 7.60 ms +4.3%
pocl/serial/stencil/timestep 10.1 ms 10.6 ms +5.6%

History: https://juliagpu.org/perf/?pkg=kernelabstractions

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.19%. Comparing base (a585449) to head (dfb34a0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #998      +/-   ##
==========================================
- Coverage   90.79%   89.19%   -1.61%     
==========================================
  Files          33       33              
  Lines        3293     2998     -295     
==========================================
- Hits         2990     2674     -316     
- Misses        303      324      +21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit 5f610a0 into main Dec 2, 2026
53 of 55 checks passed
@maleadt
maleadt deleted the tb/deferred-codegen branch December 2, 2026 10:01
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