File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -4,23 +4,27 @@ import PackageDescription
4
4
5
5
let package = Package (
6
6
name: " llama " ,
7
+ platforms: [ . macOS( . v11) ] ,
7
8
products: [
8
9
. library( name: " llama " , targets: [ " llama " ] ) ,
9
10
] ,
10
11
targets: [
11
12
. target(
12
13
name: " llama " ,
13
14
path: " . " ,
14
- exclude: [ " ggml-metal.metal " ] ,
15
15
sources: [
16
16
" ggml.c " ,
17
17
" llama.cpp " ,
18
18
" ggml-alloc.c " ,
19
- " k_quants.c "
19
+ " k_quants.c " ,
20
+ " ggml-metal.m " ,
20
21
] ,
21
22
publicHeadersPath: " spm-headers " ,
22
23
cSettings: [
23
24
. unsafeFlags( [ " -Wno-shorten-64-to-32 " ] ) ,
25
+ . unsafeFlags( [ " -fno-objc-arc " ] ) ,
26
+ . define( " GGML_SWIFT " ) ,
27
+ . define( " GGML_USE_METAL " ) ,
24
28
. define( " GGML_USE_K_QUANTS " ) ,
25
29
. define( " GGML_USE_ACCELERATE " )
26
30
] ,
Original file line number Diff line number Diff line change @@ -140,12 +140,22 @@ @implementation GGMLMetalClass
140
140
141
141
ctx->d_queue = dispatch_queue_create (" llama.cpp" , DISPATCH_QUEUE_CONCURRENT);
142
142
143
- #if 0
144
- // compile from source string and show compile log
143
+ MTLCompileOptions * options = [MTLCompileOptions new ];
144
+ options.preprocessorMacros = @{ @" QK_K" : @(64 ) };
145
+
146
+ #ifdef GGML_SWIFT
147
+ // load the default.metallib file
145
148
{
146
149
NSError * error = nil ;
147
150
148
- ctx->library = [ctx->device newLibraryWithSource:msl_library_source options:nil error:&error];
151
+ NSBundle * bundle = [NSBundle bundleForClass: [GGMLMetalClass class ]];
152
+ NSString * llamaBundlePath = [bundle pathForResource: @" llama_llama" ofType: @" bundle" ];
153
+ NSBundle * llamaBundle = [NSBundle bundleWithPath: llamaBundlePath];
154
+ NSString * libPath = [llamaBundle pathForResource: @" default" ofType: @" metallib" ];
155
+
156
+ // Load the metallib file into a Metal library
157
+ ctx->library = [ctx->device newLibraryWithFile: libPath error: &error];
158
+
149
159
if (error) {
150
160
metal_printf (" %s : error: %s \n " , __func__, [[error description ] UTF8String ]);
151
161
return NULL ;
@@ -170,8 +180,6 @@ @implementation GGMLMetalClass
170
180
}
171
181
172
182
#ifdef GGML_QKK_64
173
- MTLCompileOptions * options = [MTLCompileOptions new ];
174
- options.preprocessorMacros = @{ @" QK_K" : @(64 ) };
175
183
ctx->library = [ctx->device newLibraryWithSource: src options: options error: &error];
176
184
#else
177
185
ctx->library = [ctx->device newLibraryWithSource: src options: nil error: &error];
You can’t perform that action at this time.
0 commit comments