Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.

Commit 3af9e4e

Browse files
authored
Merge pull request #528 from JuliaGPU/tb/hygiene
Work around macro hygiene for 1.5
2 parents 7f08486 + 0bc69cf commit 3af9e4e

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/execution.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function assign_args!(code, args)
4949
# assign arguments to variables
5050
vars = Tuple(gensym() for arg in args)
5151
map(vars, args) do var,arg
52-
push!(code.args, :($var = $(esc(arg))))
52+
push!(code.args, :($var = $arg))
5353
end
5454

5555
# convert the arguments, compile the function and call the kernel
@@ -149,6 +149,9 @@ macro cuda(ex...)
149149
end
150150
end
151151

152+
# FIXME: macro hygiene wrt. escaping kwarg values (this broke with 1.5)
153+
# we esc() the whole thing now, necessitating gensyms...
154+
@gensym kernel_args kernel_tt kernel
152155
if dynamic
153156
# FIXME: we could probably somehow support kwargs with constant values by either
154157
# saving them in a global Dict here, or trying to pick them up from the Julia
@@ -159,9 +162,9 @@ macro cuda(ex...)
159162
push!(code.args,
160163
quote
161164
# we're in kernel land already, so no need to cudaconvert arguments
162-
local kernel_tt = Tuple{$((:(Core.Typeof($var)) for var in var_exprs)...)}
163-
local kernel = dynamic_cufunction($(esc(f)), kernel_tt)
164-
kernel($(var_exprs...); $(map(esc, call_kwargs)...))
165+
local $kernel_tt = Tuple{$((:(Core.Typeof($var)) for var in var_exprs)...)}
166+
local $kernel = $dynamic_cufunction($f, $kernel_tt)
167+
$kernel($(var_exprs...); $(call_kwargs...))
165168
end)
166169
else
167170
# regular, host-side kernel launch
@@ -171,16 +174,14 @@ macro cuda(ex...)
171174
push!(code.args,
172175
quote
173176
GC.@preserve $(vars...) begin
174-
local kernel_args = map(cudaconvert, ($(var_exprs...),))
175-
local kernel_tt = Tuple{Core.Typeof.(kernel_args)...}
176-
local kernel = cufunction($(esc(f)), kernel_tt;
177-
$(map(esc, compiler_kwargs)...))
178-
kernel(kernel_args...; $(map(esc, call_kwargs)...))
177+
local $kernel_args = map($cudaconvert, ($(var_exprs...),))
178+
local $kernel_tt = Tuple{Core.Typeof.($kernel_args)...}
179+
local $kernel = $cufunction($f, $kernel_tt; $(compiler_kwargs...))
180+
$kernel($kernel_args...; $(call_kwargs...))
179181
end
180182
end)
181183
end
182-
183-
return code
184+
return esc(code)
184185
end
185186

186187

test/util.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ end
4848

4949
# Run some code on-device, returning captured standard output
5050
macro on_device(ex)
51-
quote
51+
@gensym kernel
52+
esc(quote
5253
let
53-
function kernel()
54-
$(esc(ex))
54+
function $kernel()
55+
$ex
5556
return
5657
end
5758

58-
@cuda kernel()
59+
@cuda $kernel()
5960
synchronize()
6061
end
61-
end
62+
end)
6263
end
6364

6465
# helper function for sinking a value to prevent the callee from getting optimized away

0 commit comments

Comments
 (0)