# CUDA nested structs not isbits \[solved\]

**URL:** https://discourse.julialang.org/t/cuda-nested-structs-not-isbits-solved/121592
**Category:** General Usage
**Tags:** cuda
**Created:** [October 22, 2024, 2:07pm UTC](https://discourse.julialang.org/t/cuda-nested-structs-not-isbits-solved/121592 "2024-10-22T14:07:11Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![moukle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moukle/32/212789_2.png) [@moukle](https://discourse.julialang.org/u/moukle)
#### Post date: [October 22, 2024, 2:07pm UTC](https://discourse.julialang.org/t/cuda-nested-structs-not-isbits-solved/121592/1 "2024-10-22T14:07:11Z")

</div>

Hi,

can I somehow use nested structs inside CUDA kernels?  
Here is an example inspired by the custom structs section from the get started.

```julia
using CUDA
using Adapt

struct Interpolate{A}
    xs::A
    ys::A
end

struct Nested{A}
    itp::Interpolate
    zs::A
end

Adapt.@adapt_structure Interpolate

# Adapt.@adapt_structure Nested
function Adapt.adapt_structure(to, nst::Nested)
    zs = Adapt.adapt_structure(to, nst.zs)

    # first test
    # xs = Adapt.adapt_structure(to, nst.itp.xs)
    # ys = Adapt.adapt_structure(to, nst.itp.ys)
    # Nested(Interpolate(xs, ys), zs)

    # second test
    itp = Adapt.adapt_structure(to, nst.itp)
    Nested(itp, zs)
end

xs = [1, 2, 3]
ys = [10, 20, 30]
zs = [100, 200, 300]

itp = Interpolate(xs, ys)
itp_cu = Interpolate(cu(xs), cu(ys))
nst_cu = Nested(itp_cu, cu(zs))

function kernel(itp::Interpolate)
    @cushow itp.xs[threadIdx().x]
    return
end

function kernel(nst::Nested)
    @cushow nst.itp.xs[threadIdx().x]
    return
end

@cuda kernel(itp_cu)
@cuda kernel(nst_cu)

```

Both times I get the not isbits error

```julia
Argument 2 to your kernel function is of type Nested{CuDeviceVector{Int64, 1}}, which is not isbits:
  .itp is of type Interpolate which is not isbits.
    .xs is of type Any which is not isbits.
    .ys is of type Any which is not isbits.

```

**Edit** : templating the Nested struct did it:

```julia
struct Nested{A,ITP}
    itp::ITP
    zs::A
end

```
