Skip to content

Commit

Permalink
metal : release buffers when freeing metal context (ggerganov#2062)
Browse files Browse the repository at this point in the history
  • Loading branch information
apage43 committed Jul 1, 2023
1 parent 471aab6 commit 2f8cd97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ggml-metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ @implementation GGMLMetalClass

void ggml_metal_free(struct ggml_metal_context * ctx) {
fprintf(stderr, "%s: deallocating\n", __func__);

for (int i = 0; i < ctx->n_buffers; ++i) {
[ctx->buffers[i].metal release];
}
free(ctx);
}

Expand Down
8 changes: 7 additions & 1 deletion llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,13 @@ struct llama_model {

struct llama_context {
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) {}

#ifdef GGML_USE_METAL
~llama_context() {
if (ctx_metal) {
ggml_metal_free(ctx_metal);
}
}
#endif
std::mt19937 rng;

bool has_evaluated_once = false;
Expand Down

0 comments on commit 2f8cd97

Please sign in to comment.