Skip to content

Compile with GPUCompiler's do-block compile - #3627

Merged
maleadt merged 2 commits into
mainfrom
tb/compile-do-block
Nov 25, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/compile-do-block

Conversation

@maleadt

@maleadt maleadt commented Nov 25, 2026

Copy link
Copy Markdown
Member

emit_ptx now passes its IR inspection (the undefined functions that decide whether cudadevrt is needed, and the entry point's name) as a callback to the new GPUCompiler.compile(f, :asm, job) from JuliaGPU/GPUCompiler.jl#1124, instead of creating a JuliaContext and disposing the module itself. GPUCompiler compat is raised to 2.24 in CUDACore and CUDATools.

This prepares for the llvmgpu toolchain (JuliaGPU/GPUCompiler.jl#1122), where the IR returned by compile belongs to libLLVMGPU, a newer LLVM than Julia's. Reading it from a JuliaContext, as emit_ptx did, calls Julia's libLLVM on libLLVMGPU values and segfaults (in LLVMGetValueName, already while precompiling CUDACore). The do-block form activates the IR's own context around the callback, so the same code works with either toolchain. CUDA's GPUCompiler hooks needed no change: finish_module! (the only one using convert(LLVMType, ...)) runs before the IR moves to libLLVMGPU.

Validated on an RTX 5080 with Julia 1.12.7 and GPUCompiler 2.24 (the #1122 branch with the do-block form), running the core and tools test groups: 20069 passed, 22 broken under the default toolchain; 20051 passed, 22 broken under llvmgpu (with KernelAbstractions' precompile workload disabled, as its POCL back-end doesn't support llvmgpu yet).

@maleadt

maleadt commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

CI failure unrelated.

emit_ptx now inspects the IR (the undefined functions that decide whether
cudadevrt is needed, and the entry point's name) in a function passed to
GPUCompiler.compile, which creates the context, keeps it active around the
callback and frees the IR afterwards.

With GPUCompiler's upcoming llvmgpu toolchain, the IR can belong to
libLLVMGPU, a newer LLVM than Julia's. Reading it from a JuliaContext then
calls Julia's libLLVM on libLLVMGPU values, which crashes; the do-block form
activates the IR's own context, so this works with either toolchain.

Requires GPUCompiler 2.24.
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.94%. Comparing base (61e93a6) to head (2842463).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3627      +/-   ##
==========================================
- Coverage   89.54%   88.94%   -0.60%     
==========================================
  Files         201      200       -1     
  Lines       22967    21646    -1321     
==========================================
- Hits        20565    19254    -1311     
+ Misses       2402     2392      -10     

☔ 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.

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with 61e93a6b0, the merge base.
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.8% 1 0 79
Latency +0.7% 0 0 3
Applications −0.1% 0 0 6
Benchmark Baseline This PR Change
Performance
kernel/occupancy 30.0 ns 36.1 ns +20.2% 🔴 slower
Benchmark Baseline allocations This PR
Performance
kernel/occupancy none 1 (32 B) 🔴 allocates
All benchmarks
Benchmark Baseline This PR Change
Performance
array/accumulate/Float32/1d 44.2 µs 43.7 µs −1.2%
array/accumulate/Float32/dims=1 30.3 µs 30.7 µs +1.2%
array/accumulate/Float32/dims=1L 96.6 µs 96.6 µs −0.1%
array/accumulate/Float32/dims=2 48.8 µs 48.5 µs −0.5%
array/accumulate/Float32/dims=2L 364 µs 366 µs +0.5%
array/accumulate/Int64/1d 68.1 µs 68.2 µs +0.0%
array/accumulate/Int64/dims=1 41.2 µs 41.3 µs +0.2%
array/accumulate/Int64/dims=1L 140 µs 140 µs +0.1%
array/accumulate/Int64/dims=2 71.4 µs 70.6 µs −1.1%
array/accumulate/Int64/dims=2L 762 µs 758 µs −0.6%
array/broadcast 10.7 µs 10.6 µs −1.3%
array/broadcast launch 5.89 µs 5.68 µs −3.5%
array/construct 1.40 µs 1.36 µs −3.3%
array/copy 18.0 µs 17.7 µs −1.5%
array/copyto!/cpu_to_gpu 207 µs 207 µs −0.4%
array/copyto!/gpu_to_cpu 241 µs 239 µs −0.7%
array/copyto!/gpu_to_gpu 12.1 µs 12.1 µs −0.1%
array/iteration/findall/bool 48.4 µs 48.3 µs −0.2%
array/iteration/findall/int 58.0 µs 57.6 µs −0.7%
array/iteration/findfirst/bool 32.5 µs 32.3 µs −0.4%
array/iteration/findfirst/int 33.2 µs 33.5 µs +0.8%
array/iteration/findmin/1d 63.3 µs 62.8 µs −0.7%
array/iteration/findmin/2d 41.1 µs 41.0 µs −0.2%
array/iteration/logical 48.9 µs 48.3 µs −1.3%
array/iteration/scalar 56.7 µs 57.4 µs +1.3%
array/permutedims/2d 56.0 µs 55.4 µs −1.0%
array/permutedims/3d 52.1 µs 51.8 µs −0.5%
array/permutedims/4d 43.7 µs 43.1 µs −1.3%
array/random/rand!/Float32 9.76 µs 9.75 µs −0.0%
array/random/rand!/Int64 16.4 µs 16.2 µs −1.0%
array/random/rand/Float32 12.1 µs 11.8 µs −2.0%
array/random/rand/Int64 21.2 µs 20.7 µs −2.2%
array/random/randn!/Float32 29.8 µs 29.6 µs −0.7%
array/random/randn/Float32 39.5 µs 39.4 µs −0.3%
array/reductions/mapreduce/Float32/1d 30.6 µs 30.9 µs +1.1%
array/reductions/mapreduce/Float32/dims=1 18.0 µs 17.9 µs −1.0%
array/reductions/mapreduce/Float32/dims=1L 54.7 µs 54.3 µs −0.7%
array/reductions/mapreduce/Float32/dims=2 25.3 µs 24.6 µs −2.9%
array/reductions/mapreduce/Float32/dims=2L 61.7 µs 61.0 µs −1.2%
array/reductions/mapreduce/Int64/1d 30.9 µs 31.3 µs +1.2%
array/reductions/mapreduce/Int64/dims=1 20.3 µs 20.0 µs −1.5%
array/reductions/mapreduce/Int64/dims=1L 93.2 µs 93.0 µs −0.2%
array/reductions/mapreduce/Int64/dims=2 27.6 µs 27.0 µs −2.1%
array/reductions/mapreduce/Int64/dims=2L 97.0 µs 96.6 µs −0.4%
array/reductions/reduce/Float32/1d 30.1 µs 30.3 µs +0.8%
array/reductions/reduce/Float32/dims=1 18.0 µs 17.7 µs −1.6%
array/reductions/reduce/Float32/dims=1L 54.2 µs 53.8 µs −0.7%
array/reductions/reduce/Float32/dims=2 25.0 µs 24.5 µs −2.2%
array/reductions/reduce/Float32/dims=2L 61.5 µs 60.8 µs −1.1%
array/reductions/reduce/Int64/1d 31.1 µs 31.5 µs +1.5%
array/reductions/reduce/Int64/dims=1 20.4 µs 19.9 µs −2.3%
array/reductions/reduce/Int64/dims=1L 93.2 µs 92.7 µs −0.5%
array/reductions/reduce/Int64/dims=2 27.5 µs 27.1 µs −1.5%
array/reductions/reduce/Int64/dims=2L 97.3 µs 96.9 µs −0.4%
array/reverse/1d 19.7 µs 19.2 µs −2.3%
array/reverse/1d_inplace 12.2 µs 11.8 µs −3.3%
array/reverse/1dL 73.8 µs 72.9 µs −1.2%
array/reverse/1dL_inplace 68.7 µs 68.2 µs −0.7%
array/reverse/2d 23.6 µs 23.2 µs −1.6%
array/reverse/2d_inplace 15.4 µs 15.0 µs −2.3%
array/reverse/2dL 93.0 µs 92.6 µs −0.5%
array/reverse/2dL_inplace 69.7 µs 69.3 µs −0.6%
array/sorting/1d 827 µs 825 µs −0.2%
array/sorting/2d 248 µs 248 µs −0.2%
array/sorting/by 969 µs 967 µs −0.2%
cuda/graph/capture 26.3 µs 25.3 µs −4.0%
cuda/graph/eager 25.1 µs 24.4 µs −2.8%
cuda/graph/launch 16.4 µs 16.7 µs +1.3%
cuda/synchronization/context/auto 1.98 µs 1.91 µs −3.7%
cuda/synchronization/context/blocking 643 ns 658 ns +2.3%
cuda/synchronization/context/nonblocking 6.06 µs 4.52 µs −25.5%
cuda/synchronization/stream/auto 575 ns 575 ns −0.0%
cuda/synchronization/stream/blocking 529 ns 539 ns +1.9%
cuda/synchronization/stream/nonblocking 6.35 µs 6.81 µs +7.2%
kernel/indexing 11.8 µs 11.8 µs −0.1%
kernel/indexing_checked 12.4 µs 12.4 µs +0.2%
kernel/launch 1.44 µs 1.44 µs +0.0%
kernel/occupancy 30.0 ns 36.1 ns +20.2% 🔴 slower
kernel/rand 16.4 µs 16.1 µs −1.3%
Latency
import 3.92 s 3.95 s +0.7%
precompile 6.19 s 6.24 s +0.8%
ttfp 4.30 s 4.33 s +0.7%
Applications
byval/reference 145 µs 145 µs −0.1%
byval/slices=1 146 µs 146 µs −0.0%
byval/slices=2 286 µs 286 µs +0.0%
byval/slices=3 426 µs 426 µs −0.0%
cudadevrt 104 µs 104 µs −0.2%
volumerhs 10.3 ms 10.3 ms −0.0%

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

@maleadt
maleadt merged commit ffdd314 into main Nov 25, 2026
1 check was pending
@maleadt
maleadt deleted the tb/compile-do-block branch November 25, 2026 21:59
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