GGML_ABORT use format string

ggml-ci
This commit is contained in:
slaren 2024-07-27 02:23:44 +02:00
parent 3ed1bc09f5
commit ae5331d0cf
6 changed files with 19 additions and 13 deletions

View file

@ -272,8 +272,8 @@
#define GGML_NORETURN _Noreturn
#endif
#define GGML_ABORT(x) ggml_abort(__FILE__, __LINE__, x)
#define GGML_ASSERT(x) if (!(x)) GGML_ABORT(#x)
#define GGML_ABORT(...) ggml_abort(__FILE__, __LINE__, __VA_ARGS__)
#define GGML_ASSERT(x) if (!(x)) GGML_ABORT("GGML_ASSERT(%s) failed", #x)
// used to copy the number of elements and stride in bytes of tensors into local variables.
// main purpose is to reduce code duplication and improve readability.
@ -323,7 +323,8 @@
extern "C" {
#endif
GGML_NORETURN GGML_API void ggml_abort(const char * file, int line, const char * expr);
GGML_NORETURN GGML_ATTRIBUTE_FORMAT(3, 4)
GGML_API void ggml_abort(const char * file, int line, const char * fmt, ...);
enum ggml_status {
GGML_STATUS_ALLOC_FAILED = -2,

View file

@ -141,8 +141,7 @@ static void remove_allocated_tensor(struct ggml_dyn_tallocr * alloc, size_t offs
return;
}
}
fprintf(stderr, "tried to free tensor %s not found\n", tensor->name);
GGML_ABORT("tensor not found");
GGML_ABORT("tried to free tensor %s not found\n", tensor->name);
}
#endif

View file

@ -1279,8 +1279,7 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg
sched->ctx = ggml_init(params);
if (sched->ctx == NULL) {
fprintf(stderr, "%s: failed to initialize context\n", __func__);
GGML_ABORT("fatal error");
GGML_ABORT("%s: failed to initialize context\n", __func__);
}
// pass 1: assign backends to ops with pre-allocated inputs

View file

@ -275,8 +275,7 @@ GGML_CALL static enum ggml_status ggml_backend_blas_graph_compute(ggml_backend_t
break;
default:
fprintf(stderr, "%s: unsupported op %s\n", __func__, ggml_op_desc(node));
GGML_ABORT("fatal error");
GGML_ABORT("%s: unsupported op %s\n", __func__, ggml_op_desc(node));
}
}

View file

@ -171,8 +171,7 @@ void ggml_cuda_op_get_rows(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
break;
default:
// TODO: k-quants
fprintf(stderr, "%s: unsupported type: %s\n", __func__, ggml_type_name(src0->type));
GGML_ABORT("fatal error");
GGML_ABORT("%s: unsupported type: %s\n", __func__, ggml_type_name(src0->type));
break;
}
}

View file

@ -191,9 +191,18 @@ static void ggml_print_backtrace(void) {
}
#endif
void ggml_abort(const char * file, int line, const char * expr) {
void ggml_abort(const char * file, int line, const char * fmt, ...) {
fflush(stdout);
fprintf(stderr, "GGML_ASSERT: %s:%d: %s\n", file, line, expr);
fprintf(stderr, "%s:%d: ", file, line);
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
ggml_print_backtrace();
abort();
}