Skip to content

Commit 2f8cd97

Browse files
authored
metal : release buffers when freeing metal context (ggml-org#2062)
1 parent 471aab6 commit 2f8cd97

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ggml-metal.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ @implementation GGMLMetalClass
202202

203203
void ggml_metal_free(struct ggml_metal_context * ctx) {
204204
fprintf(stderr, "%s: deallocating\n", __func__);
205-
205+
for (int i = 0; i < ctx->n_buffers; ++i) {
206+
[ctx->buffers[i].metal release];
207+
}
206208
free(ctx);
207209
}
208210

llama.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,13 @@ struct llama_model {
253253

254254
struct llama_context {
255255
llama_context(const llama_model & model, const llama_vocab & vocab) : model(model), vocab(vocab), t_load_us(model.t_load_us), t_start_us(model.t_start_us) {}
256-
256+
#ifdef GGML_USE_METAL
257+
~llama_context() {
258+
if (ctx_metal) {
259+
ggml_metal_free(ctx_metal);
260+
}
261+
}
262+
#endif
257263
std::mt19937 rng;
258264

259265
bool has_evaluated_once = false;

0 commit comments

Comments
 (0)