# CuArray only supports element types that are stored inline?

**URL:** <https://discourse.julialang.org/t/cuarray-only-supports-element-types-that-are-stored-inline/71339>\
**Category:** GPU\
**Tags:** gpu, cuda, cuarrays, mutable-structure\
**Created:** [November 11, 2021, 5:11pm UTC](https://discourse.julialang.org/t/cuarray-only-supports-element-types-that-are-stored-inline/71339 "2021-11-11T17:11:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ludovic\_Dumoulin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ludovic_dumoulin/32/22414_2.png) [@Ludovic\_Dumoulin](https://discourse.julialang.org/u/Ludovic_Dumoulin)\
**Post date:** [November 11, 2021, 5:11pm UTC](https://discourse.julialang.org/t/cuarray-only-supports-element-types-that-are-stored-inline/71339/1 "2021-11-11T17:11:50Z")

</div>

Hello,

I would like to define, a mutable structure with a field of type `::CuArray{an_other_mutable_structure}` but I get this error:

```julia
CuArray only supports element types that are stored inline 

```

I don’t understand what it means, but it comes from the constructor of `CuArray`:

```julia
function CuArray{T,N}(::UndefInitializer, dims::Dims{N}) where {T,N}
    Base.allocatedinline(T) || error("CuArray only supports element types that are stored inline")
....

```

Here is my code:

```julia
Tf = Float64
Ti = Int64
mutable struct node_struct
    x::Tf
    y::Tf
    xr::Tf
    zr::Tf
    vx::Tf
    vz::Tf
    Fx::Tf
    Fz::Tf  
    node_struct() = new(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
end

mutable struct IBM_object
    is_wall::Bool
    num_nodes::Ti
    radius::Tf
    stiffness::Tf
    nodes::CuArray{node_struct}
    IBM_object(number) = new(true, number, 0, 1, CuArray{node_struct}(undef, number))
end

```

At the beginning I was thinking that it could be solved with `Adapt`, but with `Adapt.@adapt_structure node_struct` before the definition of the second structure nothing changed.

Best,

Ludo

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [November 11, 2021, 5:23pm UTC](https://discourse.julialang.org/t/cuarray-only-supports-element-types-that-are-stored-inline/71339/2 "2021-11-11T17:23:19Z")

</div>

You’re not allowed to store mutable structs as the element types of `CuArray`s (or any GPUArray) because they end up getting stored as pointers, and being heap-allocated and managed. This is incompatible with GPU execution, because we don’t have access to Julia’s runtime+GC while running on the GPU.

Instead, I’d use an immutable struct, and use something like Setfield.jl to read-modify-write array values.
