Add a --mibibytes flag to output bandwidth and array sizes in base 2

This sets MiB = 2^20, GiB = 2^30 rather than the default of
MB = 10^6 and GB = 10^9.
This commit is contained in:
Tom Deakin 2019-04-09 09:50:44 +01:00
parent db2a4c40d8
commit 5a1396671e

102
main.cpp
View File

@ -46,6 +46,7 @@ unsigned int deviceIndex = 0;
bool use_float = false; bool use_float = false;
bool triad_only = false; bool triad_only = false;
bool output_as_csv = false; bool output_as_csv = false;
bool mibibytes = false;
std::string csv_separator = ","; std::string csv_separator = ",";
template <typename T> template <typename T>
@ -105,11 +106,24 @@ void run()
std::cout << "Precision: double" << std::endl; std::cout << "Precision: double" << std::endl;
std::cout << std::setprecision(1) << std::fixed if (mibibytes)
<< "Array size: " << ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB" {
<< " (=" << ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl; // MiB = 2^20
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB" std::cout << std::setprecision(1) << std::fixed
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl; << "Array size: " << ARRAY_SIZE*sizeof(T)*pow(2.0, -20.0) << " MiB"
<< " (=" << ARRAY_SIZE*sizeof(T)*pow(2.0, -30.0) << " GiB)" << std::endl;
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*pow(2.0, -20.0) << " MiB"
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*pow(2.0, -30.0) << " GiB)" << std::endl;
}
else
{
// MB = 10^6
std::cout << std::setprecision(1) << std::fixed
<< "Array size: " << ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB"
<< " (=" << ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl;
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB"
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl;
}
std::cout.precision(ss); std::cout.precision(ss);
} }
@ -210,23 +224,35 @@ void run()
check_solution<T>(num_times, a, b, c, sum); check_solution<T>(num_times, a, b, c, sum);
// Display timing results // Display timing results
std::string units;
if (output_as_csv) if (output_as_csv)
{ {
if (mibibytes)
units = "max_mibytes_per_sec";
else
units = "max_mbytes_per_sec";
std::cout std::cout
<< "function" << csv_separator << "function" << csv_separator
<< "num_times" << csv_separator << "num_times" << csv_separator
<< "n_elements" << csv_separator << "n_elements" << csv_separator
<< "sizeof" << csv_separator << "sizeof" << csv_separator
<< "max_mbytes_per_sec" << csv_separator << units << csv_separator
<< "min_runtime" << csv_separator << "min_runtime" << csv_separator
<< "max_runtime" << csv_separator << "max_runtime" << csv_separator
<< "avg_runtime" << std::endl; << "avg_runtime" << std::endl;
} }
else else
{ {
if (mibibytes)
units = "MiBytes/sec";
else
units = "MBytes/sec";
std::cout std::cout
<< std::left << std::setw(12) << "Function" << std::left << std::setw(12) << "Function"
<< std::left << std::setw(12) << "MBytes/sec" << std::left << std::setw(12) << units
<< std::left << std::setw(12) << "Min (sec)" << std::left << std::setw(12) << "Min (sec)"
<< std::left << std::setw(12) << "Max" << std::left << std::setw(12) << "Max"
<< std::left << std::setw(12) << "Average" << std::left << std::setw(12) << "Average"
@ -260,8 +286,18 @@ void run()
<< labels[i] << csv_separator << labels[i] << csv_separator
<< num_times << csv_separator << num_times << csv_separator
<< ARRAY_SIZE << csv_separator << ARRAY_SIZE << csv_separator
<< sizeof(T) << csv_separator << sizeof(T) << csv_separator;
<< 1.0E-6 * sizes[i] / (*minmax.first) << csv_separator if (mibibytes)
{
std::cout
<< pow(2.0, -20.0) * sizes[i] / (*minmax.first) << csv_separator;
}
else
{
std::cout
<< 1.0E-6 * sizes[i] / (*minmax.first) << csv_separator;
}
std::cout
<< *minmax.first << csv_separator << *minmax.first << csv_separator
<< *minmax.second << csv_separator << *minmax.second << csv_separator
<< average << average
@ -298,11 +334,22 @@ void run_triad()
std::cout << "Precision: double" << std::endl; std::cout << "Precision: double" << std::endl;
std::streamsize ss = std::cout.precision(); std::streamsize ss = std::cout.precision();
std::cout << std::setprecision(1) << std::fixed if (mibibytes)
<< "Array size: " << ARRAY_SIZE*sizeof(T)*1.0E-3 << " KB" {
<< " (=" << ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB)" << std::endl; std::cout << std::setprecision(1) << std::fixed
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-3 << " KB" << "Array size: " << ARRAY_SIZE*sizeof(T)*pow(2.0, -10.0) << " KiB"
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB)" << std::endl; << " (=" << ARRAY_SIZE*sizeof(T)*pow(2.0, -20.0) << " MiB)" << std::endl;
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*pow(2.0, -10.0) << " KiB"
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*pow(2.0, -20.0) << " MiB)" << std::endl;
}
else
{
std::cout << std::setprecision(1) << std::fixed
<< "Array size: " << ARRAY_SIZE*sizeof(T)*1.0E-3 << " KB"
<< " (=" << ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB)" << std::endl;
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-3 << " KB"
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB)" << std::endl;
}
std::cout.precision(ss); std::cout.precision(ss);
} }
@ -369,15 +416,26 @@ void run_triad()
// Display timing results // Display timing results
double total_bytes = 3 * sizeof(T) * ARRAY_SIZE * num_times; double total_bytes = 3 * sizeof(T) * ARRAY_SIZE * num_times;
double bandwidth = 1.0E-9 * (total_bytes / runtime); double bandwidth;
std::string units;
if (mibibytes)
bandwidth = pow(2.0, -30.0) * (total_bytes / runtime);
else
bandwidth = 1.0E-9 * (total_bytes / runtime);
if (output_as_csv) if (output_as_csv)
{ {
if (mibibytes)
units = "gibytes_per_sec";
else
units = "gbytes_per_sec";
std::cout std::cout
<< "function" << csv_separator << "function" << csv_separator
<< "num_times" << csv_separator << "num_times" << csv_separator
<< "n_elements" << csv_separator << "n_elements" << csv_separator
<< "sizeof" << csv_separator << "sizeof" << csv_separator
<< "gbytes_per_sec" << csv_separator << units << csv_separator
<< "runtime" << "runtime"
<< std::endl; << std::endl;
std::cout std::cout
@ -391,12 +449,17 @@ void run_triad()
} }
else else
{ {
if (mibibytes)
units = "GiB/s";
else
units = "GB/s";
std::cout std::cout
<< "--------------------------------" << "--------------------------------"
<< std::endl << std::fixed << std::endl << std::fixed
<< "Runtime (seconds): " << std::left << std::setprecision(5) << "Runtime (seconds): " << std::left << std::setprecision(5)
<< runtime << std::endl << runtime << std::endl
<< "Bandwidth (GB/s): " << std::left << std::setprecision(3) << "Bandwidth (" << units << "): " << std::left << std::setprecision(3)
<< bandwidth << std::endl; << bandwidth << std::endl;
} }
@ -521,6 +584,10 @@ void parseArguments(int argc, char *argv[])
{ {
output_as_csv = true; output_as_csv = true;
} }
else if (!std::string("--mibibytes").compare(argv[i]))
{
mibibytes = true;
}
else if (!std::string("--help").compare(argv[i]) || else if (!std::string("--help").compare(argv[i]) ||
!std::string("-h").compare(argv[i])) !std::string("-h").compare(argv[i]))
{ {
@ -535,6 +602,7 @@ void parseArguments(int argc, char *argv[])
std::cout << " --float Use floats (rather than doubles)" << std::endl; std::cout << " --float Use floats (rather than doubles)" << std::endl;
std::cout << " --triad-only Only run triad" << std::endl; std::cout << " --triad-only Only run triad" << std::endl;
std::cout << " --csv Output as csv table" << std::endl; std::cout << " --csv Output as csv table" << std::endl;
std::cout << " --mibibytes Use MiB=2^20 for bandwidth calculation (default MB=10^6)" << std::endl;
std::cout << std::endl; std::cout << std::endl;
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }