Repository navigation
Closed
Description
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]:9These 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.14Pinned by christiangnrd
Pinned comment options
bump: still experiencing this issue on v0.9.40 when trying to run on CPU backend
@mtanneau This will be fixed in KA 0.10 once released. In the meantime, an easy workaround is to import @index directly as implied in #542 (comment)
module MyModule2Working
import KernelAbstractions as KA
import KernelAbstractions: @index
KA.@kernel function inc_kernel(x)
I = @index(Global)
x[I] = x[I] + 1
end
function increment(x)
backend = KA.get_backend(x)
kernel! = inc_kernel(backend)
kernel!(x, ndrange=size(x))
KA.synchronize(backend)
return x
end
end
MyModule2Working.increment(ones(4)) # no issue
Activity
vchuravy commentedon Nov 30, 2024
Huh that's a fun one...
AntoineBut commentedon Mar 24, 2025
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.
JamesWrigley commentedon Mar 24, 2025
Alas, no. My quick fix is not use CPUs 😎
AntoineBut commentedon Mar 24, 2025
Great news, will email GitHub to kindly ask they add a few GPU to their runners 🚀🚀
JamesWrigley commentedon Mar 29, 2025
Actually this is fixed on master, so I'll close it. @vchuravy, any chance of getting a new release with the fix?
vchuravy commentedon Mar 29, 2025
Master will need some more work to stabilize, it's a breaking release
JamesWrigley commentedon Mar 29, 2025
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 commentedon May 21, 2025
Gentle bump, is there a timeline for when the next release will come out?
vchuravy commentedon May 22, 2025
#600 is currently tracking some of the work needed, but otherwise when it's done and tested enough
JamesWrigley commentedon May 22, 2025
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)
vchuravy commentedon Nov 7, 2025
Note that this is due to the use of
KA.@indexinstead of@indexworks.
[-]Exception when getting the index on the CPU backend[/-][+]Qualified `KA.@index` macro not detected.[/+]vchuravy commentedon Nov 7, 2025
This is due to
KernelAbstractions.jl/src/macros.jl
Line 237 in 1f84b17
JamesWrigley commentedon Nov 7, 2025
Oh my god, I can't believe I avoided using KA on CPUs for like a year because of this 🤦
vchuravy commentedon Nov 7, 2025
😢
mtanneau commentedon Mar 2, 2026
bump: still experiencing this issue on v0.9.40 when trying to run on CPU backend
the second call errors with the following stack trace:
christiangnrd commentedon Mar 2, 2026
@mtanneau This will be fixed in KA 0.10 once released. In the meantime, an easy workaround is to import
@indexdirectly as implied in #542 (comment)feat(gpu): Add GPUCalculationsExt with KernelAbstractions.jl backend
maleadt commentedon Oct 19, 2026
Fixed by #556: the
CPUback end no longer rewrites@indexcalls at the macro level, so a qualifiedKA.@indexworks the same as@indexon every back end in 0.10.