Merge 8556db5b25
into 990a5e226a
This commit is contained in:
commit
c52991e020
1 changed files with 34 additions and 3 deletions
35
ggml-metal.m
35
ggml-metal.m
|
@ -1,4 +1,5 @@
|
||||||
#import "ggml-metal.h"
|
#import "ggml-metal.h"
|
||||||
|
#include <objc/objc.h>
|
||||||
|
|
||||||
#import "ggml.h"
|
#import "ggml.h"
|
||||||
|
|
||||||
|
@ -174,9 +175,39 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
|
||||||
NSError * error = nil;
|
NSError * error = nil;
|
||||||
|
|
||||||
//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");
|
||||||
|
NSString * path;
|
||||||
|
BOOL doLegacyCode = false;
|
||||||
|
if (v) {
|
||||||
|
path = [NSString stringWithCString: v encoding: NSUTF8StringEncoding];
|
||||||
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
|
BOOL isDir;
|
||||||
|
if ([fileManager fileExistsAtPath:path isDirectory: &isDir]) {
|
||||||
|
if (isDir) {
|
||||||
|
path = [path stringByAppendingString: @"/ggml-metal.metal"];
|
||||||
|
if ([fileManager fileExistsAtPath:path]) {
|
||||||
|
fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]);
|
||||||
|
} else {
|
||||||
|
// Use original code
|
||||||
|
doLegacyCode = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Use original code
|
||||||
|
doLegacyCode = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Use original code
|
||||||
|
doLegacyCode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doLegacyCode) {
|
||||||
NSBundle * bundle = [NSBundle bundleForClass:[GGMLMetalClass class]];
|
NSBundle * bundle = [NSBundle bundleForClass:[GGMLMetalClass class]];
|
||||||
NSString * path = [bundle pathForResource:@"ggml-metal" ofType:@"metal"];
|
path = [bundle pathForResource:@"ggml-metal" ofType:@"metal"];
|
||||||
metal_printf("%s: loading '%s'\n", __func__, [path UTF8String]);
|
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];
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue