Skip to content

Commit

Permalink
fix(ios): use calloc in wsp_ggml_metal_init during ARC enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Nov 8, 2023
1 parent 1725cd7 commit 4a38f56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cpp/ggml-metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void wsp_ggml_metal_log(enum wsp_ggml_log_level level, const char* format
WSP_GGML_METAL_LOG_INFO("%s: picking default device: %s\n", __func__, [s UTF8String]);

// Configure context
struct wsp_ggml_metal_context * ctx = malloc(sizeof(struct wsp_ggml_metal_context));
struct wsp_ggml_metal_context * ctx = calloc(1, sizeof(struct wsp_ggml_metal_context));
ctx->device = device;
ctx->n_cb = MIN(n_cb, WSP_GGML_METAL_MAX_BUFFERS);
ctx->queue = [ctx->device newCommandQueue];
Expand Down
20 changes: 15 additions & 5 deletions scripts/ggml-metal.m.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
--- ggml-metal.m.orig 2023-11-07 18:03:28
+++ ggml-metal.m 2023-11-07 18:03:29
--- ggml-metal.m.orig 2023-11-08 12:15:15
+++ ggml-metal.m 2023-11-08 12:14:49
@@ -184,7 +184,7 @@
WSP_GGML_METAL_LOG_INFO("%s: picking default device: %s\n", __func__, [s UTF8String]);

// Configure context
- struct wsp_ggml_metal_context * ctx = malloc(sizeof(struct wsp_ggml_metal_context));
+ struct wsp_ggml_metal_context * ctx = calloc(1, sizeof(struct wsp_ggml_metal_context));
ctx->device = device;
ctx->n_cb = MIN(n_cb, WSP_GGML_METAL_MAX_BUFFERS);
ctx->queue = [ctx->device newCommandQueue];
@@ -215,7 +215,7 @@
if (ggmlMetalPathResources) {
sourcePath = [ggmlMetalPathResources stringByAppendingPathComponent:@"ggml-metal.metal"];
Expand All @@ -18,20 +27,21 @@

WSP_GGML_METAL_DEL_KERNEL(add);
WSP_GGML_METAL_DEL_KERNEL(add_row);
@@ -423,16 +421,6 @@
@@ -423,17 +421,7 @@
WSP_GGML_METAL_DEL_KERNEL(sqr);

#undef WSP_GGML_METAL_DEL_KERNEL
-
- for (int i = 0; i < ctx->n_buffers; ++i) {
- [ctx->buffers[i].metal release];
- }
-
- [ctx->library release];
- [ctx->queue release];
- [ctx->device release];
-
- dispatch_release(ctx->d_queue);
-
free(ctx);
}

0 comments on commit 4a38f56

Please sign in to comment.