Skip to content

Commit

Permalink
metal : use autoreleasepool to avoid memory leaks (ggerganov#5437)
Browse files Browse the repository at this point in the history
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 ggerganov#5436
  • Loading branch information
irbull authored Feb 10, 2024
1 parent cd9aea6 commit f026f81
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ggml-metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -2272,6 +2273,7 @@ static bool ggml_metal_graph_compute(
[[MTLCaptureManager sharedCaptureManager] stopCapture];
}

}
return true;
}

Expand Down

0 comments on commit f026f81

Please sign in to comment.