Skip to content

Commit bf99c1d

Browse files
bors[bot]vchuravy
andauthored
Merge #26
26: be less judicous with escape r=vchuravy a=vchuravy fixes #24 Co-authored-by: Valentin Churavy <[email protected]>
2 parents b5709d7 + d250830 commit bf99c1d

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/macros.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ function __kernel(expr)
3838
# create two functions
3939
# 1. GPU function
4040
# 2. CPU function with work-group loops inserted
41-
gpu_name = esc(gensym(Symbol(:gpu_, name)))
42-
cpu_name = esc(gensym(Symbol(:cpu_, name)))
43-
name = esc(name)
41+
gpu_name = gensym(Symbol(:gpu_, name))
42+
cpu_name = gensym(Symbol(:cpu_, name))
4443

4544
gpu_decl = Expr(:call, gpu_name, arglist...)
4645
cpu_decl = Expr(:call, cpu_name, arglist...)
@@ -70,7 +69,7 @@ function __kernel(expr)
7069
end
7170
end
7271

73-
return Expr(:toplevel, cpu_function, gpu_function, constructors)
72+
return Expr(:block, esc(cpu_function), esc(gpu_function), esc(constructors))
7473
end
7574

7675
# Transform function for GPU execution

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ end
99
include("localmem.jl")
1010
end
1111

12+
@testset "Unroll" begin
13+
include("unroll.jl")
14+
end
15+
1216
include("examples.jl")

test/unroll.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using KernelAbstractions
2+
using KernelAbstractions.Extras
3+
4+
@kernel function kernel_unroll!(a)
5+
@unroll for i in 1:5
6+
@inbounds a[i] = i
7+
end
8+
end
9+
10+
let
11+
a = zeros(5)
12+
kernel! = kernel_unroll!(CPU(), 1, 1)
13+
event = kernel!(a)
14+
wait(event)
15+
end

0 commit comments

Comments
 (0)