InvalidIRError with CuArray broadcast when complex values are involved in Bessel functions

Hi, I’m receiving runtime errors from julia when playing with the following simple code

> 
> julia> using CUDA, SpecialFunctions
> 
> julia> function cutest(x::Float64,f::Float64)
>        c=besselj0(f);
>        return x+c
>        end
> cutest (generic function with 1 method)
> 
> julia> x=CuVector(rand(10));
> 
> julia> y=cutest.(x,1.0);
> 
> julia> y
> 10-element CuArray{Float64, 1, CUDA.Mem.DeviceBuffer}:
>  1.2543758351300334
>  1.6969145783025747
>  0.772833790043381
>  1.5466838680623587
>  0.9814961041987019
>  1.3892472218597938
>  1.5766825893406144
>  1.3715270039175633
>  1.070043997005175
>  1.4994660984390684
> 
> julia> function cutest(x::Float64,f::ComplexF64)
>        c=besselj0(f);
>        return x+c
>        end
> cutest (generic function with 2 methods)
> 
> julia> y=cutest.(x,1.0+0.0im);
> ERROR: InvalidIRError: compiling kernel #broadcast_kernel#17(CUDA.CuKernelContext, CuDeviceVector{ComplexF64, 1}, Base.Broadcast.Broadcasted{CUDA.CuArrayStyle{1}, Tuple{Base.OneTo{Int64}}, typeof(cutest), Tuple{Base.Broadcast.Extruded{CuDeviceVector{Float64, 1}, Tuple{Bool}, Tuple{Int64}}, ComplexF64}}, Int64) resulted in invalid LLVM IR
> Reason: unsupported call to the Julia runtime (call to jl_lazy_load_and_lookup)

It looks like the besselj0 function is giving some trouble when argument is complex. If I replace it with, e.g., exp, there is no error. How do I avoid this error? Thanks in advance.

That function is only implemented for Float32/Float64: CUDA.jl/special_math.jl at 49902d8812a7796da313c39e4e9fe6d84a7309e9 · JuliaGPU/CUDA.jl · GitHub. I’m not familiar with the Bessel function; if it’s possible to express the operation on ComplexF32/F64 in terms of these that would make for a great addition to CUDA.jl.

Ah, I did not realize that all elementary functions were implemented separately for the GPU, not really calling the package I’m using.