@@ -451,20 +451,20 @@ struct test_result {
451
451
};
452
452
453
453
// Printer classes for different output formats
454
+ enum class message_type {
455
+ INFO,
456
+ ERROR,
457
+ STATUS_OK,
458
+ STATUS_FAIL
459
+ };
460
+
454
461
struct printer {
455
462
virtual ~printer () {}
456
463
FILE * fout = stdout;
457
464
virtual void print_header () {}
458
465
virtual void print_test_result (const test_result & result) = 0;
459
466
virtual void print_footer () {}
460
-
461
- // General purpose output methods
462
- virtual void print_info (const char * format, ...) = 0;
463
- virtual void print_error (const char * format, ...) = 0;
464
- virtual void print_device_info (const char * format, ...) = 0;
465
- virtual void print_test_summary (const char * format, ...) = 0;
466
- virtual void print_status_ok () = 0;
467
- virtual void print_status_fail () = 0;
467
+ virtual void print_message (message_type type, const char * format, ...) = 0;
468
468
};
469
469
470
470
struct console_printer : public printer {
@@ -476,42 +476,28 @@ struct console_printer : public printer {
476
476
}
477
477
}
478
478
479
- void print_info (const char * format, ...) override {
480
- va_list args;
481
- va_start (args, format);
482
- vprintf (format, args);
483
- va_end (args);
484
- }
485
-
486
- void print_error (const char * format, ...) override {
479
+ void print_message (message_type type, const char * format, ...) override {
487
480
va_list args;
488
481
va_start (args, format);
489
- vfprintf (stderr, format, args);
490
- va_end (args);
491
- }
492
482
493
- void print_device_info (const char * format, ...) override {
494
- va_list args;
495
- va_start (args, format);
496
- vprintf (format, args);
497
- va_end (args);
498
- }
483
+ switch (type) {
484
+ case message_type::INFO:
485
+ vprintf (format, args);
486
+ break ;
487
+ case message_type::ERROR:
488
+ vfprintf (stderr, format, args);
489
+ break ;
490
+ case message_type::STATUS_OK:
491
+ printf (" \033 [1;32mOK\033 [0m\n " );
492
+ break ;
493
+ case message_type::STATUS_FAIL:
494
+ printf (" \033 [1;31mFAIL\033 [0m\n " );
495
+ break ;
496
+ }
499
497
500
- void print_test_summary (const char * format, ...) override {
501
- va_list args;
502
- va_start (args, format);
503
- vprintf (format, args);
504
498
va_end (args);
505
499
}
506
500
507
- void print_status_ok () override {
508
- printf (" \033 [1;32mOK\033 [0m\n " );
509
- }
510
-
511
- void print_status_fail () override {
512
- printf (" \033 [1;31mFAIL\033 [0m\n " );
513
- }
514
-
515
501
private:
516
502
void print_test_console (const test_result & result) {
517
503
printf (" %s(%s): " , result.op_name .c_str (), result.op_params .c_str ());
@@ -617,32 +603,16 @@ struct sql_printer : public printer {
617
603
fprintf (fout, " );\n " );
618
604
}
619
605
620
- // SQL printer ignores general output - only outputs test results
621
- void print_info (const char * format, ...) override {
622
- // Do nothing - SQL format only outputs test results
623
- (void )format;
624
- }
625
-
626
- void print_error (const char * format, ...) override {
627
- // Still output errors to stderr for SQL format
628
- va_list args;
629
- va_start (args, format);
630
- vfprintf (stderr, format, args);
631
- va_end (args);
632
- }
633
-
634
- void print_device_info (const char * format, ...) override {
635
- (void )format;
636
- }
637
-
638
- void print_test_summary (const char * format, ...) override {
639
- (void )format;
640
- }
641
-
642
- void print_status_ok () override {
643
- }
644
-
645
- void print_status_fail () override {
606
+ // SQL printer ignores most output types - only outputs test results and errors
607
+ void print_message (message_type type, const char * format, ...) override {
608
+ if (type == message_type::ERROR) {
609
+ // Still output errors to stderr for SQL format
610
+ va_list args;
611
+ va_start (args, format);
612
+ vfprintf (stderr, format, args);
613
+ va_end (args);
614
+ }
615
+ // All other message types are ignored in SQL format
646
616
}
647
617
};
648
618
@@ -1089,14 +1059,14 @@ struct test_case {
1089
1059
ggml_tensor * out = build_graph (ctx.get ());
1090
1060
1091
1061
if ((op_name != nullptr && op_desc (out) != op_name) || out->op == GGML_OP_OPT_STEP_ADAMW) {
1092
- // output_printer->print_info( " %s: skipping\n", op_desc(out).c_str());
1062
+ // output_printer->print_message(message_type::INFO, " %s: skipping\n", op_desc(out).c_str());
1093
1063
return true ;
1094
1064
}
1095
1065
1096
- output_printer->print_info ( " %s(%s): " , op_desc (out).c_str (), vars ().c_str ());
1066
+ output_printer->print_message (message_type::INFO, " %s(%s): " , op_desc (out).c_str (), vars ().c_str ());
1097
1067
1098
1068
if (out->type != GGML_TYPE_F32) {
1099
- output_printer->print_info ( " not supported [%s->type != FP32]\n " , out->name );
1069
+ output_printer->print_message (message_type::INFO, " not supported [%s->type != FP32]\n " , out->name );
1100
1070
return true ;
1101
1071
}
1102
1072
@@ -1105,25 +1075,25 @@ struct test_case {
1105
1075
bool any_params = false ;
1106
1076
for (ggml_tensor * t = ggml_get_first_tensor (ctx.get ()); t != NULL ; t = ggml_get_next_tensor (ctx.get (), t)) {
1107
1077
if (!ggml_backend_supports_op (backend, t)) {
1108
- output_printer->print_info ( " not supported [%s] " , ggml_backend_name (backend));
1078
+ output_printer->print_message (message_type::INFO, " not supported [%s] " , ggml_backend_name (backend));
1109
1079
supported = false ;
1110
1080
break ;
1111
1081
}
1112
1082
if ((t->flags & GGML_TENSOR_FLAG_PARAM)) {
1113
1083
any_params = true ;
1114
1084
if (t->type != GGML_TYPE_F32) {
1115
- output_printer->print_info ( " not supported [%s->type != FP32] " , t->name );
1085
+ output_printer->print_message (message_type::INFO, " not supported [%s->type != FP32] " , t->name );
1116
1086
supported = false ;
1117
1087
break ;
1118
1088
}
1119
1089
}
1120
1090
}
1121
1091
if (!any_params) {
1122
- output_printer->print_info ( " not supported [%s] \n " , op_desc (out).c_str ());
1092
+ output_printer->print_message (message_type::INFO, " not supported [%s] \n " , op_desc (out).c_str ());
1123
1093
supported = false ;
1124
1094
}
1125
1095
if (!supported) {
1126
- output_printer->print_info ( " \n " );
1096
+ output_printer->print_message (message_type::INFO, " \n " );
1127
1097
return true ;
1128
1098
}
1129
1099
@@ -1134,7 +1104,7 @@ struct test_case {
1134
1104
}
1135
1105
}
1136
1106
if (ngrads > grad_nmax ()) {
1137
- output_printer->print_info ( " skipping large tensors for speed \n " );
1107
+ output_printer->print_message (message_type::INFO, " skipping large tensors for speed \n " );
1138
1108
return true ;
1139
1109
}
1140
1110
@@ -1157,25 +1127,25 @@ struct test_case {
1157
1127
1158
1128
for (ggml_tensor * t = ggml_get_first_tensor (ctx.get ()); t != NULL ; t = ggml_get_next_tensor (ctx.get (), t)) {
1159
1129
if (!ggml_backend_supports_op (backend, t)) {
1160
- output_printer->print_info ( " not supported [%s] " , ggml_backend_name (backend));
1130
+ output_printer->print_message (message_type::INFO, " not supported [%s] " , ggml_backend_name (backend));
1161
1131
supported = false ;
1162
1132
break ;
1163
1133
}
1164
1134
if ((t->flags & GGML_TENSOR_FLAG_PARAM) && t->type != GGML_TYPE_F32) {
1165
- output_printer->print_info ( " not supported [%s->type != FP32] " , t->name );
1135
+ output_printer->print_message (message_type::INFO, " not supported [%s->type != FP32] " , t->name );
1166
1136
supported = false ;
1167
1137
break ;
1168
1138
}
1169
1139
}
1170
1140
if (!supported) {
1171
- output_printer->print_info ( " \n " );
1141
+ output_printer->print_message (message_type::INFO, " \n " );
1172
1142
return true ;
1173
1143
}
1174
1144
1175
1145
// allocate
1176
1146
ggml_backend_buffer_ptr buf (ggml_backend_alloc_ctx_tensors (ctx.get (), backend)); // smart ptr
1177
1147
if (buf == NULL ) {
1178
- output_printer->print_error ( " failed to allocate tensors [%s] " , ggml_backend_name (backend));
1148
+ output_printer->print_message (message_type::ERROR, " failed to allocate tensors [%s] " , ggml_backend_name (backend));
1179
1149
return false ;
1180
1150
}
1181
1151
@@ -1213,7 +1183,7 @@ struct test_case {
1213
1183
for (int64_t i = 0 ; i < ne; ++i) { // gradient algebraic
1214
1184
// check for nans
1215
1185
if (!std::isfinite (ga[i])) {
1216
- output_printer->print_info ( " [%s] nonfinite gradient at index %" PRId64 " (%s=%f) " , ggml_op_desc (t), i, bn, ga[i]);
1186
+ output_printer->print_message (message_type::INFO, " [%s] nonfinite gradient at index %" PRId64 " (%s=%f) " , ggml_op_desc (t), i, bn, ga[i]);
1217
1187
ok = false ;
1218
1188
break ;
1219
1189
}
@@ -1281,7 +1251,7 @@ struct test_case {
1281
1251
1282
1252
const double err = mean_abs_asymm (gn.data (), ga.data (), gn.size (), expect);
1283
1253
if (err > max_maa_err ()) {
1284
- output_printer->print_info ( " [%s] MAA = %.9f > %.9f " , ggml_op_desc (t), err, max_maa_err ());
1254
+ output_printer->print_message (message_type::INFO, " [%s] MAA = %.9f > %.9f " , ggml_op_desc (t), err, max_maa_err ());
1285
1255
ok = false ;
1286
1256
break ;
1287
1257
}
@@ -1291,15 +1261,15 @@ struct test_case {
1291
1261
}
1292
1262
1293
1263
if (!ok) {
1294
- output_printer->print_info ( " compare failed " );
1264
+ output_printer->print_message (message_type::INFO, " compare failed " );
1295
1265
}
1296
1266
1297
1267
if (ok) {
1298
- output_printer->print_status_ok ( );
1268
+ output_printer->print_message (message_type::STATUS_OK, " " );
1299
1269
return true ;
1300
1270
}
1301
1271
1302
- output_printer->print_status_fail ( );
1272
+ output_printer->print_message (message_type::STATUS_FAIL, " " );
1303
1273
return false ;
1304
1274
}
1305
1275
};
@@ -5330,7 +5300,7 @@ static bool test_backend(ggml_backend_t backend, test_mode mode, const char * op
5330
5300
filter_test_cases (test_cases, params_filter);
5331
5301
ggml_backend_t backend_cpu = ggml_backend_init_by_type (GGML_BACKEND_DEVICE_TYPE_CPU, NULL );
5332
5302
if (backend_cpu == NULL ) {
5333
- output_printer->print_error ( " Failed to initialize CPU backend\n " );
5303
+ output_printer->print_message (message_type::ERROR, " Failed to initialize CPU backend\n " );
5334
5304
return false ;
5335
5305
}
5336
5306
@@ -5340,7 +5310,7 @@ static bool test_backend(ggml_backend_t backend, test_mode mode, const char * op
5340
5310
n_ok++;
5341
5311
}
5342
5312
}
5343
- output_printer->print_test_summary ( " %zu/%zu tests passed\n " , n_ok, test_cases.size ());
5313
+ output_printer->print_message (message_type::INFO, " %zu/%zu tests passed\n " , n_ok, test_cases.size ());
5344
5314
5345
5315
ggml_backend_free (backend_cpu);
5346
5316
@@ -5356,7 +5326,7 @@ static bool test_backend(ggml_backend_t backend, test_mode mode, const char * op
5356
5326
n_ok++;
5357
5327
}
5358
5328
}
5359
- output_printer->print_test_summary ( " %zu/%zu tests passed\n " , n_ok, test_cases.size ());
5329
+ output_printer->print_message (message_type::INFO, " %zu/%zu tests passed\n " , n_ok, test_cases.size ());
5360
5330
5361
5331
return n_ok == test_cases.size ();
5362
5332
}
@@ -5443,23 +5413,23 @@ int main(int argc, char ** argv) {
5443
5413
output_printer->print_header ();
5444
5414
}
5445
5415
5446
- output_printer->print_info ( " Testing %zu devices\n\n " , ggml_backend_dev_count ());
5416
+ output_printer->print_message (message_type::INFO, " Testing %zu devices\n\n " , ggml_backend_dev_count ());
5447
5417
5448
5418
size_t n_ok = 0 ;
5449
5419
5450
5420
for (size_t i = 0 ; i < ggml_backend_dev_count (); i++) {
5451
5421
ggml_backend_dev_t dev = ggml_backend_dev_get (i);
5452
5422
5453
- output_printer->print_device_info ( " Backend %zu/%zu: %s\n " , i + 1 , ggml_backend_dev_count (), ggml_backend_dev_name (dev));
5423
+ output_printer->print_message (message_type::INFO, " Backend %zu/%zu: %s\n " , i + 1 , ggml_backend_dev_count (), ggml_backend_dev_name (dev));
5454
5424
5455
5425
if (backend_filter != NULL && strcmp (backend_filter, ggml_backend_dev_name (dev)) != 0 ) {
5456
- output_printer->print_device_info ( " Skipping\n " );
5426
+ output_printer->print_message (message_type::INFO, " Skipping\n " );
5457
5427
n_ok++;
5458
5428
continue ;
5459
5429
}
5460
5430
5461
5431
if (backend_filter == NULL && ggml_backend_dev_type (dev) == GGML_BACKEND_DEVICE_TYPE_CPU && mode != MODE_GRAD) {
5462
- output_printer->print_device_info ( " Skipping CPU backend\n " );
5432
+ output_printer->print_message (message_type::INFO, " Skipping CPU backend\n " );
5463
5433
n_ok++;
5464
5434
continue ;
5465
5435
}
@@ -5474,23 +5444,23 @@ int main(int argc, char ** argv) {
5474
5444
ggml_backend_set_n_threads_fn (backend, std::thread::hardware_concurrency ());
5475
5445
}
5476
5446
5477
- output_printer->print_device_info ( " Device description: %s\n " , ggml_backend_dev_description (dev));
5447
+ output_printer->print_message (message_type::INFO, " Device description: %s\n " , ggml_backend_dev_description (dev));
5478
5448
size_t free, total; // NOLINT
5479
5449
ggml_backend_dev_memory (dev, &free, &total);
5480
- output_printer->print_device_info ( " Device memory: %zu MB (%zu MB free)\n " , total / 1024 / 1024 , free / 1024 / 1024 );
5481
- output_printer->print_device_info ( " \n " );
5450
+ output_printer->print_message (message_type::INFO, " Device memory: %zu MB (%zu MB free)\n " , total / 1024 / 1024 , free / 1024 / 1024 );
5451
+ output_printer->print_message (message_type::INFO, " \n " );
5482
5452
5483
5453
bool ok = test_backend (backend, mode, op_name_filter, params_filter, output_printer.get ());
5484
5454
5485
- output_printer->print_device_info ( " Backend %s: " , ggml_backend_name (backend));
5455
+ output_printer->print_message (message_type::INFO, " Backend %s: " , ggml_backend_name (backend));
5486
5456
if (ok) {
5487
- output_printer->print_status_ok ( );
5457
+ output_printer->print_message (message_type::STATUS_OK, " " );
5488
5458
n_ok++;
5489
5459
} else {
5490
- output_printer->print_status_fail ( );
5460
+ output_printer->print_message (message_type::STATUS_FAIL, " " );
5491
5461
}
5492
5462
5493
- output_printer->print_device_info ( " \n " );
5463
+ output_printer->print_message (message_type::INFO, " \n " );
5494
5464
5495
5465
ggml_backend_free (backend);
5496
5466
}
@@ -5501,13 +5471,13 @@ int main(int argc, char ** argv) {
5501
5471
output_printer->print_footer ();
5502
5472
}
5503
5473
5504
- output_printer->print_test_summary ( " %zu/%zu backends passed\n " , n_ok, ggml_backend_dev_count ());
5474
+ output_printer->print_message (message_type::INFO, " %zu/%zu backends passed\n " , n_ok, ggml_backend_dev_count ());
5505
5475
5506
5476
if (n_ok != ggml_backend_dev_count ()) {
5507
- output_printer->print_status_fail ( );
5477
+ output_printer->print_message (message_type::STATUS_FAIL, " " );
5508
5478
return 1 ;
5509
5479
}
5510
5480
5511
- output_printer->print_status_ok ( );
5481
+ output_printer->print_message (message_type::STATUS_OK, " " );
5512
5482
return 0 ;
5513
5483
}
0 commit comments