[Do not merge] Test KernelIntrinsics#688
Open
christiangnrd wants to merge 10 commits into
Open
Conversation
Contributor
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/MetalKernels.jl b/src/MetalKernels.jl
index 4e856194..7573c5e1 100644
--- a/src/MetalKernels.jl
+++ b/src/MetalKernels.jl
@@ -136,26 +136,26 @@ end
KI.argconvert(::MetalBackend, arg) = mtlconvert(arg)
-function KI.kernel_function(::MetalBackend, f::F, tt::TT=Tuple{}; name=nothing, kwargs...) where {F,TT}
+function KI.kernel_function(::MetalBackend, f::F, tt::TT = Tuple{}; name = nothing, kwargs...) where {F, TT}
kern = mtlfunction(f, tt; name, kwargs...)
- KI.Kernel{MetalBackend, typeof(kern)}(MetalBackend(), kern)
+ return KI.Kernel{MetalBackend, typeof(kern)}(MetalBackend(), kern)
end
-function (obj::KI.Kernel{MetalBackend})(args...; numworkgroups=1, workgroupsize=1)
+function (obj::KI.Kernel{MetalBackend})(args...; numworkgroups = 1, workgroupsize = 1)
KI.check_launch_args(numworkgroups, workgroupsize)
- obj.kern(args...; threads=workgroupsize, groups=numworkgroups)
+ return obj.kern(args...; threads = workgroupsize, groups = numworkgroups)
end
-function KI.kernel_max_work_group_size(kikern::KI.Kernel{<:MetalBackend}; max_work_items::Int=typemax(Int))::Int
- Int(min(kikern.kern.pipeline.maxTotalThreadsPerThreadgroup, max_work_items))
+function KI.kernel_max_work_group_size(kikern::KI.Kernel{<:MetalBackend}; max_work_items::Int = typemax(Int))::Int
+ return Int(min(kikern.kern.pipeline.maxTotalThreadsPerThreadgroup, max_work_items))
end
function KI.max_work_group_size(::MetalBackend)::Int
- Int(device().maxThreadsPerThreadgroup.width)
+ return Int(device().maxThreadsPerThreadgroup.width)
end
function KI.multiprocessor_count(::MetalBackend)::Int
- Metal.num_gpu_cores()
+ return Metal.num_gpu_cores()
end
diff --git a/src/broadcast.jl b/src/broadcast.jl
index 5d107ec2..3455fad2 100644
--- a/src/broadcast.jl
+++ b/src/broadcast.jl
@@ -66,9 +66,9 @@ end
if _broadcast_shapes[Is] > BROADCAST_SPECIALIZATION_THRESHOLD
## COV_EXCL_START
function broadcast_cartesian_static(dest, bc, Is)
- i = KI.get_global_id().x
- stride = KI.get_global_size().x
- while 1 <= i <= length(dest)
+ i = KI.get_global_id().x
+ stride = KI.get_global_size().x
+ while 1 <= i <= length(dest)
I = @inbounds Is[i]
@inbounds dest[I] = bc[I]
i += stride
@@ -91,13 +91,13 @@ end
(isa(IndexStyle(dest), IndexLinear) && isa(IndexStyle(bc), IndexLinear))
## COV_EXCL_START
function broadcast_linear(dest, bc)
- i = KI.get_global_id().x
- stride = KI.get_global_size().x
- while 1 <= i <= length(dest)
- @inbounds dest[i] = bc[i]
- i += stride
- end
- return
+ i = KI.get_global_id().x
+ stride = KI.get_global_size().x
+ while 1 <= i <= length(dest)
+ @inbounds dest[i] = bc[i]
+ i += stride
+ end
+ return
end
## COV_EXCL_STOP
@@ -168,9 +168,9 @@ end
else
## COV_EXCL_START
function broadcast_cartesian(dest, bc)
- i = KI.get_global_id().x
- stride = KI.get_global_size().x
- while 1 <= i <= length(dest)
+ i = KI.get_global_id().x
+ stride = KI.get_global_size().x
+ while 1 <= i <= length(dest)
I = @inbounds CartesianIndices(dest)[i]
@inbounds dest[I] = bc[I]
i += stride
diff --git a/src/device/random.jl b/src/device/random.jl
index 12b053a2..edc999cd 100644
--- a/src/device/random.jl
+++ b/src/device/random.jl
@@ -89,8 +89,8 @@ end
@inbounds global_random_counters()[simdgroupId]
elseif field === :ctr2
globalId = KI.get_global_id().x +
- (KI.get_global_id().y - 1i32) * KI.get_global_size().x +
- (KI.get_global_id().z - 1i32) * KI.get_global_size().x * KI.get_global_size().y
+ (KI.get_global_id().y - 1i32) * KI.get_global_size().x +
+ (KI.get_global_id().z - 1i32) * KI.get_global_size().x * KI.get_global_size().y
globalId % UInt32
end::UInt32
end
diff --git a/src/mapreduce.jl b/src/mapreduce.jl
index 7be5ef43..a737e8d0 100644
--- a/src/mapreduce.jl
+++ b/src/mapreduce.jl
@@ -224,7 +224,8 @@ function GPUArrays.mapreducedim!(f::F, op::OP, R::WrappedMtlArray{T},
# we might not be able to launch all those threads to reduce each slice in one go.
# that's why each threads also loops across their inputs, processing multiple values
# so that we can span the entire reduction dimension using a single item group.
- kernel = KI.@kernel backend launch = false partial_mapreduce_device(f, op, init, Val(maxthreads), Val(Rreduce), Val(Rother),
+ kernel = KI.@kernel backend launch = false partial_mapreduce_device(
+ f, op, init, Val(maxthreads), Val(Rreduce), Val(Rother),
Val(UInt64(length(Rother))), Val(grain), Val(shuffle), R, A)
# how many threads do we want?
@@ -260,7 +261,8 @@ function GPUArrays.mapreducedim!(f::F, op::OP, R::WrappedMtlArray{T},
# we can cover the dimensions to reduce using a single group
kernel(f, op, init, Val(maxthreads), Val(Rreduce), Val(Rother),
Val(UInt64(length(Rother))), Val(grain), Val(shuffle), R, A;
- workgroupsize = threads, numworkgroups = groups)
+ workgroupsize = threads, numworkgroups = groups
+ )
else
# temporary empty array whose type will match the final partial array
partial = similar(R, ntuple(_ -> 0, Val(ndims(R)+1)))
@@ -287,7 +289,8 @@ function GPUArrays.mapreducedim!(f::F, op::OP, R::WrappedMtlArray{T},
partial_kernel(f, op, init, Val(threads), Val(Rreduce),
Val(Rother), Val(UInt64(length(Rother))),
Val(grain), Val(shuffle), partial, A;
- numworkgroups = partial_groups, workgroupsize = partial_threads)
+ numworkgroups = partial_groups, workgroupsize = partial_threads
+ )
GPUArrays.mapreducedim!(identity, op, R, partial; init=init)
end
diff --git a/test/kernelabstractions.jl b/test/kernelabstractions.jl
index cda5b249..339fcbc8 100644
--- a/test/kernelabstractions.jl
+++ b/test/kernelabstractions.jl
@@ -7,6 +7,6 @@ Testsuite.testsuite(MetalBackend, "Metal", Metal, MtlArray, Metal.MtlDeviceArray
"Convert", # depends on https://github.com/JuliaGPU/Metal.jl/issues/69
"SpecialFunctions", # gamma and erfc not currently supported on Metal.jl
"sparse", # not supported yet
- "CPU synchronization",
- "fallback test: callable types",
+ "CPU synchronization",
+ "fallback test: callable types",
]))
diff --git a/test/runtests.jl b/test/runtests.jl
index 32b45c8c..14fcfb93 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -1,6 +1,6 @@
@static if VERSION < v"1.11" && get(ENV, "BUILDKITE_PIPELINE_NAME", "Metal.jl") == "Metal.jl"
using Pkg
- Pkg.add(url="https://github.com/JuliaGPU/KernelAbstractions.jl", rev="main")
+ Pkg.add(url = "https://github.com/JuliaGPU/KernelAbstractions.jl", rev = "main")
end
using Metal |
christiangnrd
force-pushed
the
kaintr
branch
3 times, most recently
from
October 22, 2025 04:31
9ac3d49 to
6314372
Compare
Contributor
There was a problem hiding this comment.
Metal Benchmarks
Details
| Benchmark suite | Current: 7f653a1 | Previous: ac0202d | Ratio |
|---|---|---|---|
array/accumulate/Float32/1d |
406916 ns |
407375 ns |
1.00 |
array/accumulate/Float32/dims=1 |
377959 ns |
351791 ns |
1.07 |
array/accumulate/Float32/dims=1L |
8804750 ns |
8796584 ns |
1.00 |
array/accumulate/Float32/dims=2 |
451000 ns |
439792 ns |
1.03 |
array/accumulate/Float32/dims=2L |
2686083 ns |
2603208 ns |
1.03 |
array/accumulate/Int64/1d |
913375 ns |
842333 ns |
1.08 |
array/accumulate/Int64/dims=1 |
1060375 ns |
944125 ns |
1.12 |
array/accumulate/Int64/dims=1L |
9665667 ns |
9521000 ns |
1.02 |
array/accumulate/Int64/dims=2 |
1035667 ns |
1247208 ns |
0.83 |
array/accumulate/Int64/dims=2L |
6523042 ns |
6499125 ns |
1.00 |
array/broadcast |
230167 ns |
222000 ns |
1.04 |
array/construct |
2333 ns |
2417 ns |
0.97 |
array/permutedims/2d |
525334 ns |
449458 ns |
1.17 |
array/permutedims/3d |
1127917 ns |
1011000 ns |
1.12 |
array/permutedims/4d |
1479042 ns |
1275416 ns |
1.16 |
array/private/copy |
239167 ns |
229791 ns |
1.04 |
array/private/copyto!/cpu_to_gpu |
199417 ns |
195833 ns |
1.02 |
array/private/copyto!/gpu_to_cpu |
196875 ns |
194167 ns |
1.01 |
array/private/copyto!/gpu_to_gpu |
212042 ns |
173708 ns |
1.22 |
array/private/iteration/findall/bool |
1146458 ns |
1057250 ns |
1.08 |
array/private/iteration/findall/int |
1290083 ns |
1228125 ns |
1.05 |
array/private/iteration/findfirst/bool |
1162291 ns |
1111542 ns |
1.05 |
array/private/iteration/findfirst/int |
1185208 ns |
1117792 ns |
1.06 |
array/private/iteration/findmin/1d |
1283458 ns |
1229625 ns |
1.04 |
array/private/iteration/findmin/2d |
785458 ns |
769709 ns |
1.02 |
array/private/iteration/logical |
1815791 ns |
1688959 ns |
1.08 |
array/private/iteration/scalar |
1250250 ns |
1216958 ns |
1.03 |
array/random/rand/Float32 |
398916 ns |
426125 ns |
0.94 |
array/random/rand/Int64 |
519625 ns |
513417 ns |
1.01 |
array/random/rand!/Float32 |
381833 ns |
313042 ns |
1.22 |
array/random/rand!/Int64 |
409917 ns |
406791 ns |
1.01 |
array/random/randn/Float32 |
340875 ns |
391833 ns |
0.87 |
array/random/randn!/Float32 |
356375 ns |
340208 ns |
1.05 |
array/reductions/mapreduce/Float32/1d |
439500 ns |
383792 ns |
1.15 |
array/reductions/mapreduce/Float32/dims=1 |
269083 ns |
263000 ns |
1.02 |
array/reductions/mapreduce/Float32/dims=1L |
625417 ns |
621791 ns |
1.01 |
array/reductions/mapreduce/Float32/dims=2 |
362417 ns |
275708 ns |
1.31 |
array/reductions/mapreduce/Float32/dims=2L |
1050208 ns |
841125 ns |
1.25 |
array/reductions/mapreduce/Int64/1d |
614750 ns |
621125 ns |
0.99 |
array/reductions/mapreduce/Int64/dims=1 |
440208 ns |
450958 ns |
0.98 |
array/reductions/mapreduce/Int64/dims=1L |
1031625 ns |
1026500 ns |
1.00 |
array/reductions/mapreduce/Int64/dims=2 |
570334 ns |
778292 ns |
0.73 |
array/reductions/mapreduce/Int64/dims=2L |
2246167 ns |
2179166 ns |
1.03 |
array/reductions/reduce/Float32/1d |
437750 ns |
412916 ns |
1.06 |
array/reductions/reduce/Float32/dims=1 |
287917 ns |
345084 ns |
0.83 |
array/reductions/reduce/Float32/dims=1L |
632167 ns |
635167 ns |
1.00 |
array/reductions/reduce/Float32/dims=2 |
231458 ns |
228750 ns |
1.01 |
array/reductions/reduce/Float32/dims=2L |
450125 ns |
448708 ns |
1.00 |
array/reductions/reduce/Int64/1d |
593875 ns |
576542 ns |
1.03 |
array/reductions/reduce/Int64/dims=1 |
613375 ns |
614541 ns |
1.00 |
array/reductions/reduce/Int64/dims=1L |
1024666 ns |
1030125 ns |
0.99 |
array/reductions/reduce/Int64/dims=2 |
244459 ns |
240250 ns |
1.02 |
array/reductions/reduce/Int64/dims=2L |
655375 ns |
644833 ns |
1.02 |
array/shared/copy |
136625 ns |
136583 ns |
1.00 |
array/shared/copyto!/cpu_to_gpu |
37708 ns |
38292 ns |
0.98 |
array/shared/copyto!/gpu_to_cpu |
38000 ns |
38167 ns |
1.00 |
array/shared/copyto!/gpu_to_gpu |
38292 ns |
38917 ns |
0.98 |
array/shared/iteration/findall/bool |
1142708 ns |
1076292 ns |
1.06 |
array/shared/iteration/findall/int |
1304458 ns |
1220458 ns |
1.07 |
array/shared/iteration/findfirst/bool |
1002791 ns |
956459 ns |
1.05 |
array/shared/iteration/findfirst/int |
848000 ns |
650041 ns |
1.30 |
array/shared/iteration/findmin/1d |
1152333 ns |
1089541 ns |
1.06 |
array/shared/iteration/findmin/2d |
1088958 ns |
1075500 ns |
1.01 |
array/shared/iteration/logical |
1446500 ns |
1553459 ns |
0.93 |
array/shared/iteration/scalar |
4160.714285714285 ns |
4023.714285714286 ns |
1.03 |
array/sorting/1d |
1603541 ns |
1786083 ns |
0.90 |
array/sorting/2d |
8302125 ns |
8305833 ns |
1.00 |
integration/byval/reference |
1111167 ns |
1119042 ns |
0.99 |
integration/byval/slices=1 |
1104792 ns |
1109583 ns |
1.00 |
integration/byval/slices=2 |
2022583 ns |
2021291 ns |
1.00 |
integration/byval/slices=3 |
7723750 ns |
6610875 ns |
1.17 |
integration/metaldevrt |
387458 ns |
379833 ns |
1.02 |
kernel/indexing |
207125 ns |
208708 ns |
0.99 |
kernel/indexing_checked |
374583 ns |
370667 ns |
1.01 |
kernel/launch |
1891.6 ns |
1883.3 ns |
1.00 |
kernel/rand |
393750 ns |
393792 ns |
1.00 |
latency/import |
2208580083 ns |
2038510291 ns |
1.08 |
latency/precompile |
44965841000 ns |
38792921333 ns |
1.16 |
latency/ttfp |
2539808458 ns |
2354706125 ns |
1.08 |
metal/synchronization/context |
583.5635359116022 ns |
583.7912087912088 ns |
1.00 |
metal/synchronization/stream |
331.4663677130045 ns |
332.58744394618833 ns |
1.00 |
This comment was automatically generated by workflow using github-action-benchmark.
christiangnrd
force-pushed
the
kaintr
branch
3 times, most recently
from
October 22, 2025 13:38
22e754e to
68db9c2
Compare
christiangnrd
force-pushed
the
kaintr
branch
2 times, most recently
from
November 2, 2025 21:16
2b8dce1 to
0e76668
Compare
christiangnrd
force-pushed
the
kaintr
branch
9 times, most recently
from
November 6, 2025 22:27
db9a7dc to
c802ccc
Compare
christiangnrd
force-pushed
the
kaintr
branch
6 times, most recently
from
November 18, 2025 01:36
4b8f026 to
ce67b4c
Compare
christiangnrd
force-pushed
the
kaintr
branch
from
December 12, 2025 20:39
ce67b4c to
03bb0dd
Compare
christiangnrd
force-pushed
the
kaintr
branch
2 times, most recently
from
January 19, 2026 19:56
415079d to
90e4fb2
Compare
christiangnrd
force-pushed
the
kaintr
branch
from
February 13, 2026 16:00
90e4fb2 to
ee7543a
Compare
christiangnrd
force-pushed
the
kaintr
branch
4 times, most recently
from
June 12, 2026 15:19
9f95616 to
fb61557
Compare
christiangnrd
force-pushed
the
kaintr
branch
3 times, most recently
from
June 17, 2026 18:54
86196fa to
9ee5724
Compare
christiangnrd
force-pushed
the
kaintr
branch
2 times, most recently
from
July 1, 2026 13:45
b36b4ba to
cf3cbfb
Compare
christiangnrd
force-pushed
the
kaintr
branch
3 times, most recently
from
July 2, 2026 15:31
dae5922 to
e1c67c7
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #688 +/- ##
==========================================
- Coverage 86.21% 86.20% -0.01%
==========================================
Files 76 76
Lines 5246 5264 +18
==========================================
+ Hits 4523 4538 +15
- Misses 723 726 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
christiangnrd
force-pushed
the
kaintr
branch
2 times, most recently
from
July 15, 2026 13:47
89a8970 to
f33628b
Compare
christiangnrd
force-pushed
the
kaintr
branch
2 times, most recently
from
July 17, 2026 15:31
dc9333b to
52bdf27
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Not a draft to also run benchmarks