|
93 | 93 | if (ctx->mtl_device == nil) {
|
94 | 94 | ctx->mtl_device = MTLCreateSystemDefaultDevice();
|
95 | 95 |
|
96 |
| - ctx->has_simdgroup_reduction = [ctx->mtl_device supportsFamily:MTLGPUFamilyApple7]; |
97 |
| - ctx->has_simdgroup_reduction |= [ctx->mtl_device supportsFamily:MTLGPUFamilyMetal3_GGML]; |
| 96 | + if (ctx->mtl_device) { |
| 97 | + ctx->has_simdgroup_reduction = [ctx->mtl_device supportsFamily:MTLGPUFamilyApple7]; |
| 98 | + ctx->has_simdgroup_reduction |= [ctx->mtl_device supportsFamily:MTLGPUFamilyMetal3_GGML]; |
98 | 99 |
|
99 |
| - ctx->has_simdgroup_mm = [ctx->mtl_device supportsFamily:MTLGPUFamilyApple7]; |
| 100 | + ctx->has_simdgroup_mm = [ctx->mtl_device supportsFamily:MTLGPUFamilyApple7]; |
100 | 101 |
|
101 | 102 | #if defined(GGML_METAL_HAS_RESIDENCY_SETS)
|
102 |
| - ctx->has_residency_sets = getenv("GGML_METAL_NO_RESIDENCY") == nil; |
| 103 | + ctx->has_residency_sets = getenv("GGML_METAL_NO_RESIDENCY") == nil; |
103 | 104 | #endif
|
104 | 105 |
|
105 |
| - ctx->has_bfloat = [ctx->mtl_device supportsFamily:MTLGPUFamilyMetal3_GGML]; |
106 |
| - ctx->has_bfloat |= [ctx->mtl_device supportsFamily:MTLGPUFamilyApple6]; |
| 106 | + ctx->has_bfloat = [ctx->mtl_device supportsFamily:MTLGPUFamilyMetal3_GGML]; |
| 107 | + ctx->has_bfloat |= [ctx->mtl_device supportsFamily:MTLGPUFamilyApple6]; |
107 | 108 |
|
108 | 109 | #if defined(GGML_METAL_USE_BF16)
|
109 |
| - ctx->use_bfloat = ctx->has_bfloat; |
| 110 | + ctx->use_bfloat = ctx->has_bfloat; |
110 | 111 | #else
|
111 |
| - ctx->use_bfloat = false; |
| 112 | + ctx->use_bfloat = false; |
112 | 113 | #endif
|
113 |
| - ctx->use_fusion = getenv("GGML_METAL_FUSION_DISABLE") == nil; |
| 114 | + ctx->use_fusion = getenv("GGML_METAL_FUSION_DISABLE") == nil; |
114 | 115 |
|
115 |
| - { |
116 |
| - const char * val = getenv("GGML_METAL_FUSION_DEBUG"); |
117 |
| - ctx->debug_fusion = val ? atoi(val) : 0; |
118 |
| - } |
| 116 | + { |
| 117 | + const char * val = getenv("GGML_METAL_FUSION_DEBUG"); |
| 118 | + ctx->debug_fusion = val ? atoi(val) : 0; |
| 119 | + } |
119 | 120 |
|
120 |
| - memset(ctx->fuse_cnt, 0, sizeof(ctx->fuse_cnt)); |
| 121 | + memset(ctx->fuse_cnt, 0, sizeof(ctx->fuse_cnt)); |
121 | 122 |
|
122 |
| - ctx->max_size = ctx->mtl_device.maxBufferLength; |
| 123 | + ctx->max_size = ctx->mtl_device.maxBufferLength; |
123 | 124 |
|
124 |
| - strncpy(ctx->name, [[ctx->mtl_device name] UTF8String], sizeof(ctx->name) - 1); |
| 125 | + strncpy(ctx->name, [[ctx->mtl_device name] UTF8String], sizeof(ctx->name) - 1); |
| 126 | + } |
125 | 127 | }
|
126 | 128 |
|
127 | 129 | ctx->mtl_device_ref_count++;
|
|
0 commit comments