Weird behavior in @cuda kernel dispatch

CuVector and CuArray are host representations of cuda memory buffers. Because of this, they carry a lot of metadata and extraneous fields that don’t make any sense in the context of a cuda kernel (which expects little more than an unadorned pointer to some device memory). That’s the role CuDeviceVector and CuDeviceArray fill.

When you invoke a kernel with @cuda, CUDA.jl will auto-convert between host and device arrays. However, since my_kernel only accepts host arrays, julia will throw a MethodError when CUDA.jl tries to invoke it as GPU-side code with a device array. The easiest way to resolve this would be to remove the type annotation from my_kernel, since you’re likely only ever going to be calling it via @cuda anyhow.

2 Likes