# KernelAbstractions.get\_backend(::BitArray) causes StackOverflowError

**URL:** <https://discourse.julialang.org/t/kernelabstractions-get-backend-bitarray-causes-stackoverflowerror/129551>\
**Category:** GPU\
**Tags:** question, bug, kernelabstractions\
**Created:** [June 2, 2025, 8:49am UTC](https://discourse.julialang.org/t/kernelabstractions-get-backend-bitarray-causes-stackoverflowerror/129551 "2025-06-02T08:49:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![0samuraiE](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/0samuraie/32/209825_2.png) [@0samuraiE](https://discourse.julialang.org/u/0samuraiE)\
**Post date:** [June 2, 2025, 8:49am UTC](https://discourse.julialang.org/t/kernelabstractions-get-backend-bitarray-causes-stackoverflowerror/129551/1 "2025-06-02T08:49:59Z")

</div>

Hi all,

I’m using `KernelAbstractions.jl`, and encountered a `StackOverflowError` when trying to call `get_backend` on a `BitArray` (e.g., from a comparison like `.<`):

```julia
using KernelAbstractions
x = rand(10)
msk = x .< 0.5
get_backend(msk)

```

This results in the following error:

```julia
julia> KernelAbstractions.get_backend(msk)
ERROR: StackOverflowError:
Stacktrace:
 [1] get_backend(A::BitVector) (repeats 79984 times)
   @ KernelAbstractions ~/.julia/packages/KernelAbstractions/sWSE0/src/KernelAbstractions.jl:519

```

It seems `get_backend` is recursively calling itself when passed a `BitArray`, likely due to a missing method definition.

As a workaround, I added the following method, which resolves the issue:

```julia
KernelAbstractions.get_backend(::BitArray) = KernelAbstractions.CPU()

```

Is this the recommended approach?  
Or should `BitArray` support be handled explicitly in `KernelAbstractions` itself (i.e., is this a bug)?

Additioanl context:  
This appears to be related to [issue #588](https://github.com/JuliaGPU/KernelAbstractions.jl/issues/588)

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [June 2, 2025, 9:23am UTC](https://discourse.julialang.org/t/kernelabstractions-get-backend-bitarray-causes-stackoverflowerror/129551/2 "2025-06-02T09:23:57Z")

</div>

> [@0samuraiE](#):
>
> Is this the recommended approach?

No. Type piracy is only good for debugging in the REPL.

> [@0samuraiE](#):
>
> Or should `BitArray` support be handled explicitly in `KernelAbstractions` itself (i.e., is this a bug)?

Yeah.

EDIT: here’s a PR to prevent the stack overflows specifically:

- [prevent `get_backend` from overflowing the stack by nsajko · Pull Request #602 · JuliaGPU/KernelAbstractions.jl · GitHub](https://github.com/JuliaGPU/KernelAbstractions.jl/pull/602)

I suggest you open another PR for defining the appropriate method for `BitArray`.
