Skip to content

Commit e49045c

Browse files
Fix type instability in KA.allocate (#665)
* Fix type instability * Better fix
1 parent e60b15a commit e49045c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/MetalKernels.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ The `KernelAbstractions` backend for running on Metal GPUs.
2222
struct MetalBackend <: KA.GPU
2323
end
2424

25-
KA.allocate(::MetalBackend, ::Type{T}, dims::Tuple; unified::Bool = false) where T = MtlArray{T, length(dims), unified ? SharedStorage : DefaultStorageMode}(undef, dims)
25+
# Ensure type stability. See JuliaGPU/KernelAbstractions#634
26+
@inline KA.allocate(::MetalBackend, ::Type{T}, dims::Tuple; unified::Bool = false) where T = MtlArray{T, length(dims), unified ? SharedStorage : DefaultStorageMode}(undef, dims)
2627
KA.zeros(::MetalBackend, ::Type{T}, dims::Tuple; unified::Bool = false) where T = Metal.zeros(T, dims; storage=unified ? SharedStorage : DefaultStorageMode)
2728
KA.ones(::MetalBackend, ::Type{T}, dims::Tuple; unified::Bool = false) where T = Metal.ones(T, dims; storage=unified ? SharedStorage : DefaultStorageMode)
2829

0 commit comments

Comments
 (0)