Skip to content

Commit

Permalink
GGML_ABORT use format string
Browse files Browse the repository at this point in the history
ggml-ci
  • Loading branch information
slaren committed Jul 27, 2024
1 parent cdc02b7 commit 8ccf979
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
7 changes: 4 additions & 3 deletions ggml/include/ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions ggml/src/ggml-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions ggml/src/ggml-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions ggml/src/ggml-blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
3 changes: 1 addition & 2 deletions ggml/src/ggml-cuda/getrows.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
13 changes: 11 additions & 2 deletions ggml/src/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 8ccf979

Please sign in to comment.