How to move an array of struct with array members to GPU?

Not easily. The problem is that when launching a kernel, we convert CuArray to CuDeviceArray. When passing objects that contain CuArrays (e.g. your grid with cells here), we would need to allocate new objects containing CuDeviceArrays, which is generally unacceptably expensive for a kernel launch. If you really want to do this, there’s a couple of hacky solutions to be found on Discourse here, which either boil down to you manually putting CuDeviceArrays in your structures, or using a more complicated adaptor like Arrays of arrays and arrays of structures in CUDA kernels cause random errors - #21 by maleadt

Also note that for cell to be GPU compatible, it cannot contain an AbstractArray, but the b type should be parametric.

3 Likes