# Passing a wrapped array to a kernel

**URL:** https://discourse.julialang.org/t/passing-a-wrapped-array-to-a-kernel/40254
**Category:** GPU
**Created:** [May 27, 2020, 1:37pm UTC](https://discourse.julialang.org/t/passing-a-wrapped-array-to-a-kernel/40254 "2020-05-27T13:37:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![emiwar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emiwar/32/215517_2.png) [@emiwar](https://discourse.julialang.org/u/emiwar)
#### Post date: [May 27, 2020, 1:37pm UTC](https://discourse.julialang.org/t/passing-a-wrapped-array-to-a-kernel/40254/1 "2020-05-27T13:37:58Z")

</div>

Hi,

I’m trying to pass an object with a wrapped CuArray to a kernel:

```julia
import CUDA
struct MyStruct
    arrayField::CUDA.CuArray{Float32, 1, Nothing}
end

function f!(obj::MyStruct)
    id = CUDA.threadIdx().x
    if id <= length(a)
        obj.arrayField[id] = id
    end
    nothing
end

myObj = MyStruct(CUDA.fill(0.0, 5))
CUDA.@cuda threads = length(myObj) f!(myObj)

```

This fails with error message

```julia
GPU compilation of kernel f!(MyStruct) failed
KernelError: recursion is currently not supported

```

Is this a bug or am I doing something wrong?

Thanks

---

<div class="post-metadata">

### Author: ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)
#### Post date: [May 27, 2020, 1:39pm UTC](https://discourse.julialang.org/t/passing-a-wrapped-array-to-a-kernel/40254/2 "2020-05-27T13:39:24Z")

</div>

`CuArray` is the host-representation of a CUDA array, you need `CuDeviceArray`. That conversion happens automatically for known types, but you need to register your own Adapt.jl conversions for custom types.

---

<div class="post-metadata">

### Author: ![emiwar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emiwar/32/215517_2.png) [@emiwar](https://discourse.julialang.org/u/emiwar)
#### Post date: [May 27, 2020, 1:41pm UTC](https://discourse.julialang.org/t/passing-a-wrapped-array-to-a-kernel/40254/3 "2020-05-27T13:41:57Z")

</div>

I see, thanks!
