Repository navigation
Fix type instability in KA.allocate and friends - #2920
Merged
Merged
Conversation
KA.allocate and friends
Contributor
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/CUDAKernels.jl b/src/CUDAKernels.jl
index 5a36ed5ea..f1f6fed2a 100644
--- a/src/CUDAKernels.jl
+++ b/src/CUDAKernels.jl
@@ -21,9 +21,9 @@ end
CUDABackend(; prefer_blocks=false, always_inline=false) = CUDABackend(prefer_blocks, always_inline)
-@inline KA.allocate(::CUDABackend, ::Type{T}, dims::Tuple; unified::Bool = false) where T = CuArray{T, length(dims), unified ? UnifiedMemory : default_memory}(undef, dims)
-@inline KA.zeros(::CUDABackend, ::Type{T}, dims::Tuple; unified::Bool = false) where T = fill!(CuArray{T, length(dims), unified ? UnifiedMemory : default_memory}(undef, dims), zero(T))
-@inline KA.ones(::CUDABackend, ::Type{T}, dims::Tuple; unified::Bool = false) where T = fill!(CuArray{T, length(dims), unified ? UnifiedMemory : default_memory}(undef, dims), one(T))
+@inline KA.allocate(::CUDABackend, ::Type{T}, dims::Tuple; unified::Bool = false) where {T} = CuArray{T, length(dims), unified ? UnifiedMemory : default_memory}(undef, dims)
+@inline KA.zeros(::CUDABackend, ::Type{T}, dims::Tuple; unified::Bool = false) where {T} = fill!(CuArray{T, length(dims), unified ? UnifiedMemory : default_memory}(undef, dims), zero(T))
+@inline KA.ones(::CUDABackend, ::Type{T}, dims::Tuple; unified::Bool = false) where {T} = fill!(CuArray{T, length(dims), unified ? UnifiedMemory : default_memory}(undef, dims), one(T))
KA.get_backend(::CuArray) = CUDABackend()
KA.get_backend(::CUSPARSE.AbstractCuSparseArray) = CUDABackend() |
Contributor
There was a problem hiding this comment.
CUDA.jl Benchmarks
Details
| Benchmark suite | Current: 625734f | Previous: f99784f | Ratio |
|---|---|---|---|
latency/precompile |
56825371079.5 ns |
57505943660.5 ns |
0.99 |
latency/ttfp |
8362433802 ns |
8175596902 ns |
1.02 |
latency/import |
4504698349 ns |
4548330811 ns |
0.99 |
integration/volumerhs |
9620055 ns |
9627247.5 ns |
1.00 |
integration/byval/slices=1 |
146863 ns |
147004 ns |
1.00 |
integration/byval/slices=3 |
426092 ns |
426015 ns |
1.00 |
integration/byval/reference |
145064 ns |
144995 ns |
1.00 |
integration/byval/slices=2 |
286449.5 ns |
286391 ns |
1.00 |
integration/cudadevrt |
103582 ns |
103484 ns |
1.00 |
kernel/indexing |
14230 ns |
14144.5 ns |
1.01 |
kernel/indexing_checked |
15040 ns |
14979 ns |
1.00 |
kernel/occupancy |
751.2258064516129 ns |
696.1307189542483 ns |
1.08 |
kernel/launch |
2193.8888888888887 ns |
2152.1111111111113 ns |
1.02 |
kernel/rand |
15078 ns |
17139 ns |
0.88 |
array/reverse/1d |
19958 ns |
20127 ns |
0.99 |
array/reverse/2dL_inplace |
67043 ns |
66835 ns |
1.00 |
array/reverse/1dL |
70213 ns |
70275 ns |
1.00 |
array/reverse/2d |
22030 ns |
22347 ns |
0.99 |
array/reverse/1d_inplace |
9660 ns |
9616 ns |
1.00 |
array/reverse/2d_inplace |
13454 ns |
13357 ns |
1.01 |
array/reverse/2dL |
73975 ns |
74201 ns |
1.00 |
array/reverse/1dL_inplace |
66868 ns |
66737 ns |
1.00 |
array/copy |
21099 ns |
21034 ns |
1.00 |
array/iteration/findall/int |
158829 ns |
158193.5 ns |
1.00 |
array/iteration/findall/bool |
140684 ns |
140393.5 ns |
1.00 |
array/iteration/findfirst/int |
161899.5 ns |
161096 ns |
1.00 |
array/iteration/findfirst/bool |
162694 ns |
161802 ns |
1.01 |
array/iteration/scalar |
70957.5 ns |
72492 ns |
0.98 |
array/iteration/logical |
219073 ns |
214800 ns |
1.02 |
array/iteration/findmin/1d |
51219.5 ns |
50555 ns |
1.01 |
array/iteration/findmin/2d |
96951 ns |
96485 ns |
1.00 |
array/reductions/reduce/Int64/1d |
44127 ns |
43782 ns |
1.01 |
array/reductions/reduce/Int64/dims=1 |
45275.5 ns |
44868.5 ns |
1.01 |
array/reductions/reduce/Int64/dims=2 |
61688 ns |
61893.5 ns |
1.00 |
array/reductions/reduce/Int64/dims=1L |
89354 ns |
89229.5 ns |
1.00 |
array/reductions/reduce/Int64/dims=2L |
88784.5 ns |
88425 ns |
1.00 |
array/reductions/reduce/Float32/1d |
37703 ns |
37869 ns |
1.00 |
array/reductions/reduce/Float32/dims=1 |
42216 ns |
52159 ns |
0.81 |
array/reductions/reduce/Float32/dims=2 |
60373 ns |
60004 ns |
1.01 |
array/reductions/reduce/Float32/dims=1L |
52813 ns |
52689 ns |
1.00 |
array/reductions/reduce/Float32/dims=2L |
73027 ns |
72514 ns |
1.01 |
array/reductions/mapreduce/Int64/1d |
44293 ns |
44158 ns |
1.00 |
array/reductions/mapreduce/Int64/dims=1 |
55394.5 ns |
44917.5 ns |
1.23 |
array/reductions/mapreduce/Int64/dims=2 |
62037 ns |
61973 ns |
1.00 |
array/reductions/mapreduce/Int64/dims=1L |
89209.5 ns |
89251 ns |
1.00 |
array/reductions/mapreduce/Int64/dims=2L |
89062 ns |
88531 ns |
1.01 |
array/reductions/mapreduce/Float32/1d |
37624 ns |
37472.5 ns |
1.00 |
array/reductions/mapreduce/Float32/dims=1 |
42588 ns |
52480 ns |
0.81 |
array/reductions/mapreduce/Float32/dims=2 |
60640 ns |
60249 ns |
1.01 |
array/reductions/mapreduce/Float32/dims=1L |
53066 ns |
52856 ns |
1.00 |
array/reductions/mapreduce/Float32/dims=2L |
73107 ns |
72524 ns |
1.01 |
array/broadcast |
20318 ns |
20030 ns |
1.01 |
array/copyto!/gpu_to_gpu |
11592 ns |
11386 ns |
1.02 |
array/copyto!/cpu_to_gpu |
214303 ns |
216869 ns |
0.99 |
array/copyto!/gpu_to_cpu |
283419.5 ns |
286424.5 ns |
0.99 |
array/accumulate/Int64/1d |
125471.5 ns |
124830 ns |
1.01 |
array/accumulate/Int64/dims=1 |
83614 ns |
83529 ns |
1.00 |
array/accumulate/Int64/dims=2 |
158090 ns |
157818 ns |
1.00 |
array/accumulate/Int64/dims=1L |
1709189 ns |
1709864 ns |
1.00 |
array/accumulate/Int64/dims=2L |
966553.5 ns |
966626.5 ns |
1.00 |
array/accumulate/Float32/1d |
109202 ns |
109404 ns |
1.00 |
array/accumulate/Float32/dims=1 |
80483.5 ns |
80482 ns |
1.00 |
array/accumulate/Float32/dims=2 |
147818 ns |
147930.5 ns |
1.00 |
array/accumulate/Float32/dims=1L |
1618323 ns |
1618960.5 ns |
1.00 |
array/accumulate/Float32/dims=2L |
698575.5 ns |
698784 ns |
1.00 |
array/construct |
1294.9 ns |
1292.1 ns |
1.00 |
array/random/randn/Float32 |
48987 ns |
45521 ns |
1.08 |
array/random/randn!/Float32 |
25032 ns |
24996 ns |
1.00 |
array/random/rand!/Int64 |
27317 ns |
27279 ns |
1.00 |
array/random/rand!/Float32 |
8874.666666666666 ns |
8755 ns |
1.01 |
array/random/rand/Int64 |
30025 ns |
30194 ns |
0.99 |
array/random/rand/Float32 |
13266 ns |
13350 ns |
0.99 |
array/permutedims/4d |
60270.5 ns |
59834 ns |
1.01 |
array/permutedims/2d |
54154 ns |
53788.5 ns |
1.01 |
array/permutedims/3d |
55101.5 ns |
54729 ns |
1.01 |
array/sorting/1d |
2758440 ns |
2758146 ns |
1.00 |
array/sorting/by |
3344794 ns |
3344254 ns |
1.00 |
array/sorting/2d |
1081223 ns |
1080860 ns |
1.00 |
cuda/synchronization/stream/auto |
1030.8461538461538 ns |
1008.3 ns |
1.02 |
cuda/synchronization/stream/nonblocking |
8271.4 ns |
7614.8 ns |
1.09 |
cuda/synchronization/stream/blocking |
838.1894736842105 ns |
789.4040404040404 ns |
1.06 |
cuda/synchronization/context/auto |
1162.3 ns |
1182.6 ns |
0.98 |
cuda/synchronization/context/nonblocking |
7157.1 ns |
8392.2 ns |
0.85 |
cuda/synchronization/context/blocking |
897.3260869565217 ns |
890.468085106383 ns |
1.01 |
This comment was automatically generated by workflow using github-action-benchmark.
maleadt
approved these changes
Oct 7, 2025
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2920 +/- ##
==========================================
- Coverage 89.37% 89.35% -0.03%
==========================================
Files 150 150
Lines 13086 13086
==========================================
- Hits 11696 11693 -3
- Misses 1390 1393 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
JuliaGPU/KernelAbstractions.jl#634
@vchuravy