Skip to content

Commit

Permalink
metal : try cwd for ggml-metal.metal if bundle lookup fails (ggergano…
Browse files Browse the repository at this point in the history
…v#3793)

* Try cwd for ggml-metal if bundle lookup fails

When building with `-DBUILD_SHARED_LIBS=ON -DLLAMA_METAL=ON -DLLAMA_BUILD_SERVER=ON`,
`server` would fail to load `ggml-metal.metal` because `[bundle pathForResource:...]`
returns `nil`.  In that case, fall back to `ggml-metal.metal` in the cwd instead of
passing `null` as a path.

Follows up on ggerganov#1782

* Update ggml-metal.m

---------

Co-authored-by: Georgi Gerganov <[email protected]>
  • Loading branch information
akx and ggerganov authored Oct 28, 2023
1 parent ba231e8 commit 82a6646
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ggml-metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ static void ggml_metal_log(enum ggml_log_level level, const char* format, ...){
GGML_METAL_LOG_INFO("%s: default.metallib not found, loading from source\n", __func__);

NSString * sourcePath = [bundle pathForResource:@"ggml-metal" ofType:@"metal"];
if (sourcePath == nil) {
GGML_METAL_LOG_WARN("%s: error: could not use bundle path to find ggml-metal.metal, falling back to trying cwd\n", __func__);
sourcePath = @"ggml-metal.metal";
}
GGML_METAL_LOG_INFO("%s: loading '%s'\n", __func__, [sourcePath UTF8String]);
NSString * src = [NSString stringWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:&error];
if (error) {
Expand Down

0 comments on commit 82a6646

Please sign in to comment.