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

**URL:** <https://discourse.julialang.org/t/how-to-move-an-array-of-struct-with-array-members-to-gpu/110240>\
**Category:** GPU\
**Created:** [February 15, 2024, 7:54am UTC](https://discourse.julialang.org/t/how-to-move-an-array-of-struct-with-array-members-to-gpu/110240 "2024-02-15T07:54:59Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [February 15, 2024, 8:20am UTC](https://discourse.julialang.org/t/how-to-move-an-array-of-struct-with-array-members-to-gpu/110240/2 "2024-02-15T08:20:23Z")

</div>

> [@zhzhang](#):
>
> can I 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 `cell`s 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 `CuDeviceArray`s 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](https://discourse.julialang.org/t/arrays-of-arrays-and-arrays-of-structures-in-cuda-kernels-cause-random-errors/69739/21)

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

---

_[View the full topic](https://discourse.julialang.org/t/how-to-move-an-array-of-struct-with-array-members-to-gpu/110240)._
