]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
metal : use autoreleasepool to avoid memory leaks (#5437)
authorIan Bull <redacted>
Sat, 10 Feb 2024 10:53:28 +0000 (02:53 -0800)
committerGitHub <redacted>
Sat, 10 Feb 2024 10:53:28 +0000 (12:53 +0200)
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

ggml-metal.m

index 5260ed827702694d22c569274812c8377475cbf8..c1d8e2de81e023aa277b059ce94cac506f6b2a8b 100644 (file)
@@ -687,6 +687,7 @@ static bool ggml_metal_graph_compute(
         struct ggml_metal_context * ctx,
                struct ggml_cgraph * gf) {
 
+    @autoreleasepool {
     MTLComputePassDescriptor * edesc = MTLComputePassDescriptor.computePassDescriptor;
     edesc.dispatchType = MTLDispatchTypeSerial;
 
@@ -2272,6 +2273,7 @@ static bool ggml_metal_graph_compute(
         [[MTLCaptureManager sharedCaptureManager] stopCapture];
     }
 
+    }
     return true;
 }