@@ -11,8 +11,10 @@ effectively returns the only system GPU.
1111function current_device ()
1212 get! (task_local_storage (), :MTLDevice ) do
1313 dev = MTLDevice (1 )
14- supports_family (dev, MTL. MTLGPUFamilyApple7) || @warn """ Metal.jl is only supported on M-series Macs, you may run into issues.
15- See https://github.com/JuliaGPU/Metal.jl/issues/22 for more details.""" maxlog= 1
14+ if ! supports_family (dev, MTL. MTLGPUFamilyApple7)
15+ @warn """ Metal.jl is only supported on M-series Macs, you may run into issues.
16+ See https://github.com/JuliaGPU/Metal.jl/issues/22 for more details.""" maxlog= 1
17+ end
1618 return dev
1719 end :: MTLDevice
1820end
@@ -33,10 +35,14 @@ Return the Metal command queue associated with the current Julia thread.
3335"""
3436function global_queue (dev:: MTLDevice )
3537 get! (task_local_storage (), (:MTLCommandQueue , dev)) do
36- queue = MTLCommandQueue (dev)
37- queue. label = " global_queue($(current_task ()) )"
38- global_queues[queue] = nothing
39- queue
38+ @autoreleasepool begin
39+ # NOTE: MTLCommandQueue itself is manually reference-counted,
40+ # the release pool is for resources used during its construction.
41+ queue = MTLCommandQueue (dev)
42+ queue. label = " global_queue($(current_task ()) )"
43+ global_queues[queue] = nothing
44+ queue
45+ end
4046 end :: MTLCommandQueue
4147end
4248
@@ -50,7 +56,7 @@ Create a new MTLCommandBuffer from the global command queue, commit it to the qu
5056and simply wait for it to be completed. Since command buffers *should* execute in a
5157First-In-First-Out manner, this synchronizes the GPU.
5258"""
53- function synchronize (queue:: MTLCommandQueue = global_queue (current_device ()))
59+ @autoreleasepool function synchronize (queue:: MTLCommandQueue = global_queue (current_device ()))
5460 cmdbuf = MTLCommandBuffer (queue)
5561 commit! (cmdbuf)
5662 wait_completed (cmdbuf)
0 commit comments