8000 metal : support default.metallib load & reuse code for swift package by jhen0409 · Pull Request #3522 · ggml-org/llama.cpp · GitHub
[go: up one dir, main page]

Skip to content

metal : support default.metallib load & reuse code for swift package #3522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
metal : use SWIFT_PACKAGE def instead of define GGML_SWIFT
  • Loading branch information
jhen0409 committed Oct 7, 2023
commit f134d64bbdbab6b52c3cb6fe7fc19018fb7bca42
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.gcno
*.gcda
*.dot
*.metallib
.DS_Store
.build/
.cache/
Expand Down
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ let resources: [Resource] = [
let additionalSources: [String] = ["ggml-metal.m"]
let additionalSettings: [CSetting] = [
.unsafeFlags(["-fno-objc-arc"]),
.define("GGML_SWIFT"),
.define("GGML_USE_METAL")
]
#else
let platforms: [SupportedPlatform]? = nil
let exclude: [String] = ["ggml-metal.metal"]
let resources: [String] = []
let resources: [Resource] = []
let additionalSources: [String] = []
let additionalSettings: [CSetting] = []
#endif
Expand Down
8 changes: 4 additions & 4 deletions ggml-metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static void ggml_metal_log(enum ggml_log_level level, const char* format, ...){
// load library
{
NSBundle * bundle = nil;
#ifdef GGML_SWIFT
#ifdef SWIFT_PACKAGE
bundle = SWIFTPM_MODULE_BUNDLE;
#else
bundle = [NSBundle bundleForClass:[GGMLMetalClass class]];
Expand All @@ -204,7 +204,7 @@ static void ggml_metal_log(enum ggml_log_level level, const char* format, ...){
GGML_METAL_LOG_INFO("%s: loading '%s'\n", __func__, [sourcePath UTF8String]);
NSString * src = [NSString stringWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:&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;
}

Expand All @@ -215,9 +215,9 @@ static void ggml_metal_log(enum ggml_log_level level, const char* format, ...){
#endif
ctx->library = [ctx->device newLibraryWithSource:src options:options error:&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;
}
}
Expand Down
0