KernelAbstractions.jl icon indicating copy to clipboard operation
KernelAbstractions.jl copied to clipboard

eps(::AbstractFloat) inside a kernel doesn't compile on Julia 1.5.1

Open mwarusz opened this issue 4 years ago • 4 comments

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

mwarusz avatar Aug 29 '20 00:08 mwarusz

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 avatar Sep 11 '20 17:09 jakebolewski

@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.

vchuravy avatar Sep 17 '20 19:09 vchuravy

I noticed that, although I would think that behavior might have to be back end dependent for the GPU?

jakebolewski avatar Sep 17 '20 20:09 jakebolewski

Well it depends, even for the GPU it is probably good to outline these error calls. But yes we can make this context dependent.

vchuravy avatar Sep 17 '20 21:09 vchuravy