@@ -257,13 +257,14 @@ static void ggml_metal_log(enum ggml_log_level level, const char * format, ...){
257257 bundle = [NSBundle bundleForClass: [GGMLMetalClass class ]];
258258#endif
259259 NSError * error = nil ;
260- NSString * libPath = [bundle pathForResource: @" default " ofType: @" metallib" ];
260+ NSString * libPath = [bundle pathForResource: @" ggml " ofType: @" metallib" ];
261261 if (libPath != nil ) {
262+ // pre-compiled library found
262263 NSURL * libURL = [NSURL fileURLWithPath: libPath];
263264 GGML_METAL_LOG_INFO (" %s : loading '%s '\n " , __func__, [libPath UTF8String ]);
264265 ctx->library = [ctx->device newLibraryWithURL: libURL error: &error];
265266 } else {
266- GGML_METAL_LOG_INFO (" %s : default .metallib not found, loading from source\n " , __func__);
267+ GGML_METAL_LOG_INFO (" %s : ggml .metallib not found, loading from source\n " , __func__);
267268
268269 NSString * sourcePath;
269270 NSString * ggmlMetalPathResources = [[NSProcessInfo processInfo ].environment objectForKey: @" GGML_METAL_PATH_RESOURCES" ];
@@ -291,6 +292,13 @@ static void ggml_metal_log(enum ggml_log_level level, const char * format, ...){
291292 options = [MTLCompileOptions new ];
292293 options.preprocessorMacros = @{ @" QK_K" : @(64 ) };
293294#endif
295+ // try to disable fast-math
296+ // NOTE: this seems to have no effect whatsoever
297+ // instead, in order to disable fast-math, we have to build ggml.metallib from the command line
298+ // using xcrun -sdk macosx metal -fno-fast-math -c ggml-metal.metal -o ggml-metal.air
299+ // and go through the "pre-compiled library found" path above
300+ // [options setFastMathEnabled:false];
301+
294302 ctx->library = [ctx->device newLibraryWithSource: src options: options error: &error];
295303 }
296304
0 commit comments