CuArray only supports element types that are stored inline?

Hello,

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

CuArray only supports element types that are stored inline 

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

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:

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

You’re not allowed to store mutable structs as the element types of CuArrays (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.