# What is \`Base.allocatedinline\` and custom types for \`CuArray\` (\`CUDA.jl\`) involving \`Missing\`

**URL:** <https://discourse.julialang.org/t/what-is-base-allocatedinline-and-custom-types-for-cuarray-cuda-jl-involving-missing/70122>\
**Category:** GPU\
**Tags:** question, cuda\
**Created:** [October 21, 2021, 12:01am UTC](https://discourse.julialang.org/t/what-is-base-allocatedinline-and-custom-types-for-cuarray-cuda-jl-involving-missing/70122 "2021-10-21T00:01:20Z")\
**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:** [October 21, 2021, 8:17am UTC](https://discourse.julialang.org/t/what-is-base-allocatedinline-and-custom-types-for-cuarray-cuda-jl-involving-missing/70122/2 "2021-10-21T08:17:52Z")

</div>

There’s several issues with this MWE. First of all, `cpu_arr` is a type, not a value. Your `MyStruct` should be parametric because `Vector` can never live on the GPU. Then there’s the problem of arrays-of-arrays, which doesn’t really work, see [Arrays of arrays and arrays of structures in CUDA kernels cause random errors - #12 by fedoroff](https://discourse.julialang.org/t/arrays-of-arrays-and-arrays-of-structures-in-cuda-kernels-cause-random-errors/69739/12).

An example how this could work:

```julia
using CUDA, Adapt

struct MyStruct{T <: AbstractVector{Tuple{Int,Int}}}
    arr::T
end
MyStruct(x::T) where T = MyStruct{T}(x)
Adapt.adapt_structure(to, x::MyStruct) = MyStruct(adapt(to, x.arr))

function main()
    cpu_arr = [MyStruct(Vector{Tuple{Int, Int}}())]

    # first, convert the contained MyStruct{Vector} elements
    gpu_arr = adapt.(CuArray, cpu_arr)

    # we could now convert gpu_arr::Vector to a CuArray, but since we'll also have to
    # convert the MyStruct{CuArray} elements to MyStruct{CuDeviceArray} (because @cuda
    # doesn't automatically convert array _elements_ when calling a kernel), we'll
    # leave it on the CPU

    GC.@preserve gpu_arr begin
        gpu_device_arr = cudaconvert.(gpu_arr)
        final_gpu_arr = CuArray(gpu_device_arr)

        # final_gpu_arr is now a CuArray of MyStruct{CuDeviceArray} elements, which we can
        # pass to a kernel (@cuda will do the outer CuArray->CuDeviceArray conversion)
        @show typeof(final_gpu_arr)
    end
end

```

But I recommend simplifying the setup instead.

---

_[View the full topic](https://discourse.julialang.org/t/what-is-base-allocatedinline-and-custom-types-for-cuarray-cuda-jl-involving-missing/70122)._
