# Arrays of arrays and arrays of structures in CUDA kernels cause random errors

**URL:** <https://discourse.julialang.org/t/arrays-of-arrays-and-arrays-of-structures-in-cuda-kernels-cause-random-errors/69739>\
**Category:** GPU\
**Tags:** gpu, cuda\
**Created:** [October 14, 2021, 10:41am UTC](https://discourse.julialang.org/t/arrays-of-arrays-and-arrays-of-structures-in-cuda-kernels-cause-random-errors/69739 "2021-10-14T10:41:45Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![fedoroff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedoroff/32/53209_2.png) [@fedoroff](https://discourse.julialang.org/u/fedoroff)\
**Post date:** [October 20, 2021, 7:04am UTC](https://discourse.julialang.org/t/arrays-of-arrays-and-arrays-of-structures-in-cuda-kernels-cause-random-errors/69739/12 "2021-10-20T07:04:30Z")

</div>

I also tried the following:

```julia
cuintegs = CuArray([cudaconvert(integs[i]) for i=1:Np])

GC.@preserve integs begin
    @cuda threads=nthreads blocks=nblocks kernel(u, cuintegs)
end

```

Unfortunately, it does not help.

As far as I understand, when the function `cudaconvert(integs[i])` is called it also calls the corresponding adaptor:

```julia
function Adapt.adapt_structure(to, integ::Integrator)
    ks = [Adapt.adapt(to, integ.ks[i]) for i=1:length(integ.ks)]
    ks = CuArray(ks)
    ks = Adapt.adapt_structure(to, ks)
    return Integrator(integ.p, ks)
end

```

Inside this adaptor I do the same trick with the `ks` array of CuArrays which is the field of each `integs[i]` structure. According to your explanation, here I have the same issue when I transform `integ.ks` to CuArray `ks`. However, here it is not clear how to preserve `integ.ks`.

---

_[View the full topic](https://discourse.julialang.org/t/arrays-of-arrays-and-arrays-of-structures-in-cuda-kernels-cause-random-errors/69739)._
