Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/KernelAbstractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Like [`@uniform`](@ref), the allocation is also executed by padding work-items t
outside of the `ndrange`.
"""
macro localmem(T, dims)
return :($KI.localmemory($(esc(T)), Val($(esc(dims)))))
return :($(KI.localmemory)($(esc(T)), Val($(esc(dims)))))
end

"""
Expand Down
10 changes: 5 additions & 5 deletions src/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ macro spawn(args...)
# `device!` comes first because `wait_event` acts on the queue of the device that is
# active when it is called: selecting the device afterwards would leave it unordered.
body = quote
$KI.device!($b, $dev)
$KI.wait_event($b, $event)
$(KI.device!)($b, $dev)
$(KI.wait_event)($b, $event)
local $result = $expr
$KI.synchronize($b)
$(KI.synchronize)($b)
$result
end
task = if threadpool === nothing
Expand All @@ -122,8 +122,8 @@ macro spawn(args...)
return esc(
quote
local $b = $backend
local $dev = $(device === nothing ? :($KI.device($b)) : device)
local $event = $KI.record_event($b)
local $dev = $(device === nothing ? :($(KI.device)($b)) : device)
local $event = $(KI.record_event)($b)
$task
end
)
Expand Down
21 changes: 21 additions & 0 deletions test/localmem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,28 @@ end
end
end

# A kernel whose `@localmem` was expanded before `@kernel` saw it, as tools that generate
# kernels (e.g. ParallelStencil.jl) do. `@kernel` copies the definition with `deepcopy`,
# which fails for expansions that contain a module.
const pre_expanded_localmem = macroexpand(@__MODULE__, :(KernelAbstractions.@localmem Int (16,)))
@eval @kernel function localmem_pre_expanded(A)
i = @index(Local, Linear)
I = @index(Global, Linear)
lmem = $pre_expanded_localmem
lmem[i] = i
@synchronize
@inbounds A[I] = lmem[16 - i + 1]
end

function localmem_testsuite(backend, ArrayT)
@testset "pre-expanded @localmem" begin
@test deepcopy(pre_expanded_localmem) == pre_expanded_localmem
A = ArrayT{Int}(undef, 32)
localmem_pre_expanded(backend(), 16)(A, ndrange = size(A))
synchronize(backend())
@test Array(A) == [17 .- (1:16); 17 .- (1:16)]
end

@testset "kernels" begin
@testset for kernel! in (localmem(backend(), 16), localmem2(backend(), 16), localmem_unsafe_indices(backend(), 16), many_localmem(backend(), 16))
A = ArrayT{Int}(undef, 64)
Expand Down
6 changes: 6 additions & 0 deletions test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ end
end

function spawn_testsuite(Backend, AT)
@testset "expansion can be copied" begin
# tools that generate code copy expressions with `deepcopy`, which fails for modules
ex = macroexpand(@__MODULE__, :(KernelAbstractions.@spawn backend nothing))
@test deepcopy(ex) isa Expr
end

backend = Backend()

@testset "ordered after the spawning task" begin
Expand Down
Loading