5
5
// source code
6
6
7
7
#include < algorithm>
8
+ #include < array>
8
9
#include < chrono>
9
10
#include < cmath>
10
11
#include < cstring>
@@ -27,6 +28,7 @@ unsigned int deviceIndex = 0;
27
28
bool use_float = false ;
28
29
bool output_as_csv = false ;
29
30
Unit unit = MegaByte;
31
+ bool silence_errors = false ;
30
32
std::string csv_separator = " ," ;
31
33
32
34
// Benchmarks:
@@ -243,7 +245,7 @@ void run()
243
245
244
246
std::cout
245
247
<< std::left << std::setw (12 ) << " Function"
246
- << std::left << std::setw (12 ) << (string (unit.str ()) + " /s" )
248
+ << std::left << std::setw (12 ) << (std:: string (unit.str ()) + " /s" )
247
249
<< std::left << std::setw (12 ) << " Min (sec)"
248
250
<< std::left << std::setw (12 ) << " Max"
249
251
<< std::left << std::setw (12 ) << " Average"
@@ -307,26 +309,37 @@ void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>
307
309
308
310
long double epsi = std::numeric_limits<T>::epsilon () * 100.0 ;
309
311
310
- if (errA > epsi)
312
+ bool failed = false ;
313
+ if (errA > epsi) {
314
+ failed = true ;
311
315
std::cerr
312
316
<< " Validation failed on a[]. Average error " << errA
313
317
<< std::endl;
314
- if (errB > epsi)
318
+ }
319
+ if (errB > epsi) {
320
+ failed = true ;
315
321
std::cerr
316
322
<< " Validation failed on b[]. Average error " << errB
317
323
<< std::endl;
318
- if (errC > epsi)
324
+ }
325
+ if (errC > epsi) {
326
+ failed = true ;
319
327
std::cerr
320
328
<< " Validation failed on c[]. Average error " << errC
321
329
<< std::endl;
330
+ }
322
331
// Check sum to 8 decimal places
323
- if (selection == Benchmark::All && errSum > 1.0E-8 )
332
+ if (selection == Benchmark::All && errSum > epsi) {
333
+ failed = true ;
324
334
std::cerr
325
335
<< " Validation failed on sum. Error " << errSum
326
336
<< std::endl << std::setprecision (15 )
327
337
<< " Sum was " << sum << " but should be " << goldSum
328
338
<< std::endl;
339
+ }
329
340
341
+ if (failed && !silence_errors)
342
+ std::exit (EXIT_FAILURE);
330
343
}
331
344
332
345
int parseUInt (const char *str, unsigned int *output)
@@ -401,7 +414,7 @@ void parseArguments(int argc, char *argv[])
401
414
std::cerr << " Expected benchmark name after --only" << std::endl;
402
415
exit (EXIT_FAILURE);
403
416
}
404
- auto key = string (argv[i]);
417
+ auto key = std:: string (argv[i]);
405
418
if (key == " Classic" )
406
419
{
407
420
selection = Benchmark::Classic;
@@ -413,7 +426,7 @@ void parseArguments(int argc, char *argv[])
413
426
else
414
427
{
415
428
auto p = find_if (labels.begin (), labels.end (), [&](char const * label) {
416
- return string (label) == key;
429
+ return std:: string (label) == key;
417
430
});
418
431
if (p == labels.end ()) {
419
432
std::cerr << " Unknown benchmark name \" " << argv[i] << " \" after --only" << std::endl;
@@ -433,18 +446,22 @@ void parseArguments(int argc, char *argv[])
433
446
{
434
447
unit = Unit (MibiByte);
435
448
}
436
- else if (!string (" --megabytes" ).compare (argv[i]))
449
+ else if (!std:: string (" --megabytes" ).compare (argv[i]))
437
450
{
438
451
unit = Unit (MegaByte);
439
452
}
440
- else if (!string (" --gibibytes" ).compare (argv[i]))
453
+ else if (!std:: string (" --gibibytes" ).compare (argv[i]))
441
454
{
442
455
unit = Unit (GibiByte);
443
456
}
444
- else if (!string (" --gigabytes" ).compare (argv[i]))
457
+ else if (!std:: string (" --gigabytes" ).compare (argv[i]))
445
458
{
446
459
unit = Unit (GigaByte);
447
460
}
461
+ else if (!std::string (" --silence-errors" ).compare (argv[i]))
462
+ {
463
+ silence_errors = true ;
464
+ }
448
465
else if (!std::string (" --help" ).compare (argv[i]) ||
449
466
!std::string (" -h" ).compare (argv[i]))
450
467
{
@@ -464,13 +481,14 @@ void parseArguments(int argc, char *argv[])
464
481
std::cout << " --mibibytes Use MiB=2^20 for bandwidth calculation (default MB=10^6)" << std::endl;
465
482
std::cout << " --gigibytes Use GiB=2^30 for bandwidth calculation (default MB=10^6)" << std::endl;
466
483
std::cout << " --gigabytes Use GB=10^9 for bandwidth calculation (default MB=10^6)" << std::endl;
484
+ std::cout << " --silence-errors Ignores validation errors." << std::endl;
467
485
std::cout << std::endl;
468
486
std::exit (EXIT_SUCCESS);
469
487
}
470
488
else
471
489
{
472
490
std::cerr << " Unrecognized argument '" << argv[i] << " ' (try '--help')"
473
- << std::std:: endl;
491
+ << std::endl;
474
492
std::exit (EXIT_FAILURE);
475
493
}
476
494
}
0 commit comments