metal : use SWIFT_PACKAGE def instead of define GGML_SWIFT

This commit is contained in:
Jhen 2023-10-07 11:20:11 +08:00
parent 1b88cbadd5
commit f134d64bbd
3 changed files with 6 additions and 6 deletions

1
.gitignore vendored
View file

@ -10,6 +10,7 @@
*.gcno *.gcno
*.gcda *.gcda
*.dot *.dot
*.metallib
.DS_Store .DS_Store
.build/ .build/
.cache/ .cache/

View file

@ -16,13 +16,12 @@ let resources: [Resource] = [
let additionalSources: [String] = ["ggml-metal.m"] let additionalSources: [String] = ["ggml-metal.m"]
let additionalSettings: [CSetting] = [ let additionalSettings: [CSetting] = [
.unsafeFlags(["-fno-objc-arc"]), .unsafeFlags(["-fno-objc-arc"]),
.define("GGML_SWIFT"),
.define("GGML_USE_METAL") .define("GGML_USE_METAL")
] ]
#else #else
let platforms: [SupportedPlatform]? = nil let platforms: [SupportedPlatform]? = nil
let exclude: [String] = ["ggml-metal.metal"] let exclude: [String] = ["ggml-metal.metal"]
let resources: [String] = [] let resources: [Resource] = []
let additionalSources: [String] = [] let additionalSources: [String] = []
let additionalSettings: [CSetting] = [] let additionalSettings: [CSetting] = []
#endif #endif

View file

@ -186,7 +186,7 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
// load library // load library
{ {
NSBundle * bundle = nil; NSBundle * bundle = nil;
#ifdef GGML_SWIFT #ifdef SWIFT_PACKAGE
bundle = SWIFTPM_MODULE_BUNDLE; bundle = SWIFTPM_MODULE_BUNDLE;
#else #else
bundle = [NSBundle bundleForClass:[GGMLMetalClass class]]; bundle = [NSBundle bundleForClass:[GGMLMetalClass class]];
@ -204,7 +204,7 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
GGML_METAL_LOG_INFO("%s: loading '%s'\n", __func__, [sourcePath UTF8String]); GGML_METAL_LOG_INFO("%s: loading '%s'\n", __func__, [sourcePath UTF8String]);
NSString * src = [NSString stringWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:&error]; NSString * src = [NSString stringWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:&error];
if (error) { if (error) {
GGML_METAL_LOG_INFO("%s: error: %s\n", __func__, [[error description] UTF8String]); GGML_METAL_LOG_ERROR("%s: error: %s\n", __func__, [[error description] UTF8String]);
return NULL; return NULL;
} }
@ -215,9 +215,9 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
#endif #endif
ctx->library = [ctx->device newLibraryWithSource:src options:options error:&error]; ctx->library = [ctx->device newLibraryWithSource:src options:options error:&error];
} }
if (error) { if (error) {
GGML_METAL_LOG_INFO("%s: error: %s\n", __func__, [[error description] UTF8String]); GGML_METAL_LOG_ERROR("%s: error: %s\n", __func__, [[error description] UTF8String]);
return NULL; return NULL;
} }
} }