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

Qualified `KA.@index` macro not detected.

Open JamesWrigley opened this issue 1 year ago • 14 comments

When running this slightly minified code from the quickstart guide:

import KernelAbstractions as KA

KA.@kernel function mul2_kernel(A)
    I = KA.@index(Global, Linear)
end
    
dev = KA.CPU()
A = ones(1024, 1024)
ev = mul2_kernel(dev, 64)(A, ndrange=size(A))
KA.synchronize(dev)
all(A .== 2.0)

I get this exception (only on the CPU backend, the CUDA backend works):

TaskFailedException

    nested task error: MethodError: no method matching __index_Global_Linear(::KernelAbstractions.CompilerMetadata{KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.NoDynamicCheck, CartesianIndex{2}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, KernelAbstractions.NDIteration.NDRange{2, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.StaticSize{(64, 1)}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, Nothing}})
    The function `__index_Global_Linear` exists, but no method is defined for this combination of argument types.
    
    Closest candidates are:
      __index_Global_Linear(::Any, ::CartesianIndex)
       @ KernelAbstractions ~/.julia/packages/KernelAbstractions/491pi/src/cpu.jl:163
    
    Stacktrace:
     [1] macro expansion
       @ ./In[85]:3 [inlined]
     [2] cpu_mul2_kernel
       @ ~/.julia/packages/KernelAbstractions/491pi/src/macros.jl:291 [inlined]
     [3] (::var"#cpu_mul2_kernel#9")(__ctx__::KernelAbstractions.CompilerMetadata{KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.NoDynamicCheck, CartesianIndex{2}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, KernelAbstractions.NDIteration.NDRange{2, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.StaticSize{(64, 1)}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, Nothing}}, A::Matrix{Float64})
       @ Main ./none:0
     [4] __thread_run(tid::Int64, len::Int64, rem::Int64, obj::KernelAbstractions.Kernel{CPU, KernelAbstractions.NDIteration.StaticSize{(64,)}, KernelAbstractions.NDIteration.DynamicSize, var"#cpu_mul2_kernel#9"}, ndrange::Tuple{Int64, Int64}, iterspace::KernelAbstractions.NDIteration.NDRange{2, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.StaticSize{(64, 1)}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, Nothing}, args::Tuple{Matrix{Float64}}, dynamic::KernelAbstractions.NDIteration.NoDynamicCheck)
       @ KernelAbstractions ~/.julia/packages/KernelAbstractions/491pi/src/cpu.jl:144
     [5] (::KernelAbstractions.var"#20#23"{KernelAbstractions.Kernel{CPU, KernelAbstractions.NDIteration.StaticSize{(64,)}, KernelAbstractions.NDIteration.DynamicSize, var"#cpu_mul2_kernel#9"}, Tuple{Int64, Int64}, KernelAbstractions.NDIteration.NDRange{2, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.StaticSize{(64, 1)}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, Nothing}, Tuple{Matrix{Float64}}, KernelAbstractions.NDIteration.NoDynamicCheck, Int64})()
       @ KernelAbstractions ~/.julia/packages/KernelAbstractions/491pi/src/cpu.jl:119

...and 39 more exceptions.


Stacktrace:
 [1] sync_end(c::Channel{Any})
   @ Base ./task.jl:466
 [2] macro expansion
   @ ./task.jl:499 [inlined]
 [3] __run(obj::KernelAbstractions.Kernel{CPU, KernelAbstractions.NDIteration.StaticSize{(64,)}, KernelAbstractions.NDIteration.DynamicSize, var"#cpu_mul2_kernel#9"}, ndrange::Tuple{Int64, Int64}, iterspace::KernelAbstractions.NDIteration.NDRange{2, KernelAbstractions.NDIteration.DynamicSize, KernelAbstractions.NDIteration.StaticSize{(64, 1)}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, Nothing}, args::Tuple{Matrix{Float64}}, dynamic::KernelAbstractions.NDIteration.NoDynamicCheck, static_threads::Bool)
   @ KernelAbstractions ~/.julia/packages/KernelAbstractions/491pi/src/cpu.jl:118
 [4] (::KernelAbstractions.Kernel{CPU, KernelAbstractions.NDIteration.StaticSize{(64,)}, KernelAbstractions.NDIteration.DynamicSize, var"#cpu_mul2_kernel#9"})(args::Matrix{Float64}; ndrange::Tuple{Int64, Int64}, workgroupsize::Nothing)
   @ KernelAbstractions ~/.julia/packages/KernelAbstractions/491pi/src/cpu.jl:46
 [5] top-level scope
   @ In[85]:9

These are the versions I'm running it with:

% julia --project
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.1 (2024-10-16)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(james) pkg> st
Status `Project.toml`
  [824d6782] Bonito v3.2.2
  [052768ef] CUDA v5.5.2
  [f68482b8] Cthulhu v2.15.2
  [8bb1440f] DelimitedFiles v1.9.1
  [7a1cc6ca] FFTW v1.8.0
  [63c18a36] KernelAbstractions v0.9.28
  [2fda8390] LsqFit v0.15.0
  [67456a42] OhMyThreads v0.7.0
  [6099a3de] PythonCall v0.9.23
  [276b4fcb] WGLMakie v0.10.14

JamesWrigley avatar Oct 22 '24 19:10 JamesWrigley

Huh that's a fun one...

vchuravy avatar Nov 30 '24 21:11 vchuravy

I've encountered the same issue, has anyone found a quick fix to get around the problem?

It doesn't matter if it is inneficient since it only show up on theCPU backend, but it currently prevents me from testing my package in the CI.

AntoineBut avatar Mar 24 '25 23:03 AntoineBut

Alas, no. My quick fix is not use CPUs 😎

JamesWrigley avatar Mar 24 '25 23:03 JamesWrigley

Great news, will email GitHub to kindly ask they add a few GPU to their runners 🚀🚀

AntoineBut avatar Mar 24 '25 23:03 AntoineBut

Actually this is fixed on master, so I'll close it. @vchuravy, any chance of getting a new release with the fix?

JamesWrigley avatar Mar 29 '25 18:03 JamesWrigley

Master will need some more work to stabilize, it's a breaking release

vchuravy avatar Mar 29 '25 19:03 vchuravy

Roger that 👍 Out of curiosity, what more work would be necessary? I might be able to find some time for it in the next few weeks.

(not that I know much about KA 😅 )

JamesWrigley avatar Mar 29 '25 19:03 JamesWrigley

Gentle bump, is there a timeline for when the next release will come out?

JamesWrigley avatar May 21 '25 22:05 JamesWrigley

#600 is currently tracking some of the work needed, but otherwise when it's done and tested enough

vchuravy avatar May 22 '25 04:05 vchuravy

Roger that, is there anything a relative noob could help out with? (disclaimer: I will likely not have a lot of time to work on it for a few weeks)

JamesWrigley avatar May 22 '25 07:05 JamesWrigley

Note that this is due to the use of KA.@index instead of @index

julia> KA.@kernel function mul2_kernel(A)
           I = @index(Global, Linear)
       end

works.

vchuravy avatar Nov 07 '25 20:11 vchuravy

This is due to https://github.com/JuliaGPU/KernelAbstractions.jl/blob/1f84b17414bc325fce199d51e97f75a408aa1e63/src/macros.jl#L237

vchuravy avatar Nov 07 '25 20:11 vchuravy

Oh my god, I can't believe I avoided using KA on CPUs for like a year because of this 🤦

JamesWrigley avatar Nov 07 '25 20:11 JamesWrigley

😢

vchuravy avatar Nov 07 '25 21:11 vchuravy