JuliaMath / JuliaMath/Interpolations.jl
Error with Metal and oneAPI when nodes are ranges
- Dominant language
- Julia
- Stars
- 575
- Forks
- 117
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I am experiencing an error that can be reproduced with the following lines:
```julia
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:
```julia
cuitp = adapt(MtlArray{Float32}, itp);
```
or:
```julia
cuitp = adapt(oneArray{Float32}, itp);
```
The following errors appear:
```julia
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
```
```julia
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](https://github.com/user-attachments/files/15986782/stacktrace.md).
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:
```julia
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.