diff options
author | Paul Tsochantaris <ptsochantaris@icloud.com> | 2024-01-18 08:47:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-18 10:47:24 +0200 |
commit | 1e605f4102c7ea8dc0dff82f5eaa6a71973d549f (patch) | |
tree | 4c9eec47ed1995189916634b8070cbb1d6891979 | |
parent | 6b6916b215251e09bd57cdbf870dc8a73345edc2 (diff) |
metal : fix memory leak, dangling pointer and unused autorel (#5007)
* Metal memory: Small memory leak on init, dangling pointer, and unused autorelease pool in graph compute
* SPM header potential fix
* Reverting symlinks
-rw-r--r-- | ggml-metal.m | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/ggml-metal.m b/ggml-metal.m index 66d4d675..912ddc83 100644 --- a/ggml-metal.m +++ b/ggml-metal.m @@ -238,21 +238,19 @@ static void * ggml_metal_host_malloc(size_t n) { static struct ggml_metal_context * ggml_metal_init(int n_cb) { GGML_METAL_LOG_INFO("%s: allocating\n", __func__); - id<MTLDevice> device; - NSString * s; - -#if TARGET_OS_OSX +#if TARGET_OS_OSX && !GGML_METAL_NDEBUG // Show all the Metal device instances in the system NSArray * devices = MTLCopyAllDevices(); - for (device in devices) { - s = [device name]; + for (id<MTLDevice> device in devices) { + NSString * s = [device name]; GGML_METAL_LOG_INFO("%s: found device: %s\n", __func__, [s UTF8String]); } + [devices release]; // since it was created by a *Copy* C method #endif // Pick and show default Metal device - device = MTLCreateSystemDefaultDevice(); - s = [device name]; + id<MTLDevice> device = MTLCreateSystemDefaultDevice(); + NSString * s = [device name]; GGML_METAL_LOG_INFO("%s: picking default device: %s\n", __func__, [s UTF8String]); // Configure context @@ -712,7 +710,6 @@ static bool ggml_metal_supports_op(const struct ggml_metal_context * ctx, const static bool ggml_metal_graph_compute( struct ggml_metal_context * ctx, struct ggml_cgraph * gf) { - @autoreleasepool { MTLComputePassDescriptor * edesc = MTLComputePassDescriptor.computePassDescriptor; edesc.dispatchType = MTLDispatchTypeSerial; @@ -2255,7 +2252,6 @@ static bool ggml_metal_graph_compute( } return true; - } } //////////////////////////////////////////////////////////////////////////////// |