7373 ctx->has_simdgroup_mm = [ctx->mtl_device supportsFamily: MTLGPUFamilyApple7];
7474
7575#if defined(GGML_METAL_HAS_RESIDENCY_SETS)
76- ctx->has_residency_sets = true ;
76+ ctx->has_residency_sets = getenv ( " GGML_METAL_NO_RESIDENCY " ) == NULL ;
7777#endif
7878
7979 ctx->has_bfloat = [ctx->mtl_device supportsFamily: MTLGPUFamilyMetal3_GGML];
@@ -1058,11 +1058,19 @@ static void ggml_metal_free(struct ggml_backend_metal_context * ctx) {
10581058};
10591059
10601060// rset init
1061- static bool ggml_backend_metal_buffer_rset_init (struct ggml_backend_metal_buffer_context * ctx, id <MTLDevice > device) {
1061+ static bool ggml_backend_metal_buffer_rset_init (
1062+ struct ggml_backend_metal_buffer_context * ctx,
1063+ struct ggml_backend_metal_device_context * ctx_dev,
1064+ id <MTLDevice > device) {
1065+ ctx->rset = nil ;
1066+
10621067#if defined(GGML_METAL_HAS_RESIDENCY_SETS)
10631068 if (@available (macOS 15.0 , *)) {
1064- MTLResidencySetDescriptor * desc;
1065- desc = [[MTLResidencySetDescriptor alloc ] init ];
1069+ if (!ctx_dev->has_residency_sets ) {
1070+ return true ;
1071+ }
1072+
1073+ MTLResidencySetDescriptor * desc = [[MTLResidencySetDescriptor alloc ] init ];
10661074 desc.label = @" ggml_backend_metal" ;
10671075 desc.initialCapacity = ctx->n_buffers ;
10681076
@@ -1089,8 +1097,6 @@ static bool ggml_backend_metal_buffer_rset_init(struct ggml_backend_metal_buffer
10891097 GGML_UNUSED (device);
10901098#endif
10911099
1092- ctx->rset = nil ;
1093-
10941100 return true ;
10951101}
10961102
@@ -4386,7 +4392,7 @@ static ggml_backend_buffer_t ggml_backend_metal_buffer_type_alloc_buffer(ggml_ba
43864392 return NULL ;
43874393 }
43884394
4389- if (!ggml_backend_metal_buffer_rset_init (ctx, device)) {
4395+ if (!ggml_backend_metal_buffer_rset_init (ctx, ctx_dev, device)) {
43904396 GGML_LOG_ERROR (" %s : error: failed to initialize residency set\n " , __func__);
43914397 free (ctx);
43924398 ggml_backend_metal_device_rel (ctx_dev);
@@ -4536,7 +4542,7 @@ ggml_backend_buffer_t ggml_backend_metal_buffer_from_ptr(void * data, size_t siz
45364542 }
45374543 }
45384544
4539- if (!ggml_backend_metal_buffer_rset_init (ctx, device)) {
4545+ if (!ggml_backend_metal_buffer_rset_init (ctx, ctx_dev, device)) {
45404546 GGML_LOG_ERROR (" %s : error: failed to initialize residency set\n " , __func__);
45414547 free (ctx);
45424548 ggml_backend_metal_device_rel (ctx_dev);
@@ -4856,7 +4862,7 @@ static ggml_backend_buffer_t ggml_backend_metal_device_buffer_from_ptr(ggml_back
48564862 }
48574863 }
48584864
4859- if (!ggml_backend_metal_buffer_rset_init (ctx, device)) {
4865+ if (!ggml_backend_metal_buffer_rset_init (ctx, ctx_dev, device)) {
48604866 GGML_LOG_ERROR (" %s : error: failed to initialize residency set\n " , __func__);
48614867 free (ctx);
48624868 ggml_backend_metal_device_rel (ctx_dev);
0 commit comments