Skip to content

UndefVarError when variable is defined #647

Description

@efaulhaber
using KernelAbstractions

@kernel function mykernel(y)
    z = length(y)

    for i in 1:z
        @synchronize
    end
end

x = zeros(3)
backend = get_backend(x)

mykernel(backend)(x; ndrange=length(x))

KernelAbstractions.synchronize(backend)

This MWE yields:

ERROR: UndefVarError: `z` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
 [1] cpu_mykernel
   @ ~/.julia/packages/KernelAbstractions/lGrz7/src/macros.jl:307 [inlined]
 [2] cpu_mykernel(__ctx__::KernelAbstractions.CompilerMetadata{…}, x::Vector{…})
   @ Main ./none:0
 [3] __thread_run(tid::Int64, len::Int64, rem::Int64, obj::KernelAbstractions.Kernel{…}, ndrange::Tuple{…}, iterspace::KernelAbstractions.NDIteration.NDRange{…}, args::Tuple{…}, dynamic::KernelAbstractions.NDIteration.NoDynamicCheck)
   @ KernelAbstractions ~/.julia/packages/KernelAbstractions/lGrz7/src/cpu.jl:145
 [4] __run(obj::KernelAbstractions.Kernel{…}, ndrange::Tuple{…}, iterspace::KernelAbstractions.NDIteration.NDRange{…}, args::Tuple{…}, dynamic::KernelAbstractions.NDIteration.NoDynamicCheck, static_threads::Bool)
   @ KernelAbstractions ~/.julia/packages/KernelAbstractions/lGrz7/src/cpu.jl:112
 [5] (::KernelAbstractions.Kernel{…})(args::Vector{…}; ndrange::Int64, workgroupsize::Nothing)
   @ KernelAbstractions ~/.julia/packages/KernelAbstractions/lGrz7/src/cpu.jl:46
 [6] top-level scope
   @ Untitled-2:14
Some type information was truncated. Use `show(err)` to see complete types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions