Skip to content

Use GPUArrays 12's reductions, scans, sorting and findall - #1013

Open
maleadt wants to merge 1 commit into
mainfrom
tb/gpuarrays-12
Open

maleadt wants to merge 1 commit into
mainfrom
tb/gpuarrays-12

Conversation

@maleadt

@maleadt maleadt commented Oct 7, 2026

Copy link
Copy Markdown
Member

Ports Metal.jl to GPUArrays 12, which implements Base's reductions, sorting, scans, findall, logical indexing and reverse once for every GPU array, on AcceleratedKernels 0.5 (JuliaGPU/GPUArrays.jl#790), and removes the GPUArrays.mapreducedim! hook.

  • Deletes Metal's reduction kernels and the MPSGraph reductions (Metal.reduce_alg). GPUArrays 12 has no hook for vendor reductions; one can come in a 12.x minor if benchmarks show MPSGraph is worth it.
  • Deletes the native scan, findall and logical indexing.
  • Keeps MPSGraph as the fast path for sorting and scans (Metal.scan_alg); everything else goes to GPUArrays' methods instead of Base's scalar ones. Sorting now accepts AcceleratedKernels' algorithms, and sortperm is stable by default, as in Base: MPSGraph's argsort is only used when the algorithm allows an unstable result.

Intended as a minor release. Supersedes #874 (simd shuffles in the native scan, which is gone).

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Metal.jl Benchmarks

Details
Benchmark suite Current: e3c5a11 Previous: bfe34d9 Ratio
array/accumulate/Float32/1d 396958 ns 391125 ns 1.01
array/accumulate/Float32/dims=1 352416 ns 365083 ns 0.97
array/accumulate/Float32/dims=1L 8865708 ns 8882000 ns 1.00
array/accumulate/Float32/dims=2 429125 ns 429250 ns 1.00
array/accumulate/Float32/dims=2L 2573625 ns 2203000 ns 1.17
array/accumulate/Int64/1d 776958 ns 847708 ns 0.92
array/accumulate/Int64/dims=1 878250 ns 912958 ns 0.96
array/accumulate/Int64/dims=1L 3780625 ns 9542583 ns 0.40
array/accumulate/Int64/dims=2 1079583 ns 1215708 ns 0.89
array/accumulate/Int64/dims=2L 14720708 ns 6558375 ns 2.24
array/broadcast 240042 ns 227250 ns 1.06
array/construct 2375 ns 2375 ns 1
array/permutedims/2d 454583 ns 460084 ns 0.99
array/permutedims/3d 1028000 ns 1025583 ns 1.00
array/permutedims/4d 1100334 ns 1119125 ns 0.98
array/private/copy 221958 ns 227333 ns 0.98
array/private/copyto!/cpu_to_gpu 223583 ns 212291 ns 1.05
array/private/copyto!/gpu_to_cpu 220375 ns 212625 ns 1.04
array/private/copyto!/gpu_to_gpu 218916 ns 219375 ns 1.00
array/private/iteration/findall/bool 539542 ns 1043625 ns 0.52
array/private/iteration/findall/int 617875 ns 1213625 ns 0.51
array/private/iteration/findfirst/bool 377625 ns 1015208 ns 0.37
array/private/iteration/findfirst/int 381375 ns 1021792 ns 0.37
array/private/iteration/findmin/1d 383333 ns 1092209 ns 0.35
array/private/iteration/findmin/2d 622791 ns 1036125 ns 0.60
array/private/iteration/logical 540750 ns 1540542 ns 0.35
array/private/iteration/scalar 1397000 ns 1391708 ns 1.00
array/random/rand/Float32 420125 ns 420583 ns 1.00
array/random/rand/Int64 498167 ns 498791 ns 1.00
array/random/rand!/Float32 405250 ns 403375 ns 1.00
array/random/rand!/Int64 428375 ns 429500 ns 1.00
array/random/randn/Float32 386833 ns 391167 ns 0.99
array/random/randn!/Float32 374250 ns 373917 ns 1.00
array/reductions/mapreduce/Float32/1d 246459 ns 274208 ns 0.90
array/reductions/mapreduce/Float32/dims=1 392292 ns 352959 ns 1.11
array/reductions/mapreduce/Float32/dims=1L 590458 ns 603125 ns 0.98
array/reductions/mapreduce/Float32/dims=2 329375 ns 358084 ns 0.92
array/reductions/mapreduce/Float32/dims=2L 458584 ns 1245500 ns 0.37
array/reductions/mapreduce/Int64/1d 255375 ns 458125 ns 0.56
array/reductions/mapreduce/Int64/dims=1 431917 ns 635584 ns 0.68
array/reductions/mapreduce/Int64/dims=1L 1008209 ns 1011667 ns 1.00
array/reductions/mapreduce/Int64/dims=2 325542 ns 788208 ns 0.41
array/reductions/mapreduce/Int64/dims=2L 631209 ns 2204250 ns 0.29
array/reductions/reduce/Float32/1d 234959 ns 268917 ns 0.87
array/reductions/reduce/Float32/dims=1 392875 ns 357458 ns 1.10
array/reductions/reduce/Float32/dims=1L 593125 ns 613250 ns 0.97
array/reductions/reduce/Float32/dims=2 333583 ns 248708 ns 1.34
array/reductions/reduce/Float32/dims=2L 446084 ns 468458 ns 0.95
array/reductions/reduce/Int64/1d 259166 ns 453750 ns 0.57
array/reductions/reduce/Int64/dims=1 428417 ns 641667 ns 0.67
array/reductions/reduce/Int64/dims=1L 1004083 ns 1004125 ns 1.00
array/reductions/reduce/Int64/dims=2 344709 ns 260208 ns 1.32
array/reductions/reduce/Int64/dims=2L 628541 ns 666041 ns 0.94
array/shared/copy 128833 ns 129375 ns 1.00
array/shared/copyto!/cpu_to_gpu 37291 ns 36541 ns 1.02
array/shared/copyto!/gpu_to_cpu 37125 ns 38125 ns 0.97
array/shared/copyto!/gpu_to_gpu 37333 ns 38500 ns 0.97
array/shared/iteration/findall/bool 543042 ns 1051583 ns 0.52
array/shared/iteration/findall/int 614791 ns 1215334 ns 0.51
array/shared/iteration/findfirst/bool 376459 ns 974709 ns 0.39
array/shared/iteration/findfirst/int 381833 ns 986416 ns 0.39
array/shared/iteration/findmin/1d 378333 ns 1063708 ns 0.36
array/shared/iteration/findmin/2d 504500 ns 1025750 ns 0.49
array/shared/iteration/logical 542833 ns 1524291 ns 0.36
array/shared/iteration/scalar 80.32955715756951 ns 77.34394250513347 ns 1.04
array/sorting/1d 1908209 ns 1916583 ns 1.00
array/sorting/2d 8292708 ns 8256666 ns 1.00
integration/byval/reference 1113625 ns 1121334 ns 0.99
integration/byval/slices=1 1106708 ns 1126292 ns 0.98
integration/byval/slices=2 2024250 ns 2029166 ns 1.00
integration/byval/slices=3 6768542 ns 6991667 ns 0.97
integration/metaldevrt 392083 ns 395792 ns 0.99
kernel/indexing 208458 ns 214541 ns 0.97
kernel/indexing_checked 396292 ns 394167 ns 1.01
kernel/launch 2138.8888888888887 ns 2111.1111111111113 ns 1.01
kernel/rand 408375 ns 408833 ns 1.00
latency/import 1967763958 ns 1608627167 ns 1.22
latency/precompile 40907675333 ns 32823841792 ns 1.25
latency/ttfp 2218190291 ns 2063787291 ns 1.07
metal/synchronization/context 522.6910994764398 ns 536.1587301587301 ns 0.97
metal/synchronization/stream 628.1882352941177 ns 620.6395348837209 ns 1.01

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

GPUArrays 12 implements these for every GPU array on AcceleratedKernels and no
longer calls the mapreducedim! hook. Delete Metal's reduction kernels, its
MPSGraph reductions (GPUArrays 12 has no hook for vendor reductions), the native
scan, findall and logical indexing. MPSGraph stays the fast path for sorting and
scans, with everything else handed to GPUArrays' methods instead of Base's
scalar ones. Sorting now accepts AcceleratedKernels' algorithms, and sortperm is
stable by default, as in Base: MPSGraph's argsort is only used when the
algorithm allows an unstable result.

This branch has not been deployed

No deployments
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