rambrain
performanceTestClasses.h
Go to the documentation of this file.
1 /* rambrain - a dynamical physical memory extender
2  * Copyright (C) 2015 M. Imgrund, A. Arth
3  * mimgrund (at) mpifr-bonn.mpg.de
4  * arth (at) usm.uni-muenchen.de
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef PERFORMANCETESTCLASSES_H
21 #define PERFORMANCETESTCLASSES_H
22 
23 #include <iostream>
24 #include <vector>
25 #include <cstring>
26 #include <cmath>
27 #include <string>
28 #include <sstream>
29 #include <cstdlib>
30 #include <map>
31 #include <inttypes.h>
32 
33 #include "tester.h"
34 
35 #include "managedFileSwap.h"
36 #include "cyclicManagedMemory.h"
37 #include "managedPtr.h"
38 #include "rambrainconfig.h"
39 
40 using namespace std;
41 using namespace rambrain;
42 
47 {
48 public:
52  virtual ~testParameterBase() {}
53 
57  virtual string valueAsString() = 0;
63  virtual string valueAsString ( unsigned int step ) = 0;
64 
65  unsigned int steps;
66  bool deltaLog;
67  string name;
68  bool enabled = true;
69 };
70 
71 
75 template<typename T>
77 {
78 
79 public:
83  virtual ~testParameter() {}
84 
88  virtual inline string valueAsString() {
89  return toString ( mean );
90  }
91 
97  virtual inline string valueAsString ( unsigned int step ) {
98  return toString ( valueAtStep ( step ) );
99  }
100 
101  T min, max, mean;
102 
103 protected:
109  T valueAtStep ( unsigned int step ) {
110  if ( steps < 2 ) {
111  return min;
112  } else if ( deltaLog ) {
113  return pow ( 10.0, ( log10 ( max ) - log10 ( min ) ) * step / ( steps - 1 ) ) * min;
114  } else {
115  return ( max - min ) * step / ( steps - 1 ) + min;
116  }
117  }
118 
125  string toString ( const T &t ) {
126  stringstream ss;
127  ss << t;
128  return ss.str();
129  }
130 
131 };
132 
133 
137 template<typename... U>
139 
140 
144 template<>
146 {
147 
148 public:
153  performanceTest ( const char *name );
157  virtual ~performanceTest() {}
158 
164  virtual void runTests ( unsigned int repetitions, const string &path = "./" );
170  static void runRegisteredTests ( unsigned int repetitions, const string &path = "./" );
176  static void enableTest ( const string &name, bool enabled );
181  static void enableAllTests ( bool enabled );
186  static void unregisterTest ( const string &name );
190  static void dumpTestInfo();
191 
202  static bool runRespectiveTest ( const string &name, tester &myTester, unsigned int repetitions, char **arguments, int &offset, int argumentscount );
203 
211  virtual void actualTestMethod ( tester &test, char **arguments, int &offset, unsigned int argumentscount ) = 0;
212 
216  virtual string getComment() = 0;
217 
223  inline static void setDisplayPlots ( bool display ) {
224  displayPlots = display;
225  }
226 
227 protected:
233  virtual inline unsigned int getStepsForParam ( unsigned int varryParam ) {
234  return parameters[varryParam]->steps;
235  }
236 
244  virtual string getParamsString ( int varryParam, unsigned int step, const string &delimiter = " " );
251  virtual string getTestOutfile ( int varryParam, unsigned int step );
258  virtual void resultToTempFile ( int varryParam, unsigned int step, ofstream &file );
265  virtual vector<string> splitString ( const string &in, char delimiter );
278  virtual string generateGnuplotScript ( const string &infile, const string &name, const string &xlabel, const string &ylabel, const string &title, bool log, int paramColumn );
285  virtual void handleTimingInfos ( int varryParam, unsigned int step, unsigned int repetitions );
293  virtual vector<vector<string>> getRelevantTimingParts ( ifstream &in, unsigned long long start, unsigned long long end );
300  virtual void timingInfosToFile ( ofstream &out, const vector<vector<string>> &relevantTimingParts, unsigned long long &starttime );
310  virtual void plotTimingInfos ( ofstream &gnutemp, const string &outname, const string &dataFile, unsigned int measurements, unsigned int repetitions, bool linesPoints );
320  virtual void plotTimingHitMissInfos ( ofstream &gnutemp, const string &outname, const string &dataFile, unsigned int measurements, unsigned int repetitions, bool linesPoints );
321 
328  virtual string generateMyGnuplotPlotPart ( const string &file, int paramColumn ) = 0;
329 
330  const char *name;
331  bool enabled = true;
332  vector<testParameterBase *> parameters;
333  static map<string, performanceTest<> *> testClasses;
334  vector<string> plotParts;
335  static bool displayPlots;
336  bool plotTimingStats = true;
337 
338 };
339 
340 
344 template<typename T, typename... U>
345 class performanceTest<T, U...> : public performanceTest<U...>
346 {
347 
348 public:
353  performanceTest ( const char *name ) : performanceTest<U...> ( name ) {
354  this->parameters.push_back ( &parameter );
355  }
356 
360  virtual ~performanceTest() {}
361 
362 protected:
364 
365 };
366 
367 
368 #define PARAMREFS(number, param, params...) testParameter<param> &parameter##number = (performanceTest<param, ##params>::parameter)
369 
370 #define ONEPARAM(param) PARAMREFS(1, param)
371 #define TWOPARAMS(param1, param2) PARAMREFS(1, param1, param2); \
372  PARAMREFS(2, param2)
373 #define THREEARAMS(param1, param2, param3) PARAMREFS(1, param1, param2, param3); \
374  PARAMREFS(2, param2, param3); \
375  PARAMREFS(3, param3)
376 
377 #define ONECONVERT(param) param p = convert<param>(arguments[offset++]); \
378  actualTestMethod(test, p)
379 #define TWOCONVERT(param1, param2) param1 p1 = convert<param1>(arguments[offset++]); \
380  param2 p2 = convert<param2>(arguments[offset++]); \
381  actualTestMethod(test, p1, p2)
382 #define THREECONVERT(param1, param2, param3) param1 p1 = convert<param1>(arguments[offset++]); \
383  param2 p2 = convert<param2>(arguments[offset++]); \
384  param3 p3 = convert<param3>(arguments[offset++]); \
385  actualTestMethod(test, p1, p2, p3)
386 
387 #define TESTCLASS(name, parammacro, convertmacro, params...) \
388  class name : public performanceTest<params> \
389  { \
390  public: \
391  name(); \
392  virtual ~name() {} \
393  virtual inline void actualTestMethod(tester& test, char **arguments, int& offset, unsigned int argumentscount); \
394  virtual void actualTestMethod(tester&, params); \
395  virtual inline string getComment() { return comment; } \
396  parammacro; \
397  static string comment; \
398  protected: \
399  virtual string generateMyGnuplotPlotPart(const string& file, int paramColumn); \
400  template<typename T> \
401  inline T convert(char* str) { \
402  return T(str); \
403  } \
404  }; \
405  template<> \
406  inline int name::convert<int>(char* str) { \
407  return atoi(str); \
408  } \
409  void name::actualTestMethod(tester& test, char **arguments, int& offset, unsigned int argumentscount) { \
410  if (argumentscount - offset < parameters.size()) { \
411  cerr << "Not enough parameters supplied for test!" << endl; \
412  } else {\
413  convertmacro; \
414  } \
415  } \
416  extern name name##Instance
417 
418 #define ONEPARAMTEST(name, param) TESTCLASS(name, ONEPARAM(param), ONECONVERT(param), param)
419 #define TWOPARAMTEST(name, param1, param2) TESTCLASS(name, TWOPARAMS(param1, param2), TWOCONVERT(param1, param2), param1, param2)
420 #define THREEPARAMTEST(name, param1, param2, param3) TESTCLASS(name, THREEPARAMS(param1, param2, param3), THREECONVERT(param1, param2, param3), param1, param2, param3)
421 
422 
423 // Actual performance test classes come here
424 
425 TWOPARAMTEST ( matrixTransposeTest, int, int );
426 TWOPARAMTEST ( matrixCleverTransposeTest, int, int );
427 TWOPARAMTEST ( matrixCleverTranspose2Test, int, int );
428 #ifndef OpenMP_NOT_FOUND
429 TWOPARAMTEST ( matrixCleverTransposeOpenMPTest, int, int );
430 #endif
431 TWOPARAMTEST ( matrixCleverBlockTransposeTest, int, int );
432 #ifndef OpenMP_NOT_FOUND
433 TWOPARAMTEST ( matrixCleverBlockTransposeOpenMPTest, int, int );
434 #endif
435 TWOPARAMTEST ( matrixMultiplyTest, int, int );
436 #ifndef OpenMP_NOT_FOUND
437 TWOPARAMTEST ( matrixMultiplyOpenMPTest, int, int );
438 #endif
439 TWOPARAMTEST ( matrixCopyTest, int, int );
440 #ifndef OpenMP_NOT_FOUND
441 TWOPARAMTEST ( matrixCopyOpenMPTest, int, int );
442 #endif
443 TWOPARAMTEST ( matrixDoubleCopyTest, int, int );
444 #ifndef OpenMP_NOT_FOUND
445 TWOPARAMTEST ( matrixDoubleCopyOpenMPTest, int, int );
446 #endif
447 TWOPARAMTEST ( measureThroughputTest, int, int );
448 TWOPARAMTEST ( measurePreemptiveSpeedupTest, int, int );
449 TWOPARAMTEST ( measureExplicitAsyncSpeedupTest, int, int );
450 ONEPARAMTEST ( measureConstSpeedupTest, int );
451 ONEPARAMTEST ( demonstrateDecayTest, int );
452 #endif // PERFORMANCETESTCLASSES_H
453 
virtual string valueAsString(unsigned int step)
Cast the encapsulated parameter to a string and return it's value at a certain step.
TWOPARAMTEST(matrixTransposeTest, int, int)
virtual ~performanceTest()
Cleanup.
vector< testParameterBase * > parameters
performanceTest(const char *name)
Create a new test object and register it for usage.
virtual unsigned int getStepsForParam(unsigned int varryParam)
Get the amount of steps for parameter variation.
Class to encapsulate parameters given by type T.
string toString(const T &t)
Convert a value of the parameter type to a string.
virtual ~testParameterBase()
Cleanup.
static map< string, performanceTest<> * > testClasses
vector< string > plotParts
Derived performance test classes which take parameter types as template arguments.
virtual ~testParameter()
Cleanup.
static void setDisplayPlots(bool display)
If the generated plots shall be immediately displayed.
A basic class to be used by tests. Provides helper methods and functionality e.g. time measurements...
Definition: tester.h:32
virtual string valueAsString()
Cast the encapsulated parameter to a string and return it's mean value.
STL namespace.
T valueAtStep(unsigned int step)
Look up the parameter value at a certain step.
ONEPARAMTEST(measureConstSpeedupTest, int)
A base class to encapsulate parameters for performance tests.