From 3becf113bd06d83df74a64bad57ffb4405a27ff7 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Wed, 23 Mar 2016 11:39:57 -0500 Subject: [PATCH] Logging dispatch latency through database util [ROCm/clr commit: 867554c4230b2d8763baf1df035122ed4ad29389] --- .../1_Utils/hipDispatchLatency/Makefile | 2 +- .../hipDispatchLatency/ResultDatabase.cpp | 527 ++++++++++++++++++ .../hipDispatchLatency/ResultDatabase.h | 100 ++++ .../hipDispatchLatency/hipDispatchLatency.cpp | 37 +- 4 files changed, 655 insertions(+), 11 deletions(-) create mode 100644 projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/ResultDatabase.cpp create mode 100644 projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/ResultDatabase.h diff --git a/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/Makefile b/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/Makefile index b4543e6f99..4b33a0ff6d 100644 --- a/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/Makefile +++ b/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/Makefile @@ -6,7 +6,7 @@ EXE=hipDispatchLatency all: install $(EXE): hipDispatchLatency.cpp - $(HIPCC) hipDispatchLatency.cpp -o $@ + $(HIPCC) hipDispatchLatency.cpp ResultDatabase.cpp -o $@ install: $(EXE) cp $(EXE) $(HIP_PATH)/bin diff --git a/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/ResultDatabase.cpp b/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/ResultDatabase.cpp new file mode 100644 index 0000000000..2ec686f260 --- /dev/null +++ b/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/ResultDatabase.cpp @@ -0,0 +1,527 @@ +#include "ResultDatabase.h" + +#include +#include +#include +#include + +using namespace std; + +bool ResultDatabase::Result::operator<(const Result &rhs) const +{ + if (test < rhs.test) + return true; + if (test > rhs.test) + return false; + if (atts < rhs.atts) + return true; + if (atts > rhs.atts) + return false; + return false; // less-operator returns false on equal +} + +double ResultDatabase::Result::GetMin() const +{ + double r = FLT_MAX; + for (int i=0; i= 100) + return value[n-1]; + + double index = ((n + 1.) * q / 100.) - 1; + + vector sorted = value; + sort(sorted.begin(), sorted.end()); + + if (n == 2) + return (sorted[0] * (1 - q/100.) + sorted[1] * (q/100.)); + + int index_lo = int(index); + double frac = index - index_lo; + if (frac == 0) + return sorted[index_lo]; + + double lo = sorted[index_lo]; + double hi = sorted[index_lo + 1]; + return lo + (hi-lo)*frac; +} + +double ResultDatabase::Result::GetMean() const +{ + double r = 0; + for (int i=0; i &values) +{ + for (int i=0; i= results.size()) + { + Result r; + r.test = test; + r.atts = atts; + r.unit = unit; + results.push_back(r); + } + + results[index].value.push_back(value); +} + +// **************************************************************************** +// Method: ResultDatabase::DumpDetailed +// +// Purpose: +// Writes the full results, including all trials. +// +// Arguments: +// out where to print +// +// Programmer: Jeremy Meredith +// Creation: August 14, 2009 +// +// Modifications: +// Jeremy Meredith, Wed Nov 10 14:25:17 EST 2010 +// Renamed to DumpDetailed to make room for a DumpSummary. +// +// Jeremy Meredith, Thu Nov 11 11:39:57 EST 2010 +// Added note about (*) missing value tag. +// +// Jeremy Meredith, Tue Nov 23 13:57:02 EST 2010 +// Changed note about missing values to be worded a little better. +// +// **************************************************************************** +void ResultDatabase::DumpDetailed(ostream &out) +{ + vector sorted(results); + sort(sorted.begin(), sorted.end()); + + const int testNameW = 24 ; + const int attW = 12; + const int fieldW = 11; + out << std::fixed << right << std::setprecision(4); + + int maxtrials = 1; + for (int i=0; i maxtrials) + maxtrials = sorted[i].value.size(); + } + + // TODO: in big parallel runs, the "trials" are the procs + // and we really don't want to print them all out.... + out << setw(testNameW) << "test\t" + << setw(attW) << "atts\t" + << setw(fieldW) + << "median\t" + << "mean\t" + << "stddev\t" + << "min\t" + << "max\t"; + for (int i=0; i sorted(results); + sort(sorted.begin(), sorted.end()); + + const int testNameW = 24 ; + const int attW = 12; + const int fieldW = 9; + out << std::fixed << right << std::setprecision(4); + + // TODO: in big parallel runs, the "trials" are the procs + // and we really don't want to print them all out.... + out << setw(testNameW) << "test\t" + << setw(attW) << "atts\t" + << setw(fieldW) + << "units\t" + << "median\t" + << "mean\t" + << "stddev\t" + << "min\t" + << "max\t"; + out << endl; + + for (int i=0; i sorted(results); + + sort(sorted.begin(), sorted.end()); + + //Check to see if the file is empty - if so, add the headers + emptyFile = this->IsFileEmpty(fileName); + + //Open file and append by default + ofstream out; + out.open(fileName.c_str(), std::ofstream::out | std::ofstream::app); + + //Add headers only for empty files + if(emptyFile) + { + // TODO: in big parallel runs, the "trials" are the procs + // and we really don't want to print them all out.... + out << "test, " + << "atts, " + << "units, " + << "median, " + << "mean, " + << "stddev, " + << "min, " + << "max, "; + out << endl; + } + + for (int i=0; i +ResultDatabase::GetResultsForTest(const string &test) +{ + // get only the given test results + vector retval; + for (int i=0; i & +ResultDatabase::GetResults() const +{ + return results; +} diff --git a/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/ResultDatabase.h b/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/ResultDatabase.h new file mode 100644 index 0000000000..4b63a02a1f --- /dev/null +++ b/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/ResultDatabase.h @@ -0,0 +1,100 @@ +#ifndef RESULT_DATABASE_H +#define RESULT_DATABASE_H + +#include +#include +#include +#include +#include +using std::string; +using std::vector; +using std::ostream; +using std::ofstream; +using std::ifstream; + + +// **************************************************************************** +// Class: ResultDatabase +// +// Purpose: +// Track numerical results as they are generated. +// Print statistics of raw results. +// +// Programmer: Jeremy Meredith +// Creation: June 12, 2009 +// +// Modifications: +// Jeremy Meredith, Wed Nov 10 14:20:47 EST 2010 +// Split timing reports into detailed and summary. E.g. for serial code, +// we might report all trial values, but skip them in parallel. +// +// Jeremy Meredith, Thu Nov 11 11:40:18 EST 2010 +// Added check for missing value tag. +// +// Jeremy Meredith, Mon Nov 22 13:37:10 EST 2010 +// Added percentile statistic. +// +// Jeremy Meredith, Fri Dec 3 16:30:31 EST 2010 +// Added a method to extract a subset of results based on test name. Also, +// the Result class is now public, so that clients can use them directly. +// Added a GetResults method as well, and made several functions const. +// +// **************************************************************************** +class ResultDatabase +{ + public: + // + // A performance result for a single SHOC benchmark run. + // + struct Result + { + string test; // e.g. "readback" + string atts; // e.g. "pagelocked 4k^2" + string unit; // e.g. "MB/sec" + vector value; // e.g. "837.14" + double GetMin() const; + double GetMax() const; + double GetMedian() const; + double GetPercentile(double q) const; + double GetMean() const; + double GetStdDev() const; + + bool operator<(const Result &rhs) const; + + bool HadAnyFLTMAXValues() const + { + for (int i=0; i= FLT_MAX) + return true; + } + return false; + } + }; + + protected: + vector results; + + public: + void AddResult(const string &test, + const string &atts, + const string &unit, + double value); + void AddResults(const string &test, + const string &atts, + const string &unit, + const vector &values); + vector GetResultsForTest(const string &test); + const vector &GetResults() const; + void ClearAllResults(); + void DumpDetailed(ostream&); + void DumpSummary(ostream&); + void DumpCsv(string fileName); + + private: + bool IsFileEmpty(string fileName); + +}; + + +#endif diff --git a/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/hipDispatchLatency.cpp b/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/hipDispatchLatency.cpp index 9827b94229..212fc6b3b1 100644 --- a/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/hipDispatchLatency.cpp +++ b/projects/clr/hipamd/samples/1_Utils/hipDispatchLatency/hipDispatchLatency.cpp @@ -20,6 +20,7 @@ THE SOFTWARE. #include"hip_runtime.h" #include #include +#include"ResultDatabase.h" #define check(msg, status) \ if(status != hipSuccess){ \ @@ -60,18 +61,22 @@ int main(){ hipEventCreate(&start); hipEventCreate(&stop); + ResultDatabase resultDB[8]; + hipEventRecord(start); hipLaunchKernel(HIP_KERNEL_NAME(One), dim3(LEN/512), dim3(512), 0, 0, Ad); hipEventRecord(stop); hipEventElapsedTime(&mS, start, stop); - std::cout<<"First Kernel Launch: \t\t"<