From: Ian Bull Date: Sat, 10 Feb 2024 10:53:28 +0000 (-0800) Subject: metal : use autoreleasepool to avoid memory leaks (llama/5437) X-Git-Tag: upstream/1.7.4~1018 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=47dfe9d4db25520dafb626b7f2d1646aa844ef14;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp metal : use autoreleasepool to avoid memory leaks (llama/5437) There appears to be a known memory leak when using the `MLTCommandBuffer`. It is suggested to use `@autoreleasepool` in [1,2] [1] https://developer.apple.com/forums/thread/662721 [2] https://forums.developer.apple.com/forums/thread/120931 This change-set wraps the `ggml_metal_graph_compute` in a `@autoreleasepool`. This commit addresses https://github.com/ggerganov/llama.cpp/issues/5436 --- diff --git a/ggml-metal.m b/ggml-metal.m index 6027ca64..f82f72ca 100644 --- a/ggml-metal.m +++ b/ggml-metal.m @@ -696,6 +696,7 @@ static bool ggml_metal_graph_compute( struct ggml_metal_context * ctx, struct ggml_cgraph * gf) { + @autoreleasepool { MTLComputePassDescriptor * edesc = MTLComputePassDescriptor.computePassDescriptor; edesc.dispatchType = MTLDispatchTypeSerial; @@ -2281,6 +2282,7 @@ static bool ggml_metal_graph_compute( [[MTLCaptureManager sharedCaptureManager] stopCapture]; } + } return true; }