KernelAbstractions.jl
KernelAbstractions.jl copied to clipboard
eps(::AbstractFloat) inside a kernel doesn't compile on Julia 1.5.1
See the title. Works in a CUDA
kernel and in KA
on Julia 1.4.1.
MWE
using CUDA
using KernelAbstractions
function cuda_kernel(A)
@inbounds A[1] = eps(A[1])
nothing
end
@kernel function ka_kernel(A)
@inbounds A[1] = eps(A[1])
end
let
A = CuArray(ones(1))
@cuda cuda_kernel(A)
@show Array(A)
fill!(A, 1)
wait(ka_kernel(CUDADevice(), 1, 1)(A))
@show Array(A)
end
The actual issue here is with exponent
, specifically with the construction of @noinline
closures to raise specific errors:
https://github.com/JuliaLang/julia/blob/release-1.5/base/math.jl#L783
https://github.com/JuliaGPU/KernelAbstractions.jl/pull/130/files is a fix but there might be a better way fix the fundamental issue wrt to properly inlining the @noinline
closures with Cassette / KA.
cc @vchuravy
@jakebolewski I must have been to tired the last time I read your message, and didn't read the part about @noinline
.
@noinline
is something we explicitly honor (see https://github.com/JuliaGPU/KernelAbstractions.jl/blob/8c7052d23c32d6950ca9abb326af144cce8dae1c/src/compiler/pass.jl#L15-L19) mostly to not blow up code size on the CPU.
I noticed that, although I would think that behavior might have to be back end dependent for the GPU?
Well it depends, even for the GPU it is probably good to outline these error calls. But yes we can make this context dependent.