]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
metal : return null instead of exit(1) (#2573)
authorJhen-Jie Hong <redacted>
Mon, 14 Aug 2023 13:37:39 +0000 (21:37 +0800)
committerGitHub <redacted>
Mon, 14 Aug 2023 13:37:39 +0000 (16:37 +0300)
ggml-metal.m
llama.cpp

index b47a98e214b613fb0f022f8606047e6771201ddd..fbac21e3a9c7f0324f7b6b932f9360bef97955cf 100644 (file)
@@ -126,7 +126,7 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
         ctx->library = [ctx->device newLibraryWithSource:msl_library_source options:nil error:&error];
         if (error) {
             fprintf(stderr, "%s: error: %s\n", __func__, [[error description] UTF8String]);
-            exit(1);
+            return NULL;
         }
     }
 #else
@@ -144,7 +144,7 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
         NSString * src  = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
         if (error) {
             fprintf(stderr, "%s: error: %s\n", __func__, [[error description] UTF8String]);
-            exit(1);
+            return NULL;
         }
 
 #ifdef GGML_QKK_64
@@ -156,7 +156,7 @@ struct ggml_metal_context * ggml_metal_init(int n_cb) {
 #endif
         if (error) {
             fprintf(stderr, "%s: error: %s\n", __func__, [[error description] UTF8String]);
-            exit(1);
+            return NULL;
         }
     }
 #endif
index 0cf2b3749ccb5e9564a23ea94449fc56f7b1420d..c8ab313d9c11639c5739a49b6d35e47341531ba2 100644 (file)
--- a/llama.cpp
+++ b/llama.cpp
@@ -3337,6 +3337,12 @@ struct llama_context * llama_new_context_with_model(
         // this allocates all Metal resources and memory buffers
         ctx->ctx_metal = ggml_metal_init(1);
 
+        if (!ctx->ctx_metal) {
+            LLAMA_LOG_ERROR("%s: ggml_metal_init() failed\n", __func__);
+            llama_free(ctx);
+            return NULL;
+        }
+
         void * data_ptr  = NULL;
         size_t data_size = 0;