Skip to content

Commit decc44f

Browse files
authored
Merge pull request #56 from UoB-HPC/base2
Add a --mibibytes flag to output bandwidth and array sizes in base 2
2 parents db2a4c4 + dd6f3af commit decc44f

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
99
- OpenMP GNU compiler now uses native target flag.
1010
- Support CSV output for Triad only running mode.
1111
- NEC and PGI compiler option for OpenMP version.
12+
- Option to calculate memory bandwidth in base 2 (MiB/s) rather than base 10 (MB/s).
1213

1314
### Changed
1415
- Update SYCL implementation to SYCL 1.2.1 interface.

main.cpp

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ unsigned int deviceIndex = 0;
4646
bool use_float = false;
4747
bool triad_only = false;
4848
bool output_as_csv = false;
49+
bool mibibytes = false;
4950
std::string csv_separator = ",";
5051

5152
template <typename T>
@@ -105,11 +106,24 @@ void run()
105106
std::cout << "Precision: double" << std::endl;
106107

107108

108-
std::cout << std::setprecision(1) << std::fixed
109-
<< "Array size: " << ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB"
110-
<< " (=" << ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl;
111-
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB"
112-
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl;
109+
if (mibibytes)
110+
{
111+
// MiB = 2^20
112+
std::cout << std::setprecision(1) << std::fixed
113+
<< "Array size: " << ARRAY_SIZE*sizeof(T)*pow(2.0, -20.0) << " MiB"
114+
<< " (=" << ARRAY_SIZE*sizeof(T)*pow(2.0, -30.0) << " GiB)" << std::endl;
115+
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*pow(2.0, -20.0) << " MiB"
116+
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*pow(2.0, -30.0) << " GiB)" << std::endl;
117+
}
118+
else
119+
{
120+
// MB = 10^6
121+
std::cout << std::setprecision(1) << std::fixed
122+
<< "Array size: " << ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB"
123+
<< " (=" << ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl;
124+
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB"
125+
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl;
126+
}
113127
std::cout.precision(ss);
114128

115129
}
@@ -217,7 +231,7 @@ void run()
217231
<< "num_times" << csv_separator
218232
<< "n_elements" << csv_separator
219233
<< "sizeof" << csv_separator
220-
<< "max_mbytes_per_sec" << csv_separator
234+
<< ((mibibytes) ? "max_mibytes_per_sec" : "max_mbytes_per_sec") << csv_separator
221235
<< "min_runtime" << csv_separator
222236
<< "max_runtime" << csv_separator
223237
<< "avg_runtime" << std::endl;
@@ -226,7 +240,7 @@ void run()
226240
{
227241
std::cout
228242
<< std::left << std::setw(12) << "Function"
229-
<< std::left << std::setw(12) << "MBytes/sec"
243+
<< std::left << std::setw(12) << ((mibibytes) ? "MiBytes/sec" : "MBytes/sec")
230244
<< std::left << std::setw(12) << "Min (sec)"
231245
<< std::left << std::setw(12) << "Max"
232246
<< std::left << std::setw(12) << "Average"
@@ -261,7 +275,7 @@ void run()
261275
<< num_times << csv_separator
262276
<< ARRAY_SIZE << csv_separator
263277
<< sizeof(T) << csv_separator
264-
<< 1.0E-6 * sizes[i] / (*minmax.first) << csv_separator
278+
<< ((mibibytes) ? pow(2.0, -20.0) : 1.0E-6) * sizes[i] / (*minmax.first) << csv_separator
265279
<< *minmax.first << csv_separator
266280
<< *minmax.second << csv_separator
267281
<< average
@@ -271,7 +285,8 @@ void run()
271285
{
272286
std::cout
273287
<< std::left << std::setw(12) << labels[i]
274-
<< std::left << std::setw(12) << std::setprecision(3) << 1.0E-6 * sizes[i] / (*minmax.first)
288+
<< std::left << std::setw(12) << std::setprecision(3) <<
289+
((mibibytes) ? pow(2.0, -20.0) : 1.0E-6) * sizes[i] / (*minmax.first)
275290
<< std::left << std::setw(12) << std::setprecision(5) << *minmax.first
276291
<< std::left << std::setw(12) << std::setprecision(5) << *minmax.second
277292
<< std::left << std::setw(12) << std::setprecision(5) << average
@@ -298,11 +313,22 @@ void run_triad()
298313
std::cout << "Precision: double" << std::endl;
299314

300315
std::streamsize ss = std::cout.precision();
301-
std::cout << std::setprecision(1) << std::fixed
302-
<< "Array size: " << ARRAY_SIZE*sizeof(T)*1.0E-3 << " KB"
303-
<< " (=" << ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB)" << std::endl;
304-
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-3 << " KB"
305-
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB)" << std::endl;
316+
if (mibibytes)
317+
{
318+
std::cout << std::setprecision(1) << std::fixed
319+
<< "Array size: " << ARRAY_SIZE*sizeof(T)*pow(2.0, -10.0) << " KiB"
320+
<< " (=" << ARRAY_SIZE*sizeof(T)*pow(2.0, -20.0) << " MiB)" << std::endl;
321+
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*pow(2.0, -10.0) << " KiB"
322+
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*pow(2.0, -20.0) << " MiB)" << std::endl;
323+
}
324+
else
325+
{
326+
std::cout << std::setprecision(1) << std::fixed
327+
<< "Array size: " << ARRAY_SIZE*sizeof(T)*1.0E-3 << " KB"
328+
<< " (=" << ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB)" << std::endl;
329+
std::cout << "Total size: " << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-3 << " KB"
330+
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-6 << " MB)" << std::endl;
331+
}
306332
std::cout.precision(ss);
307333
}
308334

@@ -369,15 +395,16 @@ void run_triad()
369395

370396
// Display timing results
371397
double total_bytes = 3 * sizeof(T) * ARRAY_SIZE * num_times;
372-
double bandwidth = 1.0E-9 * (total_bytes / runtime);
398+
double bandwidth = ((mibibytes) ? pow(2.0, -30.0) : 1.0E-9) * (total_bytes / runtime);
399+
373400
if (output_as_csv)
374401
{
375402
std::cout
376403
<< "function" << csv_separator
377404
<< "num_times" << csv_separator
378405
<< "n_elements" << csv_separator
379406
<< "sizeof" << csv_separator
380-
<< "gbytes_per_sec" << csv_separator
407+
<< ((mibibytes) ? "gibytes_per_sec" : "gbytes_per_sec") << csv_separator
381408
<< "runtime"
382409
<< std::endl;
383410
std::cout
@@ -396,7 +423,8 @@ void run_triad()
396423
<< std::endl << std::fixed
397424
<< "Runtime (seconds): " << std::left << std::setprecision(5)
398425
<< runtime << std::endl
399-
<< "Bandwidth (GB/s): " << std::left << std::setprecision(3)
426+
<< "Bandwidth (" << ((mibibytes) ? "GiB/s" : "GB/s") << "): "
427+
<< std::left << std::setprecision(3)
400428
<< bandwidth << std::endl;
401429
}
402430

@@ -521,6 +549,10 @@ void parseArguments(int argc, char *argv[])
521549
{
522550
output_as_csv = true;
523551
}
552+
else if (!std::string("--mibibytes").compare(argv[i]))
553+
{
554+
mibibytes = true;
555+
}
524556
else if (!std::string("--help").compare(argv[i]) ||
525557
!std::string("-h").compare(argv[i]))
526558
{
@@ -535,6 +567,7 @@ void parseArguments(int argc, char *argv[])
535567
std::cout << " --float Use floats (rather than doubles)" << std::endl;
536568
std::cout << " --triad-only Only run triad" << std::endl;
537569
std::cout << " --csv Output as csv table" << std::endl;
570+
std::cout << " --mibibytes Use MiB=2^20 for bandwidth calculation (default MB=10^6)" << std::endl;
538571
std::cout << std::endl;
539572
exit(EXIT_SUCCESS);
540573
}

0 commit comments

Comments
 (0)