Passing a wrapped array to a kernel

Hi,

I’m trying to pass an object with a wrapped CuArray to a kernel:

import CUDA
struct MyStruct
    arrayField::CUDA.CuArray{Float32, 1, Nothing}
end

function f!(obj::MyStruct)
    id = CUDA.threadIdx().x
    if id <= length(a)
        obj.arrayField[id] = id
    end
    nothing
end

myObj = MyStruct(CUDA.fill(0.0, 5))
CUDA.@cuda threads = length(myObj) f!(myObj)

This fails with error message

GPU compilation of kernel f!(MyStruct) failed
KernelError: recursion is currently not supported

Is this a bug or am I doing something wrong?

Thanks

CuArray is the host-representation of a CUDA array, you need CuDeviceArray. That conversion happens automatically for known types, but you need to register your own Adapt.jl conversions for custom types.

2 Likes

I see, thanks!