File tree 2 files changed +38
-8
lines changed 2 files changed +38
-8
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import PackageDescription
4
4
5
+ #if arch(arm) || arch(arm64)
6
+ let platforms : [ SupportedPlatform ] ? = [
7
+ . macOS( . v11) ,
8
+ . iOS( . v14) ,
9
+ . watchOS( . v4) ,
10
+ . tvOS( . v14)
11
+ ]
12
+ let exclude : [ String ] = [ ]
13
+ let additionalSources : [ String ] = [ " ggml-metal.m " ]
14
+ let additionalSettings : [ CSetting ] = [
15
+ . unsafeFlags( [ " -fno-objc-arc " ] ) ,
16
+ . define( " GGML_SWIFT " ) ,
17
+ . define( " GGML_USE_METAL " )
18
+ ]
19
+ #else
20
+ let platforms : [ SupportedPlatform ] ? = nil
21
+ let exclude : [ String ] = [ " ggml-metal.metal " ]
22
+ let additionalSources : [ String ] = [ ]
23
+ let additionalSettings : [ CSetting ] = [ ]
24
+ #endif
25
+
5
26
let package = Package (
6
27
name: " llama " ,
28
+ platforms: platforms,
7
29
products: [
8
30
. library( name: " llama " , targets: [ " llama " ] ) ,
9
31
] ,
10
32
targets: [
11
33
. target(
12
34
name: " llama " ,
13
35
path: " . " ,
14
- exclude: [ " ggml-metal.metal " ] ,
36
+ exclude: exclude ,
15
37
sources: [
16
38
" ggml.c " ,
17
39
" llama.cpp " ,
18
40
" ggml-alloc.c " ,
19
- " k_quants.c "
20
- ] ,
41
+ " k_quants.c " ,
42
+ ] + additionalSources ,
21
43
publicHeadersPath: " spm-headers " ,
22
44
cSettings: [
23
45
. unsafeFlags( [ " -Wno-shorten-64-to-32 " ] ) ,
24
46
. define( " GGML_USE_K_QUANTS " ) ,
25
47
. define( " GGML_USE_ACCELERATE " )
26
- ] ,
48
+ ] + additionalSettings ,
27
49
linkerSettings: [
28
50
. linkedFramework( " Accelerate " )
29
51
]
30
- ) ,
52
+ )
31
53
] ,
32
54
cxxLanguageStandard: . cxx11
33
55
)
Original file line number Diff line number Diff line change @@ -144,12 +144,20 @@ @implementation GGMLMetalClass
144
144
145
145
ctx->d_queue = dispatch_queue_create (" llama.cpp" , DISPATCH_QUEUE_CONCURRENT);
146
146
147
- #if 0
148
- // compile from source string and show compile log
147
+ #ifdef GGML_SWIFT
148
+ // load the default.metallib file
149
149
{
150
150
NSError * error = nil ;
151
151
152
- ctx->library = [ctx->device newLibraryWithSource:msl_library_source options:nil error:&error];
152
+ NSBundle * bundle = [NSBundle bundleForClass: [GGMLMetalClass class ]];
153
+ NSString * llamaBundlePath = [bundle pathForResource: @" llama_llama" ofType: @" bundle" ];
154
+ NSBundle * llamaBundle = [NSBundle bundleWithPath: llamaBundlePath];
155
+ NSString * libPath = [llamaBundle pathForResource: @" default" ofType: @" metallib" ];
156
+ NSURL * libURL = [NSURL fileURLWithPath: libPath];
157
+
158
+ // Load the metallib file into a Metal library
159
+ ctx->library = [ctx->device newLibraryWithURL: libURL error: &error];
160
+
153
161
if (error) {
154
162
metal_printf (" %s : error: %s \n " , __func__, [[error description ] UTF8String ]);
155
163
return NULL ;
You can’t perform that action at this time.
0 commit comments