KernelAbstractions.jl icon indicating copy to clipboard operation
KernelAbstractions.jl copied to clipboard

`@localmem` silently breaks things when used with non-const dims

Open gdalle opened this issue 8 months ago • 2 comments

I'm not sure how to explain this behavior, it's like @localmem cancels the effects of the kernel:

julia> using Metal, KernelAbstractions

julia> backend = Metal.MetalBackend()
MetalBackend()

julia> @kernel function settoone_localmem!(x::AbstractVector)
           i = @index(Global)
           n = length(x)
           y = @localmem Bool (n,)
           x[i] = one(eltype(x))
       end
settoone_localmem! (generic function with 4 methods)

julia> @kernel function settoone_nolocalmem!(x::AbstractVector)
           i = @index(Global)
           x[i] = one(eltype(x))
       end
settoone_nolocalmem! (generic function with 4 methods)

julia> x = KernelAbstractions.zeros(backend, Float32, 3);

julia> settoone_localmem!(backend)(x; ndrange=length(x))  # fails

julia> x
3-element MtlVector{Float32, Metal.PrivateStorage}:
 0.0
 0.0
 0.0

julia> settoone_nolocalmem!(backend)(x; ndrange=length(x))  # works

julia> x
3-element MtlVector{Float32, Metal.PrivateStorage}:
 1.0
 1.0
 1.0

gdalle avatar Mar 25 '25 21:03 gdalle