Skip to content

Keep the PTX compilation and pool creation concretely typed - #3445

Merged
maleadt merged 1 commit into
tb/invalidationsfrom
tb/invalidations-2
Oct 22, 2026
Merged

maleadt merged 1 commit into
tb/invalidationsfrom
tb/invalidations-2

Conversation

@maleadt

@maleadt maleadt commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #3440. Two more chains that made Julia discard large parts of CUDACore's precompiled code when packages were loaded before CUDA.jl:

  • invoke_frozen(GPUCompiler.compile, :asm, job) isn't inferred, so inspecting the IR it returns (to determine whether the device runtime is needed) was compiled with edges to generic methods like setdiff of an abstract collection. This asserts the module's type.
  • ntuple(f, 53) returns a tuple of unknown length (ntuple only unrolls up to 10 elements), so the reserved bytes of CUmemPoolProps were converted to NTuple{53, UInt8} with generic ntuple/comparison methods, which ForwardDiff and others invalidate. Memory pools are created on the first allocation, so with ~1500 method instances this was the biggest remaining chain in CUDACore. The same applies to the texture descriptors. This passes the counts as Vals.

Tested with the core codegen, execution, exceptions, KernelAbstractions, broadcast, array, pool, texture and driver tests. Together with JuliaLLVM/LLVM.jl#703 and the other follow-ups, the first @cuda kernel (plus a broadcast and sum) with DataFrames loaded first goes from 6.42 s on main to 2.76 s, and with ChainRulesCore from 4.02 s to 2.22 s (2.12 s with nothing loaded first), on Julia 1.13 and an RTX 5080.

`invoke_frozen` isn't inferred, so inspecting the IR it returned was compiled
with edges to generic methods (e.g. `setdiff` of an abstract collection), and
`ntuple` with a literal count above 10 returns a tuple of unknown length, so the
reserved fields of memory pool and texture descriptors were converted with
generic `ntuple`/comparison methods. Packages loaded before CUDA.jl that extend
those (e.g. ForwardDiff's comparisons) made Julia discard large parts of
CUDACore's precompiled code, as memory pools are created on the first
allocation. Assert the IR's type and pass the counts as `Val`s.
@maleadt maleadt added the latency Compile time, load time, time-to-first-execution, invalidations. label Oct 21, 2026
@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.58%. Comparing base (6747004) to head (d05e89b).

Additional details and impacted files
@@                  Coverage Diff                  @@
##           tb/invalidations    #3445       +/-   ##
=====================================================
+ Coverage             28.28%   85.58%   +57.30%     
=====================================================
  Files                   190      191        +1     
  Lines                 19229    19468      +239     
=====================================================
+ Hits                   5438    16661    +11223     
+ Misses                13791     2807    -10984     

☔ 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

Copy link
Copy Markdown
Contributor

CUDA.jl Benchmarks

Details
Benchmark suite Current: d05e89b Previous: 44ac4eb Ratio
array/accumulate/Float32/1d 55226 ns 55308 ns 1.00
array/accumulate/Float32/dims=1 39830 ns 40571 ns 0.98
array/accumulate/Float32/dims=1L 82357 ns 83176 ns 0.99
array/accumulate/Float32/dims=2 50354 ns 50536 ns 1.00
array/accumulate/Float32/dims=2L 397829 ns 399321 ns 1.00
array/accumulate/Int64/1d 88250 ns 88873 ns 0.99
array/accumulate/Int64/dims=1 60221 ns 60537 ns 0.99
array/accumulate/Int64/dims=1L 140077 ns 140593 ns 1.00
array/accumulate/Int64/dims=2 69611 ns 68766 ns 1.01
array/accumulate/Int64/dims=2L 797724 ns 796187 ns 1.00
array/broadcast 10241 ns 10301 ns 0.99
array/broadcast launch 6625.4 ns 6884.4 ns 0.96
array/construct 926.0277777777778 ns 894.6666666666666 ns 1.04
array/copy 16630 ns 17076 ns 0.97
array/copyto!/cpu_to_gpu 207570 ns 208724 ns 0.99
array/copyto!/gpu_to_cpu 240347 ns 240881 ns 1.00
array/copyto!/gpu_to_gpu 8663 ns 8932 ns 0.97
array/iteration/findall/bool 48712 ns 50126 ns 0.97
array/iteration/findall/int 65637 ns 65404 ns 1.00
array/iteration/findfirst/bool 35645 ns 35653 ns 1.00
array/iteration/findfirst/int 35074 ns 35876 ns 0.98
array/iteration/findmin/1d 50977 ns 51420 ns 0.99
array/iteration/findmin/2d 52207 ns 53587 ns 0.97
array/iteration/logical 50089 ns 51149 ns 0.98
array/iteration/scalar 59396 ns 61238 ns 0.97
array/permutedims/2d 47109 ns 47224 ns 1.00
array/permutedims/3d 44688 ns 44784 ns 1.00
array/permutedims/4d 47830 ns 48464 ns 0.99
array/random/rand/Float32 11038 ns 11176 ns 0.99
array/random/rand/Int64 17741 ns 18087 ns 0.98
array/random/rand!/Float32 8182 ns 8279.666666666666 ns 0.99
array/random/rand!/Int64 15569 ns 15676 ns 0.99
array/random/randn/Float32 33964 ns 34429 ns 0.99
array/random/randn!/Float32 24832 ns 25461 ns 0.98
array/reductions/mapreduce/Float32/1d 35487 ns 36711 ns 0.97
array/reductions/mapreduce/Float32/dims=1 20294 ns 20536 ns 0.99
array/reductions/mapreduce/Float32/dims=1L 57774 ns 58081 ns 0.99
array/reductions/mapreduce/Float32/dims=2 28333 ns 28592 ns 0.99
array/reductions/mapreduce/Float32/dims=2L 58398 ns 58294 ns 1.00
array/reductions/mapreduce/Int64/1d 36109 ns 36620 ns 0.99
array/reductions/mapreduce/Int64/dims=1 22727 ns 22994 ns 0.99
array/reductions/mapreduce/Int64/dims=1L 97210 ns 97464 ns 1.00
array/reductions/mapreduce/Int64/dims=2 29169 ns 29433 ns 0.99
array/reductions/mapreduce/Int64/dims=2L 83472 ns 83514 ns 1.00
array/reductions/reduce/Float32/1d 35879 ns 36457 ns 0.98
array/reductions/reduce/Float32/dims=1 20293 ns 20403 ns 0.99
array/reductions/reduce/Float32/dims=1L 58149 ns 57761 ns 1.01
array/reductions/reduce/Float32/dims=2 28131 ns 28033 ns 1.00
array/reductions/reduce/Float32/dims=2L 58403 ns 58514 ns 1.00
array/reductions/reduce/Int64/1d 36438 ns 36852 ns 0.99
array/reductions/reduce/Int64/dims=1 22441 ns 23003 ns 0.98
array/reductions/reduce/Int64/dims=1L 97498 ns 97475 ns 1.00
array/reductions/reduce/Int64/dims=2 29597 ns 29524 ns 1.00
array/reductions/reduce/Int64/dims=2L 84062 ns 84151 ns 1.00
array/reverse/1d 19854 ns 19992 ns 0.99
array/reverse/1dL 73695 ns 73831 ns 1.00
array/reverse/1dL_inplace 70590 ns 70561 ns 1.00
array/reverse/1d_inplace 12362 ns 12362 ns 1
array/reverse/2d 22559 ns 23022 ns 0.98
array/reverse/2dL 80854 ns 81365 ns 0.99
array/reverse/2dL_inplace 71169 ns 71062 ns 1.00
array/reverse/2d_inplace 15089 ns 14773 ns 1.02
array/sorting/1d 750292 ns 750546 ns 1.00
array/sorting/2d 194506 ns 194226 ns 1.00
array/sorting/by 927234 ns 928901 ns 1.00
cuda/graph/capture 36175 ns 36564 ns 0.99
cuda/graph/eager 32692 ns 34234 ns 0.95
cuda/graph/launch 13857 ns 13955 ns 0.99
cuda/synchronization/context/auto 2302.222222222222 ns 2315.8888888888887 ns 0.99
cuda/synchronization/context/blocking 902.1190476190476 ns 910.175 ns 0.99
cuda/synchronization/context/nonblocking 10820 ns 10524 ns 1.03
cuda/synchronization/stream/auto 870.25 ns 892.1086956521739 ns 0.98
cuda/synchronization/stream/blocking 791.979381443299 ns 794.3020833333334 ns 1.00
cuda/synchronization/stream/nonblocking 8753.666666666666 ns 8287.666666666666 ns 1.06
integration/byval/reference 147671 ns 147653 ns 1.00
integration/byval/slices=1 148796 ns 148788 ns 1.00
integration/byval/slices=2 290356 ns 290449 ns 1.00
integration/byval/slices=3 432493 ns 432565 ns 1.00
integration/cudadevrt 105004 ns 105032 ns 1.00
integration/volumerhs 9609724 ns 9610762 ns 1.00
kernel/indexing 11591 ns 11452 ns 1.01
kernel/indexing_checked 11996 ns 12086 ns 0.99
kernel/launch 2332.222222222222 ns 2338.8888888888887 ns 1.00
kernel/occupancy 688.0457516339869 ns 668.6883116883117 ns 1.03
kernel/rand 14817 ns 15164 ns 0.98
latency/import 4095438826 ns 4065671956 ns 1.01
latency/precompile 5034377782 ns 5034183307 ns 1.00
latency/ttfp 4995870249 ns 4961406691 ns 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@maleadt
maleadt merged commit 337cfd2 into tb/invalidations Oct 22, 2026
18 checks passed
@maleadt
maleadt deleted the tb/invalidations-2 branch October 22, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

latency Compile time, load time, time-to-first-execution, invalidations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant