Skip to content

Legalize barriers for the target AIR version here, not in GPUCompiler - #1099

Merged
maleadt merged 1 commit into
mainfrom
tb/legalize-barriers
Oct 21, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/legalize-barriers

Conversation

@maleadt

@maleadt maleadt commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Device code emits barriers in their AIR 2.9 form, with a memory order, and relied on GPUCompiler (legalize_barrier_abi!, JuliaGPU/GPUCompiler.jl#1020) to drop the order for older AIR versions and to make it sequentially consistent before MSL 4.1. This moves that rewrite into finish_ir!, next to those of the simdgroup matrix and tensor intrinsics, following #1097: GPUCompiler then doesn't need to know the forms Metal.jl emits, and only legalizes the atomics and fences it emits itself.

With the GPUCompiler releases this currently allows, the rewrite there becomes a no-op, so this needs no compat change. It has to be merged before JuliaGPU/GPUCompiler.jl#1047 is released, which removes GPUCompiler's version; no released Metal.jl emits the AIR 2.9 form.

device/intrinsics/{synchronization,simd,atomics} pass on an M1 with macOS 27 against both GPUCompiler 2.16.0 and that branch. Without this change, the barrier ABI tests (Metal 3.2/AIR 2.7, Metal 4.0/AIR 2.9) fail against the branch.

Device code emits barriers in their AIR 2.9 form, with a memory order,
and relied on GPUCompiler to drop it for older targets and to make it
sequentially consistent before MSL 4.1. Do that in `finish_ir!` instead,
next to the rewrites of the other intrinsics device code emits, so that
GPUCompiler doesn't need to know the forms Metal.jl emits and the two
can change independently.
@github-actions

Copy link
Copy Markdown
Contributor

Metal.jl Benchmarks

Details
Benchmark suite Current: d2bae92 Previous: fa8ed24 Ratio
array/accumulate/Float32/1d 417125 ns 409625 ns 1.02
array/accumulate/Float32/dims=1 384792 ns 391583 ns 0.98
array/accumulate/Float32/dims=1L 8944416 ns 8995750 ns 0.99
array/accumulate/Float32/dims=2 463083 ns 472458 ns 0.98
array/accumulate/Float32/dims=2L 3228792 ns 3206042 ns 1.01
array/accumulate/Int64/1d 563583 ns 566875 ns 0.99
array/accumulate/Int64/dims=1 560917 ns 562458 ns 1.00
array/accumulate/Int64/dims=1L 1860083 ns 1831541 ns 1.02
array/accumulate/Int64/dims=2 590709 ns 581583 ns 1.02
array/accumulate/Int64/dims=2L 6188917 ns 6260500 ns 0.99
array/broadcast 228666 ns 221625 ns 1.03
array/construct 2833 ns 2833 ns 1
array/permutedims/2d 373666 ns 383667 ns 0.97
array/permutedims/3d 502416 ns 492125 ns 1.02
array/permutedims/4d 674125 ns 656166 ns 1.03
array/private/copy 266292 ns 246958 ns 1.08
array/private/copyto!/cpu_to_gpu 249292 ns 245417 ns 1.02
array/private/copyto!/gpu_to_cpu 246625 ns 247334 ns 1.00
array/private/copyto!/gpu_to_gpu 196500 ns 188667 ns 1.04
array/private/iteration/findall/bool 545041 ns 537625 ns 1.01
array/private/iteration/findall/int 686250 ns 652167 ns 1.05
array/private/iteration/findfirst/bool 263625 ns 256000 ns 1.03
array/private/iteration/findfirst/int 266084 ns 268667 ns 0.99
array/private/iteration/findmin/1d 321042 ns 316209 ns 1.02
array/private/iteration/findmin/2d 812334 ns 809250 ns 1.00
array/private/iteration/logical 554541 ns 530167 ns 1.05
array/private/iteration/scalar 1816166 ns 1824917 ns 1.00
array/random/rand/Float32 487916 ns 480041 ns 1.02
array/random/rand/Int64 565625 ns 561167 ns 1.01
array/random/rand!/Float32 403083 ns 408292 ns 0.99
array/random/rand!/Int64 428666 ns 425958 ns 1.01
array/random/randn/Float32 403750 ns 393250 ns 1.03
array/random/randn!/Float32 337333 ns 338750 ns 1.00
array/reductions/mapreduce/Float32/1d 215417 ns 212541 ns 1.01
array/reductions/mapreduce/Float32/dims=1 211875 ns 213292 ns 0.99
array/reductions/mapreduce/Float32/dims=1L 665167 ns 652000 ns 1.02
array/reductions/mapreduce/Float32/dims=2 251750 ns 254625 ns 0.99
array/reductions/mapreduce/Float32/dims=2L 415375 ns 428334 ns 0.97
array/reductions/mapreduce/Int64/1d 209583 ns 230458 ns 0.91
array/reductions/mapreduce/Int64/dims=1 225084 ns 231125 ns 0.97
array/reductions/mapreduce/Int64/dims=1L 1085584 ns 1078916 ns 1.01
array/reductions/mapreduce/Int64/dims=2 274250 ns 260750 ns 1.05
array/reductions/mapreduce/Int64/dims=2L 631167 ns 640959 ns 0.98
array/reductions/reduce/Float32/1d 211625 ns 224042 ns 0.94
array/reductions/reduce/Float32/dims=1 195750 ns 195500 ns 1.00
array/reductions/reduce/Float32/dims=1L 653292 ns 655625 ns 1.00
array/reductions/reduce/Float32/dims=2 246458 ns 264167 ns 0.93
array/reductions/reduce/Float32/dims=2L 421750 ns 418958 ns 1.01
array/reductions/reduce/Int64/1d 232958 ns 231958 ns 1.00
array/reductions/reduce/Int64/dims=1 216208 ns 214334 ns 1.01
array/reductions/reduce/Int64/dims=1L 1085083 ns 1080583 ns 1.00
array/reductions/reduce/Int64/dims=2 263250 ns 275625 ns 0.96
array/reductions/reduce/Int64/dims=2L 644459 ns 638042 ns 1.01
array/shared/copy 131417 ns 130125 ns 1.01
array/shared/copyto!/cpu_to_gpu 36291 ns 37041 ns 0.98
array/shared/copyto!/gpu_to_cpu 36916 ns 36792 ns 1.00
array/shared/copyto!/gpu_to_gpu 37417 ns 37334 ns 1.00
array/shared/iteration/findall/bool 567417 ns 540375 ns 1.05
array/shared/iteration/findall/int 687750 ns 687083 ns 1.00
array/shared/iteration/findfirst/bool 277541 ns 283459 ns 0.98
array/shared/iteration/findfirst/int 284250 ns 278084 ns 1.02
array/shared/iteration/findmin/1d 326959 ns 338167 ns 0.97
array/shared/iteration/findmin/2d 817791 ns 813792 ns 1.00
array/shared/iteration/logical 577834 ns 579416 ns 1.00
array/shared/iteration/scalar 82.99180327868852 ns 83.29012345679013 ns 1.00
array/sorting/1d 2012791 ns 2032792 ns 0.99
array/sorting/2d 9012291 ns 9165833 ns 0.98
integration/byval/reference 1100709 ns 1127542 ns 0.98
integration/byval/slices=1 1129833 ns 1131208 ns 1.00
integration/byval/slices=2 2121209 ns 2129500 ns 1.00
integration/byval/slices=3 6860375 ns 6796084 ns 1.01
integration/metaldevrt 392916 ns 375000 ns 1.05
kernel/indexing 211791 ns 207333 ns 1.02
kernel/indexing_checked 382625 ns 372750 ns 1.03
kernel/launch 1579.1 ns 1587.5 ns 0.99
kernel/rand 397250 ns 380250 ns 1.04
latency/import 1520723625 ns 1518648625 ns 1.00
latency/precompile 42524629541 ns 42324049375 ns 1.00
latency/ttfp 1842728708 ns 1839527750 ns 1.00
metal/synchronization/context 594.9720670391062 ns 611.6685714285715 ns 0.97
metal/synchronization/stream 389.30348258706465 ns 396.97014925373134 ns 0.98

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

@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1099      +/-   ##
==========================================
- Coverage   88.18%   88.16%   -0.02%     
==========================================
  Files         105      105              
  Lines        9147     9194      +47     
==========================================
+ Hits         8066     8106      +40     
- Misses       1081     1088       +7     

☔ 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 760a514 into main Oct 21, 2026
20 checks passed
@maleadt
maleadt deleted the tb/legalize-barriers branch October 21, 2026 18:58
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