Merge pull request #35 from psteinb/adding_csv_output

Adding csv output
This commit is contained in:
Tom Deakin 2017-07-31 15:03:00 +01:00 committed by GitHub
commit 5ad8341b39

View File

@ -44,6 +44,8 @@ unsigned int ARRAY_SIZE = 33554432;
unsigned int num_times = 100;
unsigned int deviceIndex = 0;
bool use_float = false;
bool output_as_csv = false;
std::string csv_separator = ",";
template <typename T>
void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>& b, std::vector<T>& c, T& sum);
@ -54,13 +56,17 @@ void run();
void parseArguments(int argc, char *argv[]);
int main(int argc, char *argv[])
{
parseArguments(argc, argv);
if (!output_as_csv)
{
std::cout
<< "BabelStream" << std::endl
<< "Version: " << VERSION_STRING << std::endl
<< "Implementation: " << IMPLEMENTATION_STRING << std::endl;
parseArguments(argc, argv);
}
// TODO: Fix Kokkos to allow multiple template specializations
#ifndef KOKKOS
@ -74,6 +80,10 @@ int main(int argc, char *argv[])
template <typename T>
void run()
{
std::streamsize ss = std::cout.precision();
if (!output_as_csv)
{
std::cout << "Running kernels " << num_times << " times" << std::endl;
@ -82,11 +92,7 @@ void run()
else
std::cout << "Precision: double" << std::endl;
// Create host vectors
std::vector<T> a(ARRAY_SIZE);
std::vector<T> b(ARRAY_SIZE);
std::vector<T> c(ARRAY_SIZE);
std::streamsize ss = std::cout.precision();
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;
@ -94,6 +100,13 @@ void run()
<< " (=" << 3.0*ARRAY_SIZE*sizeof(T)*1.0E-9 << " GB)" << std::endl;
std::cout.precision(ss);
}
// Create host vectors
std::vector<T> a(ARRAY_SIZE);
std::vector<T> b(ARRAY_SIZE);
std::vector<T> c(ARRAY_SIZE);
// Result of the Dot kernel
T sum;
@ -185,14 +198,31 @@ void run()
check_solution<T>(num_times, a, b, c, sum);
// Display timing results
if (output_as_csv)
{
std::cout
<< "function" << csv_separator
<< "num_times" << csv_separator
<< "n_elements" << csv_separator
<< "sizeof" << csv_separator
<< "max_mbytes_per_sec" << csv_separator
<< "min_runtime" << csv_separator
<< "max_runtime" << csv_separator
<< "avg_runtime" << std::endl;
}
else
{
std::cout
<< std::left << std::setw(12) << "Function"
<< std::left << std::setw(12) << "MBytes/sec"
<< std::left << std::setw(12) << "Min (sec)"
<< std::left << std::setw(12) << "Max"
<< std::left << std::setw(12) << "Average" << std::endl;
<< std::left << std::setw(12) << "Average"
<< std::endl
<< std::fixed;
}
std::cout << std::fixed;
std::string labels[5] = {"Copy", "Mul", "Add", "Triad", "Dot"};
size_t sizes[5] = {
@ -212,6 +242,21 @@ void run()
double average = std::accumulate(timings[i].begin()+1, timings[i].end(), 0.0) / (double)(num_times - 1);
// Display results
if (output_as_csv)
{
std::cout
<< labels[i] << csv_separator
<< num_times << csv_separator
<< ARRAY_SIZE << csv_separator
<< sizeof(T) << csv_separator
<< 1.0E-6 * sizes[i] / (*minmax.first) << csv_separator
<< *minmax.first << csv_separator
<< *minmax.second << csv_separator
<< average << csv_separator
<< std::endl;
}
else
{
std::cout
<< std::left << std::setw(12) << labels[i]
<< std::left << std::setw(12) << std::setprecision(3) << 1.0E-6 * sizes[i] / (*minmax.first)
@ -219,7 +264,7 @@ void run()
<< std::left << std::setw(12) << std::setprecision(5) << *minmax.second
<< std::left << std::setw(12) << std::setprecision(5) << average
<< std::endl;
}
}
delete stream;
@ -333,6 +378,10 @@ void parseArguments(int argc, char *argv[])
{
use_float = true;
}
else if (!std::string("--csv").compare(argv[i]))
{
output_as_csv = true;
}
else if (!std::string("--help").compare(argv[i]) ||
!std::string("-h").compare(argv[i]))
{
@ -345,6 +394,7 @@ void parseArguments(int argc, char *argv[])
std::cout << " -s --arraysize SIZE Use SIZE elements in the array" << std::endl;
std::cout << " -n --numtimes NUM Run the test NUM times (NUM >= 2)" << std::endl;
std::cout << " --float Use floats (rather than doubles)" << std::endl;
std::cout << " --csv Output as csv table" << std::endl;
std::cout << std::endl;
exit(EXIT_SUCCESS);
}