Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 303f580

Browse filesBrowse files
authored
metal : fix issue with ggml-metal.metal path. Closes abetlen#1769 (abetlen#1782)
* Fix issue with ggml-metal.metal path * Add ggml-metal.metal as a resource for llama target * Update flake.nix metal kernel substitution
1 parent 059e990 commit 303f580
Copy full SHA for 303f580

File tree

Expand file treeCollapse file tree

3 files changed

+15
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+15
-2
lines changed

‎CMakeLists.txt

Copy file name to clipboardExpand all lines: CMakeLists.txt
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ if (LLAMA_METAL)
218218

219219
# copy ggml-metal.metal to bin directory
220220
configure_file(ggml-metal.metal bin/ggml-metal.metal COPYONLY)
221+
if (LLAMA_METAL)
222+
set_target_properties(llama PROPERTIES RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal.metal")
223+
endif()
221224

222225
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS}
223226
${FOUNDATION_LIBRARY}
@@ -432,6 +435,9 @@ target_link_libraries(llama PRIVATE
432435
if (BUILD_SHARED_LIBS)
433436
set_target_properties(llama PROPERTIES POSITION_INDEPENDENT_CODE ON)
434437
target_compile_definitions(llama PRIVATE LLAMA_SHARED LLAMA_BUILD)
438+
if (LLAMA_METAL)
439+
set_target_properties(llama PROPERTIES RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal.metal")
440+
endif()
435441
endif()
436442

437443
if (GGML_SOURCES_CUDA)

‎flake.nix

Copy file name to clipboardExpand all lines: flake.nix
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
postPatch =
2929
if isM1 then ''
3030
substituteInPlace ./ggml-metal.m \
31-
--replace '[[NSBundle mainBundle] pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/ggml-metal.metal\";"
31+
--replace '[bundle pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/ggml-metal.metal\";"
3232
'' else "";
3333
nativeBuildInputs = with pkgs; [ cmake ];
3434
buildInputs = osSpecific;

‎ggml-metal.m

Copy file name to clipboardExpand all lines: ggml-metal.m
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
// for now it is easier to work in a separate file
7474
static NSString * const msl_library_source = @"see metal.metal";
7575

76+
// Here to assist with NSBundle Path Hack
77+
@interface GGMLMetalClass : NSObject
78+
@end
79+
@implementation GGMLMetalClass
80+
@end
81+
7682
struct ggml_metal_context * ggml_metal_init(void) {
7783
fprintf(stderr, "%s: allocating\n", __func__);
7884

@@ -108,7 +114,8 @@
108114
NSError * error = nil;
109115

110116
//NSString * path = [[NSBundle mainBundle] pathForResource:@"../../examples/metal/metal" ofType:@"metal"];
111-
NSString * path = [[NSBundle mainBundle] pathForResource:@"ggml-metal" ofType:@"metal"];
117+
NSBundle * bundle = [NSBundle bundleForClass:[GGMLMetalClass class]];
118+
NSString * path = [bundle pathForResource:@"ggml-metal" ofType:@"metal"];
112119
fprintf(stderr, "%s: loading '%s'\n", __func__, [path UTF8String]);
113120

114121
NSString * src = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.