@@ -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
@@ -1087,14 +1057,14 @@ struct test_case {
1087
1057
ggml_tensor * out = build_graph (ctx.get ());
1088
1058
1089
1059
if ((op_name != nullptr && op_desc (out) != op_name) || out->op == GGML_OP_OPT_STEP_ADAMW) {
1090
- // output_printer->print_info( " %s: skipping\n", op_desc(out).c_str());
1060
+ // output_printer->print_message(message_type::INFO, " %s: skipping\n", op_desc(out).c_str());
1091
1061
return true ;
1092
1062
}
1093
1063
1094
- output_printer->print_info ( " %s(%s): " , op_desc (out).c_str (), vars ().c_str ());
1064
+ output_printer->print_message (message_type::INFO, " %s(%s): " , op_desc (out).c_str (), vars ().c_str ());
1095
1065
1096
1066
if (out->type != GGML_TYPE_F32) {
1097
- output_printer->print_info ( " not supported [%s->type != FP32]\n " , out->name );
1067
+ output_printer->print_message (message_type::INFO, " not supported [%s->type != FP32]\n " , out->name );
1098
1068
return true ;
1099
1069
}
1100
1070
@@ -1103,25 +1073,25 @@ struct test_case {
1103
1073
bool any_params = false ;
1104
1074
for (ggml_tensor * t = ggml_get_first_tensor (ctx.get ()); t != NULL ; t = ggml_get_next_tensor (ctx.get (), t)) {
1105
1075
if (!ggml_backend_supports_op (backend, t)) {
1106
- output_printer->print_info ( " not supported [%s] " , ggml_backend_name (backend));
1076
+ output_printer->print_message (message_type::INFO, " not supported [%s] " , ggml_backend_name (backend));
1107
1077
supported = false ;
1108
1078
break ;
1109
1079
}
1110
1080
if ((t->flags & GGML_TENSOR_FLAG_PARAM)) {
1111
1081
any_params = true ;
1112
1082
if (t->type != GGML_TYPE_F32) {
1113
- output_printer->print_info ( " not supported [%s->type != FP32] " , t->name );
1083
+ output_printer->print_message (message_type::INFO, " not supported [%s->type != FP32] " , t->name );
1114
1084
supported = false ;
1115
1085
break ;
1116
1086
}
1117
1087
}
1118
1088
}
1119
1089
if (!any_params) {
1120
- output_printer->print_info ( " not supported [%s] \n " , op_desc (out).c_str ());
1090
+ output_printer->print_message (message_type::INFO, " not supported [%s] \n " , op_desc (out).c_str ());
1121
1091
supported = false ;
1122
1092
}
1123
1093
if (!supported) {
1124
- output_printer->print_info ( " \n " );
1094
+ output_printer->print_message (message_type::INFO, " \n " );
1125
1095
return true ;
1126
1096
}
1127
1097
@@ -1132,7 +1102,7 @@ struct test_case {
1132
1102
}
1133
1103
}
1134
1104
if (ngrads > grad_nmax ()) {
1135
- output_printer->print_info ( " skipping large tensors for speed \n " );
1105
+ output_printer->print_message (message_type::INFO, " skipping large tensors for speed \n " );
1136
1106
return true ;
1137
1107
}
1138
1108
@@ -1155,25 +1125,25 @@ struct test_case {
1155
1125
1156
1126
for (ggml_tensor * t = ggml_get_first_tensor (ctx.get ()); t != NULL ; t = ggml_get_next_tensor (ctx.get (), t)) {
1157
1127
if (!ggml_backend_supports_op (backend, t)) {
1158
- output_printer->print_info ( " not supported [%s] " , ggml_backend_name (backend));
1128
+ output_printer->print_message (message_type::INFO, " not supported [%s] " , ggml_backend_name (backend));
1159
1129
supported = false ;
1160
1130
break ;
1161
1131
}
1162
1132
if ((t->flags & GGML_TENSOR_FLAG_PARAM) && t->type != GGML_TYPE_F32) {
1163
- output_printer->print_info ( " not supported [%s->type != FP32] " , t->name );
1133
+ output_printer->print_message (message_type::INFO, " not supported [%s->type != FP32] " , t->name );
1164
1134
supported = false ;
1165
1135
break ;
1166
1136
}
1167
1137
}
1168
1138
if (!supported) {
1169
- output_printer->print_info ( " \n " );
1139
+ output_printer->print_message (message_type::INFO, " \n " );
1170
1140
return true ;
1171
1141
}
1172
1142
1173
1143
// allocate
1174
1144
ggml_backend_buffer_ptr buf (ggml_backend_alloc_ctx_tensors (ctx.get (), backend)); // smart ptr
1175
1145
if (buf == NULL ) {
1176
- output_printer->print_error ( " failed to allocate tensors [%s] " , ggml_backend_name (backend));
1146
+ output_printer->print_message (message_type::ERROR, " failed to allocate tensors [%s] " , ggml_backend_name (backend));
1177
1147
return false ;
1178
1148
}
1179
1149
@@ -1211,7 +1181,7 @@ struct test_case {
1211
1181
for (int64_t i = 0 ; i < ne; ++i) { // gradient algebraic
1212
1182
// check for nans
1213
1183
if (!std::isfinite (ga[i])) {
1214
- output_printer->print_info ( " [%s] nonfinite gradient at index %" PRId64 " (%s=%f) " , ggml_op_desc (t), i, bn, ga[i]);
1184
+ output_printer->print_message (message_type::INFO, " [%s] nonfinite gradient at index %" PRId64 " (%s=%f) " , ggml_op_desc (t), i, bn, ga[i]);
1215
1185
ok = false ;
1216
1186
break ;
1217
1187
}
@@ -1279,7 +1249,7 @@ struct test_case {
1279
1249
1280
1250
const double err = mean_abs_asymm (gn.data (), ga.data (), gn.size (), expect);
1281
1251
if (err > max_maa_err ()) {
1282
- output_printer->print_info ( " [%s] MAA = %.9f > %.9f " , ggml_op_desc (t), err, max_maa_err ());
1252
+ output_printer->print_message (message_type::INFO, " [%s] MAA = %.9f > %.9f " , ggml_op_desc (t), err, max_maa_err ());
1283
1253
ok = false ;
1284
1254
break ;
1285
1255
}
@@ -1289,15 +1259,15 @@ struct test_case {
1289
1259
}
1290
1260
1291
1261
if (!ok) {
1292
- output_printer->print_info ( " compare failed " );
1262
+ output_printer->print_message (message_type::INFO, " compare failed " );
1293
1263
}
1294
1264
1295
1265
if (ok) {
1296
- output_printer->print_status_ok ( );
1266
+ output_printer->print_message (message_type::STATUS_OK, " " );
1297
1267
return true ;
1298
1268
}
1299
1269
1300
- output_printer->print_status_fail ( );
1270
+ output_printer->print_message (message_type::STATUS_FAIL, " " );
1301
1271
return false ;
1302
1272
}
1303
1273
};
@@ -5002,7 +4972,7 @@ static bool test_backend(ggml_backend_t backend, test_mode mode, const char * op
5002
4972
filter_test_cases (test_cases, params_filter);
5003
4973
ggml_backend_t backend_cpu = ggml_backend_init_by_type (GGML_BACKEND_DEVICE_TYPE_CPU, NULL );
5004
4974
if (backend_cpu == NULL ) {
5005
- output_printer->print_error ( " Failed to initialize CPU backend\n " );
4975
+ output_printer->print_message (message_type::ERROR, " Failed to initialize CPU backend\n " );
5006
4976
return false ;
5007
4977
}
5008
4978
@@ -5012,7 +4982,7 @@ static bool test_backend(ggml_backend_t backend, test_mode mode, const char * op
5012
4982
n_ok++;
5013
4983
}
5014
4984
}
5015
- output_printer->print_test_summary ( " %zu/%zu tests passed\n " , n_ok, test_cases.size ());
4985
+ output_printer->print_message (message_type::INFO, " %zu/%zu tests passed\n " , n_ok, test_cases.size ());
5016
4986
5017
4987
ggml_backend_free (backend_cpu);
5018
4988
@@ -5028,7 +4998,7 @@ static bool test_backend(ggml_backend_t backend, test_mode mode, const char * op
5028
4998
n_ok++;
5029
4999
}
5030
5000
}
5031
- output_printer->print_test_summary ( " %zu/%zu tests passed\n " , n_ok, test_cases.size ());
5001
+ output_printer->print_message (message_type::INFO, " %zu/%zu tests passed\n " , n_ok, test_cases.size ());
5032
5002
5033
5003
return n_ok == test_cases.size ();
5034
5004
}
@@ -5115,23 +5085,23 @@ int main(int argc, char ** argv) {
5115
5085
output_printer->print_header ();
5116
5086
}
5117
5087
5118
- output_printer->print_info ( " Testing %zu devices\n\n " , ggml_backend_dev_count ());
5088
+ output_printer->print_message (message_type::INFO, " Testing %zu devices\n\n " , ggml_backend_dev_count ());
5119
5089
5120
5090
size_t n_ok = 0 ;
5121
5091
5122
5092
for (size_t i = 0 ; i < ggml_backend_dev_count (); i++) {
5123
5093
ggml_backend_dev_t dev = ggml_backend_dev_get (i);
5124
5094
5125
- output_printer->print_device_info ( " Backend %zu/%zu: %s\n " , i + 1 , ggml_backend_dev_count (), ggml_backend_dev_name (dev));
5095
+ output_printer->print_message (message_type::INFO, " Backend %zu/%zu: %s\n " , i + 1 , ggml_backend_dev_count (), ggml_backend_dev_name (dev));
5126
5096
5127
5097
if (backend_filter != NULL && strcmp (backend_filter, ggml_backend_dev_name (dev)) != 0 ) {
5128
- output_printer->print_device_info ( " Skipping\n " );
5098
+ output_printer->print_message (message_type::INFO, " Skipping\n " );
5129
5099
n_ok++;
5130
5100
continue ;
5131
5101
}
5132
5102
5133
5103
if (backend_filter == NULL && ggml_backend_dev_type (dev) == GGML_BACKEND_DEVICE_TYPE_CPU && mode != MODE_GRAD) {
5134
- output_printer->print_device_info ( " Skipping CPU backend\n " );
5104
+ output_printer->print_message (message_type::INFO, " Skipping CPU backend\n " );
5135
5105
n_ok++;
5136
5106
continue ;
5137
5107
}
@@ -5146,23 +5116,23 @@ int main(int argc, char ** argv) {
5146
5116
ggml_backend_set_n_threads_fn (backend, std::thread::hardware_concurrency ());
5147
5117
}
5148
5118
5149
- output_printer->print_device_info ( " Device description: %s\n " , ggml_backend_dev_description (dev));
5119
+ output_printer->print_message (message_type::INFO, " Device description: %s\n " , ggml_backend_dev_description (dev));
5150
5120
size_t free, total; // NOLINT
5151
5121
ggml_backend_dev_memory (dev, &free, &total);
5152
- output_printer->print_device_info ( " Device memory: %zu MB (%zu MB free)\n " , total / 1024 / 1024 , free / 1024 / 1024 );
5153
- output_printer->print_device_info ( " \n " );
5122
+ output_printer->print_message (message_type::INFO, " Device memory: %zu MB (%zu MB free)\n " , total / 1024 / 1024 , free / 1024 / 1024 );
5123
+ output_printer->print_message (message_type::INFO, " \n " );
5154
5124
5155
5125
bool ok = test_backend (backend, mode, op_name_filter, params_filter, output_printer.get ());
5156
5126
5157
- output_printer->print_device_info ( " Backend %s: " , ggml_backend_name (backend));
5127
+ output_printer->print_message (message_type::INFO, " Backend %s: " , ggml_backend_name (backend));
5158
5128
if (ok) {
5159
- output_printer->print_status_ok ( );
5129
+ output_printer->print_message (message_type::STATUS_OK, " " );
5160
5130
n_ok++;
5161
5131
} else {
5162
- output_printer->print_status_fail ( );
5132
+ output_printer->print_message (message_type::STATUS_FAIL, " " );
5163
5133
}
5164
5134
5165
- output_printer->print_device_info ( " \n " );
5135
+ output_printer->print_message (message_type::INFO, " \n " );
5166
5136
5167
5137
ggml_backend_free (backend);
5168
5138
}
@@ -5173,13 +5143,13 @@ int main(int argc, char ** argv) {
5173
5143
output_printer->print_footer ();
5174
5144
}
5175
5145
5176
- output_printer->print_test_summary ( " %zu/%zu backends passed\n " , n_ok, ggml_backend_dev_count ());
5146
+ output_printer->print_message (message_type::INFO, " %zu/%zu backends passed\n " , n_ok, ggml_backend_dev_count ());
5177
5147
5178
5148
if (n_ok != ggml_backend_dev_count ()) {
5179
- output_printer->print_status_fail ( );
5149
+ output_printer->print_message (message_type::STATUS_FAIL, " " );
5180
5150
return 1 ;
5181
5151
}
5182
5152
5183
- output_printer->print_status_ok ( );
5153
+ output_printer->print_message (message_type::STATUS_OK, " " );
5184
5154
return 0 ;
5185
5155
}
0 commit comments