This fixes segmentation fault error when running tests when no metal
devices are available (for example, when not linked with Core Graphics
framework or otherwise).
if (ctx->mtl_device == nil) {
ctx->mtl_device = MTLCreateSystemDefaultDevice();
+ }
+ if (ctx->mtl_device) {
ctx->has_simdgroup_reduction = [ctx->mtl_device supportsFamily:MTLGPUFamilyApple7];
ctx->has_simdgroup_reduction |= [ctx->mtl_device supportsFamily:MTLGPUFamilyMetal3_GGML];
ctx->mtl_device_ref_count--;
if (ctx->mtl_device_ref_count == 0) {
- [ctx->mtl_device release];
- ctx->mtl_device = nil;
+ if (ctx->mtl_device) {
+ [ctx->mtl_device release];
+ ctx->mtl_device = nil;
+ }
}
}