KernelAbstractions.jl
KernelAbstractions.jl copied to clipboard
creation of a subarray for function calls results in an error with throw_checksize_error
Here's the mwe:
using Test
using CUDA
using CUDAKernels
using KernelAbstractions
function check(input, tid)
end
@kernel function f_test_kernel!(input)
tid = @index(Global, Linear)
check(input[:], tid)
end
function f_test!(input; numcores = 4, numthreads = 256)
if isa(input, Array)
kernel! = f_test_kernel!(CPU(), numcores)
else
kernel! = f_test_kernel!(CUDADevice(), numthreads)
end
kernel!(input, ndrange=size(input))
end
Gotta be honest, I am not sure if this behavior should be allowed, but I could imagine a case where people want to index along different subarray or something. I think there are almost always workarounds for this that make more sense in parallel.
As a note, input[:] = 0 should probably also be disallowed for a similar reason; however, if we want to support this type of behavior, we could create an override for the checksize error. The issue is that it allocates a string for the error:
@noinline throw_checksize_error(A, sz) = throw(DimensionMismatch("output array is the wrong size; expected $sz, got $(size(A))"))
I am leaving this as an issue because it's not pressing to fix for me, but I figured someone should mention it.
For the record, I did try something like this:
#@inline Cassette.overdub(::$Ctx, ::Core.Typeof(Base.throw_checksize_error), args...) = throw(DimensionMismatch("output array is the wrong size; expected $args[2], got $(size(args[1]))"))
But it didn't work