Skip to content

Don't poll before blocking synchronization, and only poll once otherwise - #3360

Merged
maleadt merged 1 commit into
tb/event-ownershipfrom
tb/sync-fastpath
Oct 8, 2026
Merged

maleadt merged 1 commit into
tb/event-ownershipfrom
tb/sync-fastpath

Conversation

@maleadt

@maleadt maleadt commented Oct 7, 2026

Copy link
Copy Markdown
Member

Since #3315, synchronize_object queried the stream or event before every synchronization, only to decide whether to collect garbage. In the blocking path, that query costs about as much as synchronizing an idle stream (~350 ns on the benchmark machine). In the spinning path, cooperative_wait then queried again. This explains the cuda/synchronization/stream/{blocking,nonblocking} regressions on the dashboard.

Now the object is polled once up front, and only when cooperative_wait would poll it anyway (nonblocking, spinning). If it's done, we return right away, and events still go through synchronize_completed. The GC pause and draining of retired resources happen only when we're about to wait. Blocking and spin=false synchronization don't poll at all, as before #3315.

Idle-GPU benchmarks (RTX 5080, Julia 1.12, 3 pinned cores, median of 3 alternating runs, ns):

benchmark main this stack this PR
stream/auto 176 196 86
stream/blocking 194 214 195
stream/nonblocking 1977 2475 2187

The context/auto regression on the dashboard (~1 → ~6.8 µs) is intended and not addressed here. Before #3315, device_synchronize() polled the legacy stream, which doesn't cover CUDA.jl's non-blocking task streams, and then blocked the thread in cuCtxSynchronize. A context can't be polled, so it now always goes through a worker, and context/auto costs the same as context/nonblocking.

@maleadt
maleadt added this pull request to stack #3338 October 7, 2026 11:20
@maleadt maleadt added the performance Runtime performance. label Oct 7, 2026
Since #3315, synchronize_object queried the object before every
synchronization to decide whether to collect garbage, also when
synchronizing in a blocking manner, where that query costs about as much
as the synchronization of an idle stream. With spinning enabled, the
query was then repeated by cooperative_wait.

Instead, poll once up front only when cooperative_wait would, and return
right away when that finds the object done. The GC pause and draining
retired resources are left for when we are actually about to wait.
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

CUDA.jl Benchmarks

Details
Benchmark suite Current: a581505 Previous: ae637e5 Ratio
array/accumulate/Float32/1d 105613 ns 105001 ns 1.01
array/accumulate/Float32/dims=1 77837 ns 77262 ns 1.01
array/accumulate/Float32/dims=1L 1675150 ns 1684940 ns 0.99
array/accumulate/Float32/dims=2 148391 ns 148043 ns 1.00
array/accumulate/Float32/dims=2L 685943 ns 684338 ns 1.00
array/accumulate/Int64/1d 124490 ns 123503 ns 1.01
array/accumulate/Int64/dims=1 82609 ns 81902 ns 1.01
array/accumulate/Int64/dims=1L 1805589 ns 1803636 ns 1.00
array/accumulate/Int64/dims=2 163785 ns 163105 ns 1.00
array/accumulate/Int64/dims=2L 989761 ns 988275 ns 1.00
array/broadcast 17392 ns 16981 ns 1.02
array/broadcast launch 7833 ns 7497.25 ns 1.04
array/construct 935.1538461538462 ns 886.76 ns 1.05
array/copy 17390 ns 16325 ns 1.07
array/copyto!/cpu_to_gpu 208722 ns 206249 ns 1.01
array/copyto!/gpu_to_cpu 241867 ns 240560 ns 1.01
array/copyto!/gpu_to_gpu 9054 ns 8967 ns 1.01
array/iteration/findall/bool 140114 ns 135815 ns 1.03
array/iteration/findall/int 150507 ns 145400 ns 1.04
array/iteration/findfirst/bool 75376 ns 71077 ns 1.06
array/iteration/findfirst/int 76921 ns 73309 ns 1.05
array/iteration/findmin/1d 67992 ns 59845 ns 1.14
array/iteration/findmin/2d 103964 ns 103127 ns 1.01
array/iteration/logical 201008 ns 187405 ns 1.07
array/iteration/scalar 53566 ns 59115 ns 0.91
array/permutedims/2d 50102 ns 49364 ns 1.01
array/permutedims/3d 51685 ns 50795 ns 1.02
array/permutedims/4d 52799 ns 52271 ns 1.01
array/random/rand/Float32 11539 ns 11109 ns 1.04
array/random/rand/Int64 18823 ns 18411 ns 1.02
array/random/rand!/Float32 8344.333333333334 ns 8183 ns 1.02
array/random/rand!/Int64 16281 ns 15765 ns 1.03
array/random/randn/Float32 34895 ns 34501 ns 1.01
array/random/randn!/Float32 25010 ns 24403 ns 1.02
array/reductions/mapreduce/Float32/1d 32628 ns 30573 ns 1.07
array/reductions/mapreduce/Float32/dims=1 40334 ns 40213 ns 1.00
array/reductions/mapreduce/Float32/dims=1L 53884 ns 53356 ns 1.01
array/reductions/mapreduce/Float32/dims=2 59585 ns 59358 ns 1.00
array/reductions/mapreduce/Float32/dims=2L 72115 ns 71210 ns 1.01
array/reductions/mapreduce/Int64/1d 39669 ns 37469 ns 1.06
array/reductions/mapreduce/Int64/dims=1 43634 ns 42915 ns 1.02
array/reductions/mapreduce/Int64/dims=1L 89742 ns 89249 ns 1.01
array/reductions/mapreduce/Int64/dims=2 60996 ns 61370 ns 0.99
array/reductions/mapreduce/Int64/dims=2L 88019 ns 87543 ns 1.01
array/reductions/reduce/Float32/1d 32847 ns 30615 ns 1.07
array/reductions/reduce/Float32/dims=1 40543 ns 40264 ns 1.01
array/reductions/reduce/Float32/dims=1L 53405 ns 52907 ns 1.01
array/reductions/reduce/Float32/dims=2 59613 ns 59462 ns 1.00
array/reductions/reduce/Float32/dims=2L 72568 ns 71728 ns 1.01
array/reductions/reduce/Int64/1d 39677 ns 37570 ns 1.06
array/reductions/reduce/Int64/dims=1 43568 ns 42862 ns 1.02
array/reductions/reduce/Int64/dims=1L 89505 ns 89319 ns 1.00
array/reductions/reduce/Int64/dims=2 60917 ns 61437 ns 0.99
array/reductions/reduce/Int64/dims=2L 88048 ns 86880 ns 1.01
array/reverse/1d 16561 ns 16128 ns 1.03
array/reverse/1dL 70409 ns 70115 ns 1.00
array/reverse/1dL_inplace 67824 ns 67602 ns 1.00
array/reverse/1d_inplace 9570 ns 9293 ns 1.03
array/reverse/2d 21350 ns 21118 ns 1.01
array/reverse/2dL 75395 ns 74528 ns 1.01
array/reverse/2dL_inplace 67896 ns 67778 ns 1.00
array/reverse/2d_inplace 10931 ns 10676 ns 1.02
array/sorting/1d 2850525 ns 2846981 ns 1.00
array/sorting/2d 1090831 ns 1088944 ns 1.00
array/sorting/by 3403924 ns 3400388 ns 1.00
cuda/graph/capture 42432 ns
cuda/graph/eager 41418 ns
cuda/graph/launch 14446 ns
cuda/synchronization/context/auto 7947 ns 6766.6 ns 1.17
cuda/synchronization/context/blocking 891.8205128205128 ns 793.7692307692307 ns 1.12
cuda/synchronization/context/nonblocking 7918 ns 6805.4 ns 1.16
cuda/synchronization/stream/auto 353.60648148148147 ns 691.0939597315436 ns 0.51
cuda/synchronization/stream/blocking 817.16 ns 868.875 ns 0.94
cuda/synchronization/stream/nonblocking 7426 ns 7338.5 ns 1.01
integration/byval/reference 148238 ns 147882 ns 1.00
integration/byval/slices=1 149280 ns 149033 ns 1.00
integration/byval/slices=2 291296 ns 291277 ns 1.00
integration/byval/slices=3 433701 ns 434160 ns 1.00
integration/cudadevrt 105543 ns 105116 ns 1.00
integration/volumerhs 9208712 ns 9206594 ns 1.00
kernel/indexing 11831 ns 11855 ns 1.00
kernel/indexing_checked 12393 ns 12209 ns 1.02
kernel/launch 2562.222222222222 ns 2433 ns 1.05
kernel/occupancy 959.95 ns 1008.8235294117648 ns 0.95
kernel/rand 15438 ns 14899 ns 1.04
latency/import 4316478842 ns 4305717656 ns 1.00
latency/precompile 5098977588 ns 5095420673 ns 1.00
latency/ttfp 4796690923 ns 4793974717 ns 1.00

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

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.10%. Comparing base (38d4a78) to head (a581505).

Additional details and impacted files
@@                  Coverage Diff                   @@
##           tb/event-ownership    #3360      +/-   ##
======================================================
+ Coverage               84.86%   85.10%   +0.23%     
======================================================
  Files                     194      194              
  Lines                   19960    19962       +2     
======================================================
+ Hits                    16939    16988      +49     
+ Misses                   3021     2974      -47     

☔ 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 fbdc131 into main Oct 8, 2026
17 checks passed
@maleadt
maleadt deleted the tb/sync-fastpath branch October 8, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Runtime performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant