Skip to content

Commit cdc02b7

Browse files
committed
GGML_ASSERT(false) -> GGML_ABORT("fatal error")
1 parent 5fd4cef commit cdc02b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+358
-358
lines changed

examples/eval-callback/eval-callback.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void ggml_print_tensor(uint8_t * data, ggml_type type, const int64_t * ne
6262
} else if (type == GGML_TYPE_I8) {
6363
v = (float) *(int8_t *) &data[i];
6464
} else {
65-
GGML_ASSERT(false);
65+
GGML_ABORT("fatal error");
6666
}
6767
printf("%12.4f", v);
6868
sum += v;

examples/imatrix/imatrix.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
127127
}
128128
else if (e.values.size() != (size_t)src1->ne[0]*n_as) {
129129
fprintf(stderr, "Oops: inconsistent size for %s (%d vs %d)\n", wname.c_str(), (int)e.values.size(), (int)src1->ne[0]*n_as);
130-
exit(1); //GGML_ASSERT(false);
130+
exit(1); //GGML_ABORT("fatal error");
131131
}
132132
if (m_params.verbosity > 1) {
133133
printf("%s[%d]: %32s, %s, %5d x %5d, %d\n", __func__, m_last_call, wname.c_str(), ggml_op_name(t->op), (int)src1->ne[0], (int)src1->ne[2], (int)src1->type);
@@ -176,7 +176,7 @@ bool IMatrixCollector::collect_imatrix(struct ggml_tensor * t, bool ask, void *
176176
}
177177
else if (e.values.size() != (size_t)src1->ne[0]) {
178178
fprintf(stderr, "Oops: inconsistent size for %s (%d vs %d)\n", wname.c_str(), (int)e.values.size(), (int)src1->ne[0]);
179-
exit(1); //GGML_ASSERT(false);
179+
exit(1); //GGML_ABORT("fatal error");
180180
}
181181
++e.ncall;
182182
if (m_params.verbosity > 1) {

examples/llama-bench/llama-bench.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static const char * output_format_str(output_formats format) {
150150
case JSON: return "json";
151151
case MARKDOWN: return "md";
152152
case SQL: return "sql";
153-
default: GGML_ASSERT(!"invalid output format");
153+
default: GGML_ABORT("invalid output format");
154154
}
155155
}
156156

@@ -176,7 +176,7 @@ static const char * split_mode_str(llama_split_mode mode) {
176176
case LLAMA_SPLIT_MODE_NONE: return "none";
177177
case LLAMA_SPLIT_MODE_LAYER: return "layer";
178178
case LLAMA_SPLIT_MODE_ROW: return "row";
179-
default: GGML_ASSERT(!"invalid split mode");
179+
default: GGML_ABORT("invalid split mode");
180180
}
181181
}
182182

@@ -1326,7 +1326,7 @@ static std::unique_ptr<printer> create_printer(output_formats format) {
13261326
case SQL:
13271327
return std::unique_ptr<printer>(new sql_printer());
13281328
}
1329-
GGML_ASSERT(false);
1329+
GGML_ABORT("fatal error");
13301330
}
13311331

13321332
int main(int argc, char ** argv) {

examples/llava/clip.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ static ggml_cgraph * clip_image_build_graph(clip_ctx * ctx, const clip_image_f32
869869
embeddings = peg_0;
870870
}
871871
else {
872-
GGML_ASSERT(false);
872+
GGML_ABORT("fatal error");
873873
}
874874
}
875875

examples/tokenize/tokenize.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static void write_utf8_cstr_to_stdout(const char * str, bool & invalid_utf8) {
163163
printf(">");
164164
return;
165165
}
166-
GGML_ASSERT(false && "MultiByteToWideChar() failed in an unexpected way.");
166+
GGML_ABORT("MultiByteToWideChar() failed in an unexpected way.");
167167
}
168168

169169
LPWSTR wstr = (LPWSTR) calloc(length_needed+1, sizeof(*wstr));

ggml/include/ggml.h

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

275-
#define GGML_ASSERT(x) if (!(x)) ggml_abort(__FILE__, __LINE__, #x)
275+
#define GGML_ABORT(x) ggml_abort(__FILE__, __LINE__, x)
276+
#define GGML_ASSERT(x) if (!(x)) GGML_ABORT(#x)
276277

277278
// used to copy the number of elements and stride in bytes of tensors into local variables.
278279
// main purpose is to reduce code duplication and improve readability.
@@ -322,7 +323,7 @@
322323
extern "C" {
323324
#endif
324325

325-
GGML_API GGML_NORETURN void ggml_abort(const char * file, int line, const char * expr);
326+
GGML_NORETURN GGML_API void ggml_abort(const char * file, int line, const char * expr);
326327

327328
enum ggml_status {
328329
GGML_STATUS_ALLOC_FAILED = -2,

ggml/src/ggml-alloc.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void ggml_tallocr_alloc(struct ggml_tallocr * talloc, struct ggml_tensor * tenso
9191
if (talloc->offset + size > ggml_backend_buffer_get_size(talloc->buffer)) {
9292
fprintf(stderr, "%s: not enough space in the buffer to allocate %s (needed %zu, available %zu)\n",
9393
__func__, tensor->name, size, ggml_backend_buffer_get_size(talloc->buffer) - talloc->offset);
94-
GGML_ASSERT(!"not enough space in the buffer");
94+
GGML_ABORT("not enough space in the buffer");
9595
}
9696

9797
void * addr = (char *)ggml_backend_buffer_get_base(talloc->buffer) + talloc->offset;
@@ -132,7 +132,7 @@ static void add_allocated_tensor(struct ggml_dyn_tallocr * alloc, size_t offset,
132132
return;
133133
}
134134
}
135-
GGML_ASSERT(!"out of allocated_tensors");
135+
GGML_ABORT("out of allocated_tensors");
136136
}
137137
static void remove_allocated_tensor(struct ggml_dyn_tallocr * alloc, size_t offset, const struct ggml_tensor * tensor) {
138138
for (int i = 0; i < 1024; i++) {
@@ -142,7 +142,7 @@ static void remove_allocated_tensor(struct ggml_dyn_tallocr * alloc, size_t offs
142142
}
143143
}
144144
fprintf(stderr, "tried to free tensor %s not found\n", tensor->name);
145-
GGML_ASSERT(!"tensor not found");
145+
GGML_ABORT("tensor not found");
146146
}
147147
#endif
148148

@@ -175,8 +175,7 @@ static size_t ggml_dyn_tallocr_alloc(struct ggml_dyn_tallocr * alloc, size_t siz
175175
// this should never happen
176176
fprintf(stderr, "%s: not enough space in the buffer to allocate %zu bytes, largest block available %zu bytes\n",
177177
__func__, size, max_avail);
178-
GGML_ASSERT(!"not enough space in the buffer");
179-
GGML_UNREACHABLE();
178+
GGML_ABORT("not enough space in the buffer");
180179
}
181180
}
182181

ggml/src/ggml-backend.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ static void ggml_backend_sched_split_graph(ggml_backend_sched_t sched, struct gg
12801280
sched->ctx = ggml_init(params);
12811281
if (sched->ctx == NULL) {
12821282
fprintf(stderr, "%s: failed to initialize context\n", __func__);
1283-
GGML_ASSERT(false);
1283+
GGML_ABORT("fatal error");
12841284
}
12851285

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

ggml/src/ggml-blas.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ GGML_CALL static enum ggml_status ggml_backend_blas_graph_compute(ggml_backend_t
276276

277277
default:
278278
fprintf(stderr, "%s: unsupported op %s\n", __func__, ggml_op_desc(node));
279-
GGML_ASSERT(false);
279+
GGML_ABORT("fatal error");
280280
}
281281
}
282282

ggml/src/ggml-cann.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static void ggml_cann_log(enum ggml_log_level level, const char* format, ...) {
120120
file, line);
121121
GGML_CANN_LOG_ERROR(" %s\n", stmt);
122122
// abort with GGML_ASSERT to get a stack trace
123-
GGML_ASSERT(!"CANN error");
123+
GGML_ABORT("CANN error");
124124
}
125125

126126
/**
@@ -342,7 +342,7 @@ struct ggml_cann_pool_leg : public ggml_cann_pool {
342342
// memory should always buffered. these memory may still needed by
343343
// tasks in stream.
344344
// TODO, fix me.
345-
GGML_ASSERT(!"Cann buffer pool full, increase MAX_CANN_BUFFERS\n");
345+
GGML_ABORT("Cann buffer pool full, increase MAX_CANN_BUFFERS\n");
346346
}
347347
};
348348

@@ -1874,7 +1874,7 @@ static void ggml_backend_cann_event_wait(ggml_backend_t backend,
18741874
ACL_CHECK(aclrtStreamWaitEvent(cann_ctx->stream(),
18751875
(aclrtEvent)event->context));
18761876
} else {
1877-
GGML_ASSERT(false);
1877+
GGML_ABORT("fatal error");
18781878
}
18791879
}
18801880

ggml/src/ggml-cann/aclnn_ops.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ void ggml_cann_pool2d(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
844844
ggml_cann_max_pool2d(ctx, dst);
845845
break;
846846
case GGML_OP_POOL_COUNT:
847-
GGML_ASSERT(false);
847+
GGML_ABORT("fatal error");
848848
break;
849849
}
850850
}
@@ -931,9 +931,9 @@ void ggml_cann_dup(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
931931
((ggml_tensor*)dst->extra)->nb);
932932
return;
933933
}
934-
GGML_ASSERT(false);
934+
GGML_ABORT("fatal error");
935935
}
936-
GGML_ASSERT(false);
936+
GGML_ABORT("fatal error");
937937
}
938938
if (dst->type == GGML_TYPE_F32) {
939939
if (ggml_are_same_shape(src, dst)) {
@@ -955,12 +955,12 @@ void ggml_cann_dup(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
955955
((ggml_tensor*)dst->extra)->nb);
956956
return;
957957
}
958-
GGML_ASSERT(false);
958+
GGML_ABORT("fatal error");
959959
}
960-
GGML_ASSERT(false);
960+
GGML_ABORT("fatal error");
961961
}
962962
// TODO
963-
GGML_ASSERT(false);
963+
GGML_ABORT("fatal error");
964964
} else if (src->type == GGML_TYPE_F32) {
965965
// TODO: if (src0->type == dst->type && ne00 == ne0 && nb00 == type_size
966966
// && nb0 == type_size)
@@ -991,10 +991,10 @@ void ggml_cann_dup(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
991991
((ggml_tensor*)dst->extra)->nb);
992992
return;
993993
}
994-
GGML_ASSERT(false);
994+
GGML_ABORT("fatal error");
995995
} else {
996996
// TODO: dst not contiguous
997-
GGML_ASSERT(false);
997+
GGML_ABORT("fatal error");
998998
}
999999
}
10001000
if (dst->type == GGML_TYPE_F16) {
@@ -1017,19 +1017,19 @@ void ggml_cann_dup(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
10171017
((ggml_tensor*)dst->extra)->nb);
10181018
return;
10191019
}
1020-
GGML_ASSERT(false);
1020+
GGML_ABORT("fatal error");
10211021
}
10221022
}
10231023
// TODO
1024-
GGML_ASSERT(false);
1024+
GGML_ABORT("fatal error");
10251025
} else {
10261026
if (ggml_are_same_shape(src, dst)) {
10271027
cann_copy(ctx, acl_src, acl_dst);
10281028
ACL_CHECK(aclDestroyTensor(acl_src));
10291029
ACL_CHECK(aclDestroyTensor(acl_dst));
10301030
return;
10311031
}
1032-
GGML_ASSERT(false);
1032+
GGML_ABORT("fatal error");
10331033
}
10341034
}
10351035

@@ -2219,7 +2219,7 @@ void ggml_cann_get_rows(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
22192219
((ggml_tensor*)dst->extra)->nb);
22202220
break;
22212221
default:
2222-
GGML_ASSERT(false);
2222+
GGML_ABORT("fatal error");
22232223
break;
22242224
}
22252225
}
@@ -2492,7 +2492,7 @@ void ggml_cann_mul_mat(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
24922492
ggml_cann_mul_mat_q8_0(ctx, dst);
24932493
break;
24942494
default:
2495-
GGML_ASSERT(false);
2495+
GGML_ABORT("fatal error");
24962496
break;
24972497
}
24982498
}

ggml/src/ggml-cuda.cu

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void ggml_cuda_error(const char * stmt, const char * func, const char * file, in
9898
GGML_CUDA_LOG_ERROR(" current device: %d, in function %s at %s:%d\n", id, func, file, line);
9999
GGML_CUDA_LOG_ERROR(" %s\n", stmt);
100100
// abort with GGML_ASSERT to get a stack trace
101-
GGML_ASSERT(!"CUDA error");
101+
GGML_ABORT("CUDA error");
102102
}
103103

104104
// this is faster on Windows
@@ -1596,7 +1596,7 @@ static void ggml_cuda_op_mul_mat(
15961596
CUDA_CHECK(ggml_cuda_cpy_tensor_2d(
15971597
src1_ddf_i, src1, i03, i02, src1_col_0, src1_col_0+src1_ncols, stream));
15981598
} else {
1599-
GGML_ASSERT(false);
1599+
GGML_ABORT("fatal error");
16001600
}
16011601

16021602
if (quantize_src1 && !src1_is_contiguous) {
@@ -2945,7 +2945,7 @@ static void ggml_backend_cuda_event_wait(ggml_backend_t backend, ggml_backend_ev
29452945

29462946
CUDA_CHECK(cudaLaunchHostFunc(cuda_ctx->stream(), wait_fn, event));
29472947
#endif
2948-
GGML_ASSERT(false);
2948+
GGML_ABORT("fatal error");
29492949
}
29502950
}
29512951

ggml/src/ggml-cuda/argsort.cu

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void argsort_f32_i32_cuda(const float * x, int * dst, const int ncols, co
8181
} else if (order == GGML_SORT_ORDER_DESC) {
8282
k_argsort_f32_i32<GGML_SORT_ORDER_DESC><<<block_nums, block_dims, shared_mem, stream>>>(x, dst, ncols, ncols_pad);
8383
} else {
84-
GGML_ASSERT(false);
84+
GGML_ABORT("fatal error");
8585
}
8686
}
8787

ggml/src/ggml-cuda/binbcast.cu

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static void ggml_cuda_op_bin_bcast(
259259
} else {
260260
fprintf(stderr, "%s: unsupported types: dst: %s, src0: %s, src1: %s\n", __func__,
261261
ggml_type_name(dst->type), ggml_type_name(src0->type), ggml_type_name(src1->type));
262-
GGML_ASSERT(false);
262+
GGML_ABORT("fatal error");
263263
}
264264
}
265265

ggml/src/ggml-cuda/common.cuh

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static __device__ void no_device_code(
348348
#ifdef __CUDA_ARCH__
349349
#define NO_DEVICE_CODE no_device_code(__FILE__, __LINE__, __FUNCTION__, __CUDA_ARCH__, STRINGIZE(__CUDA_ARCH_LIST__))
350350
#else
351-
#define NO_DEVICE_CODE //GGML_ASSERT(false && "NO_DEVICE_CODE not valid in host code.")
351+
#define NO_DEVICE_CODE //GGML_ABORT("NO_DEVICE_CODE not valid in host code.")
352352
#endif // __CUDA_ARCH__
353353

354354
static __device__ __forceinline__ float warp_reduce_sum(float x) {

ggml/src/ggml-cuda/cpy.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ void ggml_cuda_cpy(ggml_backend_cuda_context & ctx, const ggml_tensor * src0, gg
451451
} else {
452452
fprintf(stderr, "%s: unsupported type combination (%s to %s)\n", __func__,
453453
ggml_type_name(src0->type), ggml_type_name(src1->type));
454-
GGML_ASSERT(false);
454+
GGML_ABORT("fatal error");
455455
}
456456
}
457457

@@ -484,6 +484,6 @@ void* ggml_cuda_cpy_fn(const ggml_tensor * src0, ggml_tensor * src1) {
484484
} else {
485485
fprintf(stderr, "%s: unsupported type combination (%s to %s)\n", __func__,
486486
ggml_type_name(src0->type), ggml_type_name(src1->type));
487-
GGML_ASSERT(false);
487+
GGML_ABORT("fatal error");
488488
}
489489
}

ggml/src/ggml-cuda/dmmv.cu

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ void ggml_cuda_op_dequantize_mul_mat_vec(
662662
convert_mul_mat_vec_f16_cuda(src0_dd_i, src1_dfloat, dst_dd_i, ne00, row_diff, stream);
663663
break;
664664
default:
665-
GGML_ASSERT(false);
665+
GGML_ABORT("fatal error");
666666
break;
667667
}
668668

ggml/src/ggml-cuda/fattn-common.cuh

+3-3
Original file line numberDiff line numberDiff line change
@@ -564,19 +564,19 @@ static void on_no_fattn_vec_case(const int D) {
564564
fprintf(stderr, "Unsupported KV type combination for head_size 64.\n");
565565
fprintf(stderr, "By default only f16 KV cache is supported.\n");
566566
fprintf(stderr, "Compile with GGML_CUDA_FA_ALL_QUANTS for V cache quantization support.\n");
567-
GGML_ASSERT(false);
567+
GGML_ABORT("fatal error");
568568
} else if (D == 128) {
569569
fprintf(stderr, "Unsupported KV type combination for head_size 128.\n");
570570
fprintf(stderr, "Supported combinations:\n");
571571
fprintf(stderr, " - K == q4_0, V == q4_0, 4.50 BPV\n");
572572
fprintf(stderr, " - K == q8_0, V == q8_0, 8.50 BPV\n");
573573
fprintf(stderr, " - K == f16, V == f16, 16.00 BPV\n");
574574
fprintf(stderr, "Compile with GGML_CUDA_FA_ALL_QUANTS for all combinations of q4_0, q4_1, q5_0, q5_1, q8_0, and f16.\n");
575-
GGML_ASSERT(false);
575+
GGML_ABORT("fatal error");
576576
} else {
577577
fprintf(stderr, "Unsupported KV type combination for head_size 256.\n");
578578
fprintf(stderr, "Only f16 is supported.\n");
579-
GGML_ASSERT(false);
579+
GGML_ABORT("fatal error");
580580
}
581581
}
582582

ggml/src/ggml-cuda/fattn-tile-f16.cu

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void launch_fattn_tile_f16_64_128(ggml_backend_cuda_context & ctx, ggml_tensor *
287287
launch_fattn<D, parallel_blocks>(ctx, dst, fattn_kernel, nwarps, cols_per_block, true, true);
288288
} break;
289289
default: {
290-
GGML_ASSERT(false && "FlashAttention without tensor cores only supports head sizes 64 and 128.");
290+
GGML_ABORT("FlashAttention without tensor cores only supports head sizes 64 and 128.");
291291
} break;
292292
}
293293
}

ggml/src/ggml-cuda/fattn-tile-f32.cu

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void launch_fattn_tile_f32_64_128(ggml_backend_cuda_context & ctx, ggml_tensor *
284284
launch_fattn<D, parallel_blocks>(ctx, dst, fattn_kernel, nwarps, cols_per_block, true, true);
285285
} break;
286286
default: {
287-
GGML_ASSERT(false && "FlashAttention without tensor cores only supports head sizes 64 and 128.");
287+
GGML_ABORT("FlashAttention without tensor cores only supports head sizes 64 and 128.");
288288
} break;
289289
}
290290
}

0 commit comments

Comments
 (0)