Hello,

I want to pass an array of structures to CUDA kernel. Each structure contains an array of CuArrays.

Most of the time my code works well, but sometimes randomly I see errors of the following type:

```
ERROR: Out-of-bounds array access.
WARNING: Error while freeing DeviceBuffer(96 bytes at ....)
LoadError: CUDA error: an illegal memory access was encountered (code 700, ERROR_ILLEGAL_ADDRESS)
```

The MWE where I managed to observe this behaviour is the following:

```
using Adapt
using CUDA
struct Integrator{P, K}
p :: P # Tuple
ks :: K # Array of CuArrays
end
function Adapt.adapt_structure(to, integ::Integrator)
ks = [Adapt.adapt_structure(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
function kernel(u, integs)
id = (blockIdx().x - 1) * blockDim().x + threadIdx().x
stride = blockDim().x * gridDim().x
Nu, Np = size(u)
for ip=id:stride:Np
ks = integs[ip].ks
for iu=1:Nu
for i=1:4
u[iu, ip] += ks[i][iu] + 1
end
end
end
return nothing
end
# ******************************************************************************
Nu = 100
ks = [CUDA.zeros(Nu) for i=1:4]
Np = 10000
a = range(1f0, 3f0, length=Np)
integs = Array{Integrator}(undef, Np)
for i=1:Np
p = (a[i], )
integs[i] = Integrator(p, ks)
end
integs = CuArray([cudaconvert(integs[i]) for i=1:Np])
# ******************************************************************************
u = CUDA.zeros((Nu, Np))
nthreads = min(Np, 256)
nblocks = cld(Np, nthreads)
@cuda threads=nthreads blocks=nblocks kernel(u, integs)
@show u == 4 * CUDA.ones((Nu, Np))
```

If I run this code for consecutively for 10-20 times, non stopping error messages with the above error messages will start to appear.

My main questions are:

- Is it a correct way to write the adaptor for such type of structures?
- Can I use the constructions like
`integs = CuArray([cudaconvert(integs[i]) for i=1:Np])`

to pass the array of structures to the kernel? - What is going on? Why do I see these errors randomly?

Thank you.