Skip to content

Commit 1ad3d20

Browse files
committed
Reduce allocations during launch.
1 parent c2b3528 commit 1ad3d20

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/compiler/execution.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,9 @@ const _kernel_instances = Dict{UInt, Any}()
207207

208208
## kernel launching and argument encoding
209209

210-
@inline @generated function encode_arguments!(cce, kernel, args...)
211-
ex = quote
212-
bufs = MTLBuffer[]
213-
end
210+
@inline @generated function encode_arguments!(cce, kernel, args::Vararg{Any,N}) where {N}
211+
ex = quote end
212+
buffers = []
214213

215214
# the arguments passed into this function have not been `mtlconvert`ed, because we need
216215
# to retain the top-level MTLBuffer and MtlPtr objects. eager conversion of nested
@@ -230,17 +229,18 @@ const _kernel_instances = Dict{UInt, Any}()
230229
continue
231230
else
232231
# everything else is passed by reference, in an argument buffer
232+
buf = gensym("buffer")
233233
append!(ex.args, (quote
234-
buf = encode_argument!(kernel, mtlconvert($(argex), cce))
235-
set_buffer!(cce, buf, 0, $idx)
236-
push!(bufs, buf)
234+
$buf = encode_argument!(kernel, mtlconvert($(argex), cce))
235+
set_buffer!(cce, $buf, 0, $idx)
237236
end).args)
237+
push!(buffers, buf)
238238
end
239239
idx += 1
240240
end
241241

242242
append!(ex.args, (quote
243-
return bufs
243+
return ($(buffers...),)
244244
end).args)
245245

246246
ex

0 commit comments

Comments
 (0)