# Need a basic example on using custom structs in CUDA.jl with Adapt.jl

**URL:** https://discourse.julialang.org/t/need-a-basic-example-on-using-custom-structs-in-cuda-jl-with-adapt-jl/118829
**Category:** GPU
**Tags:** cuda, struct, adapt
**Created:** [August 30, 2024, 10:49pm UTC](https://discourse.julialang.org/t/need-a-basic-example-on-using-custom-structs-in-cuda-jl-with-adapt-jl/118829 "2024-08-30T22:49:53Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)
#### Post date: [August 31, 2024, 4:05am UTC](https://discourse.julialang.org/t/need-a-basic-example-on-using-custom-structs-in-cuda-jl-with-adapt-jl/118829/2 "2024-08-31T04:05:31Z")

</div>

As far as I understand it, it is important here to use parametric types.

```julia
using CUDA, Adapt

struct TestStruct{A}
    testField::A
end

Adapt.@adapt_structure TestStruct

test = TestStruct([1,2,3]) |> cu
# but this also works: test = TestStruct([1,2,3] |> cu) 

function squareGPU!(test)
    testField = test.testField
    index = threadIdx().x
    testField[index] = testField[index]^2
    return nothing
end

@cuda threads=3 squareGPU!(test)

```

Notice that you can first construct the CPU type `TestStruct{Vector{Int64}}` and then `cu` will automatically convert it to the fully specified GPU type `TestStruct{CuArray{Int64, 1, CUDA.DeviceMemory}}`.

The error message about the is bits type indicated that `TestStruct` as a type itself does not specify the type precise enough, also `CuArray` is not precise enough as it could be different types, dimension, etc.

---

_[View the full topic](https://discourse.julialang.org/t/need-a-basic-example-on-using-custom-structs-in-cuda-jl-with-adapt-jl/118829)._
