]> git.djapps.eu Git - pkg/ggml/sources/ggml/commitdiff
metal : option to embed MSL source into compiled binary (whisper/1842)
authorDidzis Gosko <redacted>
Sun, 11 Feb 2024 14:41:41 +0000 (16:41 +0200)
committerGeorgi Gerganov <redacted>
Mon, 12 Feb 2024 07:32:52 +0000 (09:32 +0200)
* ggml : embed Metal library source (ggml-metal.metal) into binary

enable by setting WHISPER_EMBED_METAL_LIBRARY

* rename the build option

* rename the preprocessor directive

* generate Metal library embedding assembly on-fly during build process

src/ggml-metal.m

index c1d8e2de81e023aa277b059ce94cac506f6b2a8b..f82f72ca41d1322a4b44b1ef241f63896589d3be 100644 (file)
@@ -272,6 +272,14 @@ static struct ggml_metal_context * ggml_metal_init(int n_cb) {
                 return NULL;
             }
         } else {
+#if GGML_METAL_EMBED_LIBRARY
+            GGML_METAL_LOG_INFO("%s: using embedded metal library\n", __func__);
+
+            extern const char ggml_metallib_start[];
+            extern const char ggml_metallib_end[];
+
+            NSString * src  = [[NSString alloc] initWithBytes:ggml_metallib_start length:(ggml_metallib_end-ggml_metallib_start) encoding:NSUTF8StringEncoding];
+#else
             GGML_METAL_LOG_INFO("%s: default.metallib not found, loading from source\n", __func__);
 
             NSString * sourcePath;
@@ -294,6 +302,7 @@ static struct ggml_metal_context * ggml_metal_init(int n_cb) {
                 GGML_METAL_LOG_ERROR("%s: error: %s\n", __func__, [[error description] UTF8String]);
                 return NULL;
             }
+#endif
 
             @autoreleasepool {
                 // dictionary of preprocessor macros