Hi,
can I somehow use nested structs inside CUDA kernels?
Here is an example inspired by the custom structs section from the get started.
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
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:
struct Nested{A,ITP}
itp::ITP
zs::A
end