@@ -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