# FLoops + CUDAEx(): accumulator type must be \`isbits\` or \`isbitsunion\`; got: Union{}

**URL:** <https://discourse.julialang.org/t/floops-cudaex-accumulator-type-must-be-isbits-or-isbitsunion-got-union/74865>\
**Category:** General Usage\
**Created:** [January 19, 2022, 2:52pm UTC](https://discourse.julialang.org/t/floops-cudaex-accumulator-type-must-be-isbits-or-isbitsunion-got-union/74865 "2022-01-19T14:52:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [January 19, 2022, 2:52pm UTC](https://discourse.julialang.org/t/floops-cudaex-accumulator-type-must-be-isbits-or-isbitsunion-got-union/74865/1 "2022-01-19T14:52:14Z")

</div>

I’m trying my first small codes with CUDA, and using the FLoops interface. I am probably missing the basics here, so a brief explanation of this error will probably illuminate my path:

```julia
julia> using CUDA, FLoops, FoldsCUDA

julia> function test(x, ex = ThreadedEx())
           @floop ex for val in x
               @reduce(u = zero(eltype(x)) + val)
           end
           return u
       end
test (generic function with 2 methods)

julia> x = Float32[1,2,3];

julia> test(x)
6.0f0

julia> test(CuArray(x),CUDAEx())
ERROR: accumulator type must be `isbits` or `isbitsunion`; got: Union{}

```

What is wrong with the definition of my accumulator (`u = zero(eltype(x) + val`) ?

@tkf , I seem to get the same error with the [example](https://juliafolds.github.io/FoldsCUDA.jl/dev/examples/monte_carlo_pi/) from the FoldCUDA docs:

```julia
julia> function counters(n)
           stride = typemax(UInt64) ÷ n
           return UInt64(0):stride:typemax(UInt64)-stride
       end
counters (generic function with 1 method)

julia> function monte_carlo_pi(n, m = 10_000, ex = has_cuda_gpu() ? CUDAEx() : ThreadedEx())
           @floop ex for ctr in counters(n)
               rng = set_counter!(Philox2x(0), ctr)
               nhits = 0
               for _ in 1:m
                   x = rand(rng)
                   y = rand(rng)
                   nhits += x^2 + y^2 < 1
               end
               @reduce(tot = 0 + nhits)
           end
           return 4 * tot / (n * m)
       end
monte_carlo_pi (generic function with 3 methods)

julia> monte_carlo_pi(2^12)
ERROR: accumulator type must be `isbits` or `isbitsunion`; got: Tuple{Tuple{Any}}

```

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [January 19, 2022, 8:33pm UTC](https://discourse.julialang.org/t/floops-cudaex-accumulator-type-must-be-isbits-or-isbitsunion-got-union/74865/2 "2022-01-19T20:33:06Z")

</div>

Thanks for the ping. It looks like a bug. I can reproduce the error with the latest versions of the dependencies in CI [https://github.com/JuliaFolds/FoldsCUDA.jl/pull/89](https://github.com/JuliaFolds/FoldsCUDA.jl/pull/89)

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [January 28, 2022, 4:27am UTC](https://discourse.julialang.org/t/floops-cudaex-accumulator-type-must-be-isbits-or-isbitsunion-got-union/74865/3 "2022-01-28T04:27:14Z")

</div>

FoldsCUDA#master now works with CUDA#master. I’ll release the fix once CUDA.jl 3.8 is released: [https://github.com/JuliaFolds/FoldsCUDA.jl/pull/92](https://github.com/JuliaFolds/FoldsCUDA.jl/pull/92)
