simply code and allow to use the directory containing the file as a valid value as intented in the first place

This commit is contained in:
Marc 2023-08-15 16:35:06 +02:00
parent 68365e2291
commit 03297c1a7c

View file

@ -1,4 +1,5 @@
#import "ggml-metal.h" #import "ggml-metal.h"
#include <objc/objc.h>
#import "ggml.h" #import "ggml.h"
@ -132,27 +133,36 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
//NSString * path = [[NSBundle mainBundle] pathForResource:@"../../examples/metal/metal" ofType:@"metal"]; //NSString * path = [[NSBundle mainBundle] pathForResource:@"../../examples/metal/metal" ofType:@"metal"];
const char* v = getenv("GGML_METAL_PATH"); const char* v = getenv("GGML_METAL_PATH");
NSString * path; NSString * path;
BOOL doLegacyCode = false;
if (v) { if (v) {
path = [NSString stringWithCString: v encoding: NSUTF8StringEncoding]; path = [NSString stringWithCString: v encoding: NSUTF8StringEncoding];
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path]) { BOOL isDir;
fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]); if ([fileManager fileExistsAtPath:path isDirectory: &isDir]) {
} else { if (isDir) {
path = [path stringByAppendingString: @"/ggml-metal.metal"]; path = [path stringByAppendingString: @"/ggml-metal.metal"];
if ([fileManager fileExistsAtPath:path]) { if ([fileManager fileExistsAtPath:path]) {
fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]); fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]);
} else {
// Use original code
doLegacyCode = true;
}
} else { } else {
// Use original code fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]);
NSBundle * bundle = [NSBundle bundleForClass:[GGMLMetalClass class]];
path = [bundle pathForResource:@"ggml-metal" ofType:@"metal"];
fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]);
} }
} else {
// Use original code
doLegacyCode = true;
} }
} else { } else {
NSBundle * bundle = [NSBundle bundleForClass:[GGMLMetalClass class]]; // Use original code
path = [bundle pathForResource:@"ggml-metal" ofType:@"metal"]; doLegacyCode = true;
fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]); }
if (doLegacyCode) {
NSBundle * bundle = [NSBundle bundleForClass:[GGMLMetalClass class]];
path = [bundle pathForResource:@"ggml-metal" ofType:@"metal"];
fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]);
} }
NSString * src = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]; NSString * src = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];