# Isbits union support in CUDA.jl

**URL:** <https://discourse.julialang.org/t/isbits-union-support-in-cuda-jl/72219>\
**Category:** GPU\
**Tags:** question\
**Created:** [November 29, 2021, 4:33am UTC](https://discourse.julialang.org/t/isbits-union-support-in-cuda-jl/72219 "2021-11-29T04:33:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![guyvdb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/guyvdb/32/11596_2.png) [@guyvdb](https://discourse.julialang.org/u/guyvdb)\
**Post date:** [November 29, 2021, 4:33am UTC](https://discourse.julialang.org/t/isbits-union-support-in-cuda-jl/72219/1 "2021-11-29T04:33:43Z")

</div>

I’m confused about the support that CUDA.jl has for isbits unions:

```julia
# Unions of two work fine:
map(x->1, CuVector([1,missing]));
map(x->1, CuVector([1,nothing]));

# It is possible to move unions of three to the GPU memory
CuVector([1,missing,nothing]);

# But compiling a GPU kernel fails...
map(x->1, CuVector([1,missing,nothing]));
# unsupported dynamic function invocation (call to arrayref_union(A::CuDeviceArray{T, AS, A} where A, index::Integer) where {T, AS} in CUDA)

# The restriction seems to be on the size of the type union, 
# not on the size of the isbits array elements
# for example, this works fine:
struct Big
    x::Int
    y::Bool
    z::Int
    w::Float32
end
map(x->1, CuVector([Big(1,true,2,0.5), Big(2,false,3,0.2), missing]));

```

When I want CUDA.jl to work with a union of \>2 things, the best solution is to make a custom overarching isbits struct where I manually add type selector bytes?

---

<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:** [November 29, 2021, 9:04am UTC](https://discourse.julialang.org/t/isbits-union-support-in-cuda-jl/72219/2 "2021-11-29T09:04:17Z")

</div>

That’s a bug, please file an issue on the CUDA.jl repository. Union support is relatively new, so there may still be bugs.

---

<div class="post-metadata">

**Author:** ![guyvdb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/guyvdb/32/11596_2.png) [@guyvdb](https://discourse.julialang.org/u/guyvdb)\
**Post date:** [November 29, 2021, 5:18pm UTC](https://discourse.julialang.org/t/isbits-union-support-in-cuda-jl/72219/3 "2021-11-29T17:18:40Z")

</div>

Thanks, issue filed: [https://github.com/JuliaGPU/CUDA.jl/issues/1252](https://github.com/JuliaGPU/CUDA.jl/issues/1252)
