summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDidzis Gosko <didzis@users.noreply.github.com>2024-02-11 16:41:41 +0200
committerGeorgi Gerganov <ggerganov@gmail.com>2024-02-19 15:09:43 +0200
commit890559ab28e354052e16e770155ad007fd0856e8 (patch)
tree93e5435f8895cf4c5925eac3cc5a32f6ec7dbe0b
parentd0e3ce51f45bd6a646da1952d7e5d143a087db3e (diff)
metal : option to embed MSL source into compiled binary (whisper/1842)
* 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
-rw-r--r--ggml-metal.m9
1 files changed, 9 insertions, 0 deletions
diff --git a/ggml-metal.m b/ggml-metal.m
index f3c1fff8..956e323a 100644
--- a/ggml-metal.m
+++ b/ggml-metal.m
@@ -277,6 +277,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;
@@ -299,6 +307,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