KernelAbstractions.get_backend(::BitArray) causes StackOverflowError

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 .<):

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

This results in the following error:

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:

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

1 Like

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

Yeah.

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

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

1 Like