Skip to content

Commit

Permalink
Wrap at-metal's output in a let block. (#50)
Browse files Browse the repository at this point in the history
This avoids leaking temporary variables, e.g. when working in the REPL.
  • Loading branch information
maleadt authored Sep 12, 2022
1 parent dc295eb commit 02183ee
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/compiler/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,22 @@ macro metal(ex...)
quote
$f_var = $f
GC.@preserve $(vars...) $f_var begin
local $kernel_f = $mtlconvert($f_var)
local $kernel_args = map($mtlconvert, ($(var_exprs...),))
local $kernel_tt = Tuple{map(Core.Typeof, $kernel_args)...}
local $kernel = $mtlfunction($kernel_f, $kernel_tt; $(compiler_kwargs...))
$kernel_f = $mtlconvert($f_var)
$kernel_args = map($mtlconvert, ($(var_exprs...),))
$kernel_tt = Tuple{map(Core.Typeof, $kernel_args)...}
$kernel = $mtlfunction($kernel_f, $kernel_tt; $(compiler_kwargs...))
if $launch
$kernel($(var_exprs...); $(call_kwargs...))
end
$kernel
end
end)
return esc(code)

return esc(quote
let
$code
end
end)
end


Expand Down

0 comments on commit 02183ee

Please sign in to comment.