Skip to content

weird issue with index macro #30

Closed
Closed

Description

@mwarusz
using KernelAbstractions

@kernel function kernel_index!(a)
  i = KernelAbstractions.@index(Global)
  @inbounds a[i] = i
end

let
  a = zeros(1)
  kernel! = kernel_index!(CPU(), 1, 1)
  event = kernel!(a)
  wait(event)
end

fails with

TaskFailedException:
MethodError: no method matching __index_Global_Linear()
Stacktrace:
 [1] call at /home/mwarusz/.julia/packages/Cassette/7OymZ/src/context.jl:450 [inlined]
 [2] fallback at /home/mwarusz/.julia/packages/Cassette/7OymZ/src/context.jl:448 [inlined]
 [3] _overdub_fallback at /home/mwarusz/.julia/packages/Cassette/7OymZ/src/overdub.jl:486 [inlined]
 [4] ##cpu_kernel_index!#423 at /home/mwarusz/repos/KernelAbstractions.jl/src/macros.jl:4 [inlined]
 [5] (::KernelAbstractions.var"#22#27"{Cassette.Context{nametype(CPUCtx),KernelAbstractions.CompilerMetadata{KernelAbstractions.StaticSize{(1,)},KernelAbstractions.StaticSize{(1,)},false,Int64,Nothing,Nothing},Nothing,KernelAbstractions.var"##PassType#422",Nothing,Cassette.DisableHooks},KernelAbstractions.Kernel{CPU,KernelAbstractions.StaticSize{(1,)},KernelAbstractions.StaticSize{(1,)},var"###cpu_kernel_index!#423"},Tuple{Array{Float64,1}}})() at ./threadingconstructs.jl:113
Stacktrace:
 [1] macro expansion at ./task.jl:319 [inlined]
 [2] macro expansion at /home/mwarusz/repos/KernelAbstractions.jl/src/backends/cpu.jl:38 [inlined]
 [3] (::KernelAbstractions.var"#18#23"{KernelAbstractions.Kernel{CPU,KernelAbstractions.StaticSize{(1,)},KernelAbstractions.StaticSize{(1,)},var"###cpu_kernel_index!#423"},Tuple{Array{Float64,1}},Int64,Bool})() at ./threadingconstructs.jl:113
Stacktrace:
 [1] wait at ./task.jl:251 [inlined]
 [2] wait at /home/mwarusz/repos/KernelAbstractions.jl/src/backends/cpu.jl:7 [inlined]
 [3] wait(::KernelAbstractions.CPUEvent) at /home/mwarusz/repos/KernelAbstractions.jl/src/backends/cpu.jl:6
 [4] top-level scope at /home/mwarusz/repos/KernelAbstractions.jl/examples/unroll_issue.jl:13
in expression starting at /home/mwarusz/repos/KernelAbstractions.jl/examples/unroll_issue.jl:9

Activity

  1. vchuravy commented on Feb 22, 2020

    @vchuravy
    Member

    Probably an issue with using the prefix form... The challenge of doing this as a macro, things are not normalized yet.

  2. vchuravy commented on Feb 29, 2020

    @vchuravy
    Member

    Yeah we would need to add a variant of KernelAbstractions.@index for

    if @capture(stmt, @uniform x_)
    push!(allocations, stmt)
    continue
    elseif @capture(stmt, lhs_ = rhs_)
    if @capture(rhs, @index(args__))
    push!(indicies, stmt)
    continue
    elseif @capture(rhs, @localmem(args__) | @uniform(args__) )
    push!(allocations, stmt)
    continue
    elseif @capture(rhs, @private(args__))
    push!(allocations, stmt)
    push!(private, lhs)
    continue
    end
    end

    I am hesitant to do that since people might think Oceanigans.KernelAbstractions.@index would then also work, but on the otherhand maybe we can normalize the name...

  3. added theissue type on Oct 19, 2026
  4. added
    kernels
    on Oct 19, 2026
  5. maleadt commented on Oct 19, 2026

    @maleadt
    Member

    Fixed by #556, released in 0.10: the PoCL-based CPU backend lowers KernelAbstractions.@index(Global) like the GPU backends, and the example works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kernels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions