JuliaMath / Interpolations.jl

Fast, continuous interpolation of discrete datasets in Julia
http://juliamath.github.io/Interpolations.jl/
Other
518 stars 110 forks source link

Error with Metal and oneAPI when nodes are ranges #597

Open pvillacorta opened 1 month ago

pvillacorta commented 1 month ago

Hello, I am experiencing an error that can be reproduced with the following lines:

using Interpolations, CUDA, Adapt

N = 5
x = range(0f0, 1f0, N)
y = rand(Float32, N)

itp = interpolate((x,), y, Gridded(Linear()))
cuitp = adapt(CuArray{Float32}, itp);

xp = range(0f0, 1f0, N)

u = cuitp.(xp)

This works with CUDA and AMDGPU arrays but, when:

cuitp = adapt(MtlArray{Float32}, itp);

or:

cuitp = adapt(oneArray{Float32}, itp);

The following errors appear:

ERROR: LoadError: InvalidIRError: compiling MethodInstance for (::Metal.var"#broadcast_linear#202")(::Metal.MtlDeviceVector{Float32, 1}, ::Base.Broadcast.Broadcasted{Metal.MtlArrayStyle{1, Metal.MTL.Private}, Tuple{Base.OneTo{Int64}}, Interpolations.GriddedInterpolation{Float32, 1, Metal.MtlDeviceVector{Float32, 1}, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Tuple{StepRangeLen{Float32, Float32, Float32, Int64}}}, Tuple{Base.Broadcast.Extruded{StepRangeLen{Float32, Float32, Float32, Int64}, Tuple{Bool}, Tuple{Int64}}}}) resulted in invalid LLVM IR
ERROR: LoadError: InvalidIRError: compiling MethodInstance for (::GPUArrays.var"#34#36")(::oneAPI.oneKernelContext, ::oneAPI.oneDeviceVector{Float32, 1}, ::Base.Broadcast.Broadcasted{oneAPI.oneArrayStyle{1, oneAPI.oneL0.DeviceBuffer}, Tuple{Base.OneTo{Int64}}, Interpolations.GriddedInterpolation{Float32, 1, oneAPI.oneDeviceVector{Float32, 1}, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Tuple{StepRangeLen{Float32, Float32, Float32, Int64}}}, Tuple{Base.Broadcast.Extruded{oneAPI.oneDeviceVector{Float32, 1}, Tuple{Bool}, Tuple{Int64}}}}, ::Int64) resulted in invalid LLVM IR

Full stacktrace is here.

I do not know if this is a bug from Metal and oneAPI or if it is the expected behaviour. What is strange is the fact that it only fails for Metal and oneAPI. Note that this works for all backends:

using Interpolations, CUDA, Adapt

N = 5
x = collect(range(0f0, 1f0, N))
y = rand(Float32, N)

itp = interpolate((x,), y, Gridded(Linear()))
cuitp = adapt(CuArray{Float32}, itp);

xp = rand(N); xp = adapt(CuArray{Float32}, xp)

u = cuitp.(xp)

But I need input nodes to be ranges instead of arrays, to avoid extra allocations. Thank you, I really appreciate what this package offers and it would be awesome to put a solution to this :smile: Cheers, Pablo