Skip to content

Commit 8ce774a

Browse files
authored
metal : fix build(#17799)
* metal : fix build * tests : fix context destruction
1 parent 67788f6 commit 8ce774a

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

examples/save-load-state/save-load-state.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ int main(int argc, char ** argv) {
241241

242242
llama_batch_free(batch);
243243

244+
// this one is managed by common_init_result
245+
//llama_free(ctx);
246+
247+
llama_free(ctx2);
248+
llama_free(ctx3);
249+
244250
if (result0 != result2) {
245251
fprintf(stderr, "\n%s : error : the seq restore generation is different\n", __func__);
246252
return 1;

ggml/src/ggml-metal/ggml-metal-device.m

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -574,22 +574,26 @@ ggml_metal_rsets_t ggml_metal_rsets_init(void) {
574574
// the requests stop after a certain amount of time (keep_alive_s) of inactivity
575575
dispatch_queue_t d_queue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0);
576576
dispatch_group_async(res->d_group, d_queue, ^{
577-
while (!atomic_load_explicit(&res->d_stop, memory_order_relaxed)) {
578-
if (atomic_load_explicit(&res->d_loop, memory_order_relaxed) > 0) {
579-
[res->lock lock];
577+
#if defined(GGML_METAL_HAS_RESIDENCY_SETS)
578+
if (@available(macOS 15.0, iOS 18.0, tvOS 18.0, visionOS 2.0, *)) {
579+
while (!atomic_load_explicit(&res->d_stop, memory_order_relaxed)) {
580+
if (atomic_load_explicit(&res->d_loop, memory_order_relaxed) > 0) {
581+
[res->lock lock];
580582

581-
for (int i = 0; i < (int) res->data.count; ++i) {
582-
[res->data[i] requestResidency];
583-
}
583+
for (int i = 0; i < (int) res->data.count; ++i) {
584+
[res->data[i] requestResidency];
585+
}
584586

585-
atomic_fetch_sub_explicit(&res->d_loop, 1, memory_order_relaxed);
587+
atomic_fetch_sub_explicit(&res->d_loop, 1, memory_order_relaxed);
586588

587-
[res->lock unlock];
588-
}
589+
[res->lock unlock];
590+
}
589591

590-
// half a second
591-
usleep(500 * 1000);
592-
}
592+
// half a second
593+
usleep(500 * 1000);
594+
}
595+
}
596+
#endif
593597
});
594598

595599
return res;
@@ -600,6 +604,7 @@ void ggml_metal_rsets_free(ggml_metal_rsets_t rsets) {
600604
return;
601605
}
602606

607+
// note: if you hit this assert, most likely you haven't deallocated all Metal resources before exiting
603608
GGML_ASSERT([rsets->data count] == 0);
604609

605610
atomic_store_explicit(&rsets->d_stop, true, memory_order_relaxed);
@@ -787,9 +792,6 @@ ggml_metal_device_t ggml_metal_device_init(void) {
787792
dev->rsets = nil;
788793
}
789794

790-
791-
// --------------------------------------------------
792-
793795
// print MTL GPU family:
794796
GGML_LOG_INFO("%s: GPU name: %s\n", __func__, dev->props.name);
795797

0 commit comments

Comments
 (0)