Skip to content

Commit ae5331d

Browse files
committed
GGML_ABORT use format string
ggml-ci
1 parent 3ed1bc0 commit ae5331d

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

ggml/include/ggml.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@
272272
#define GGML_NORETURN _Noreturn
273273
#endif
274274

275-
#define GGML_ABORT(x) ggml_abort(__FILE__, __LINE__, x)
276-
#define GGML_ASSERT(x) if (!(x)) GGML_ABORT(#x)
275+
#define GGML_ABORT(...) ggml_abort(__FILE__, __LINE__, __VA_ARGS__)
276+
#define GGML_ASSERT(x) if (!(x)) GGML_ABORT("GGML_ASSERT(%s) failed", #x)
277277

278278
// used to copy the number of elements and stride in bytes of tensors into local variables.
279279
// main purpose is to reduce code duplication and improve readability.
@@ -323,7 +323,8 @@
323323
extern "C" {
324324
#endif
325325

326-
GGML_NORETURN GGML_API void ggml_abort(const char * file, int line, const char * expr);
326+
GGML_NORETURN GGML_ATTRIBUTE_FORMAT(3, 4)
327+
GGML_API void ggml_abort(const char * file, int line, const char * fmt, ...);
327328

328329
enum ggml_status {
329330
GGML_STATUS_ALLOC_FAILED = -2,

ggml/src/ggml-alloc.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ static void remove_allocated_tensor(struct ggml_dyn_tallocr * alloc, size_t offs
141141
return;
142142
}
143143
}
144-
fprintf(stderr, "tried to free tensor %s not found\n", tensor->name);
145-
GGML_ABORT("tensor not found");
144+
GGML_ABORT("tried to free tensor %s not found\n", tensor->name);
146145
}
147146
#endif
148147

ggml/src/ggml-backend.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,7 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg
12791279

12801280
sched->ctx = ggml_init(params);
12811281
if (sched->ctx == NULL) {
1282-
fprintf(stderr, "%s: failed to initialize context\n", __func__);
1283-
GGML_ABORT("fatal error");
1282+
GGML_ABORT("%s: failed to initialize context\n", __func__);
12841283
}
12851284

12861285
// pass 1: assign backends to ops with pre-allocated inputs

ggml/src/ggml-blas.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ GGML_CALL static enum ggml_status ggml_backend_blas_graph_compute(ggml_backend_t
275275
break;
276276

277277
default:
278-
fprintf(stderr, "%s: unsupported op %s\n", __func__, ggml_op_desc(node));
279-
GGML_ABORT("fatal error");
278+
GGML_ABORT("%s: unsupported op %s\n", __func__, ggml_op_desc(node));
280279
}
281280
}
282281

ggml/src/ggml-cuda/getrows.cu

+1-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ void ggml_cuda_op_get_rows(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
171171
break;
172172
default:
173173
// TODO: k-quants
174-
fprintf(stderr, "%s: unsupported type: %s\n", __func__, ggml_type_name(src0->type));
175-
GGML_ABORT("fatal error");
174+
GGML_ABORT("%s: unsupported type: %s\n", __func__, ggml_type_name(src0->type));
176175
break;
177176
}
178177
}

ggml/src/ggml.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,18 @@ static void ggml_print_backtrace(void) {
191191
}
192192
#endif
193193

194-
void ggml_abort(const char * file, int line, const char * expr) {
194+
void ggml_abort(const char * file, int line, const char * fmt, ...) {
195195
fflush(stdout);
196-
fprintf(stderr, "GGML_ASSERT: %s:%d: %s\n", file, line, expr);
196+
197+
fprintf(stderr, "%s:%d: ", file, line);
198+
199+
va_list args;
200+
va_start(args, fmt);
201+
vfprintf(stderr, fmt, args);
202+
va_end(args);
203+
204+
fprintf(stderr, "\n");
205+
197206
ggml_print_backtrace();
198207
abort();
199208
}

0 commit comments

Comments
 (0)