Skip to content

Commit d783f79

Browse files
authored
metal : return null instead of exit(1) (#2573)
1 parent d75561d commit d783f79

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ggml-metal.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ @implementation GGMLMetalClass
126126
ctx->library = [ctx->device newLibraryWithSource:msl_library_source options:nil error:&error];
127127
if (error) {
128128
fprintf(stderr, "%s: error: %s\n", __func__, [[error description] UTF8String]);
129-
exit(1);
129+
return NULL;
130130
}
131131
}
132132
#else
@@ -144,7 +144,7 @@ @implementation GGMLMetalClass
144144
NSString * src = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
145145
if (error) {
146146
fprintf(stderr, "%s: error: %s\n", __func__, [[error description] UTF8String]);
147-
exit(1);
147+
return NULL;
148148
}
149149

150150
#ifdef GGML_QKK_64
@@ -156,7 +156,7 @@ @implementation GGMLMetalClass
156156
#endif
157157
if (error) {
158158
fprintf(stderr, "%s: error: %s\n", __func__, [[error description] UTF8String]);
159-
exit(1);
159+
return NULL;
160160
}
161161
}
162162
#endif

llama.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,6 +3337,12 @@ struct llama_context * llama_new_context_with_model(
33373337
// this allocates all Metal resources and memory buffers
33383338
ctx->ctx_metal = ggml_metal_init(1);
33393339

3340+
if (!ctx->ctx_metal) {
3341+
LLAMA_LOG_ERROR("%s: ggml_metal_init() failed\n", __func__);
3342+
llama_free(ctx);
3343+
return NULL;
3344+
}
3345+
33403346
void * data_ptr = NULL;
33413347
size_t data_size = 0;
33423348

0 commit comments

Comments
 (0)