| [221] | 1 | /*************************************************************************** | 
|---|
|  | 2 | * blitz/benchext.h      BenchmarkExt classes (Benchmarks with external | 
|---|
|  | 3 | *                       control) | 
|---|
|  | 4 | * | 
|---|
|  | 5 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca> | 
|---|
|  | 6 | * | 
|---|
|  | 7 | * This program is free software; you can redistribute it and/or | 
|---|
|  | 8 | * modify it under the terms of the GNU General Public License | 
|---|
|  | 9 | * as published by the Free Software Foundation; either version 2 | 
|---|
|  | 10 | * of the License, or (at your option) any later version. | 
|---|
|  | 11 | * | 
|---|
|  | 12 | * This program is distributed in the hope that it will be useful, | 
|---|
|  | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 15 | * GNU General Public License for more details. | 
|---|
|  | 16 | * | 
|---|
|  | 17 | * Suggestions:          blitz-suggest@cybervision.com | 
|---|
|  | 18 | * Bugs:                 blitz-bugs@cybervision.com | 
|---|
|  | 19 | * | 
|---|
|  | 20 | * For more information, please see the Blitz++ Home Page: | 
|---|
|  | 21 | *    http://seurat.uwaterloo.ca/blitz/ | 
|---|
|  | 22 | * | 
|---|
|  | 23 | *************************************************************************** | 
|---|
|  | 24 | * $Log: not supported by cvs2svn $ | 
|---|
|  | 25 | * Revision 1.2  1998/03/14 00:04:47  tveldhui | 
|---|
|  | 26 | * 0.2-alpha-05 | 
|---|
|  | 27 | * | 
|---|
|  | 28 | * Revision 1.1  1997/07/16 14:51:20  tveldhui | 
|---|
|  | 29 | * Update: Alpha release 0.2 (Arrays) | 
|---|
|  | 30 | * | 
|---|
|  | 31 | */ | 
|---|
|  | 32 |  | 
|---|
|  | 33 | #ifndef BZ_BENCHEXT_H | 
|---|
|  | 34 | #define BZ_BENCHEXT_H | 
|---|
|  | 35 |  | 
|---|
|  | 36 | #ifndef BZ_MATRIX_H | 
|---|
|  | 37 | #include <blitz/matrix.h> | 
|---|
|  | 38 | #endif | 
|---|
|  | 39 |  | 
|---|
|  | 40 | #ifndef BZ_TIMER_H | 
|---|
|  | 41 | #include <blitz/timer.h> | 
|---|
|  | 42 | #endif | 
|---|
|  | 43 |  | 
|---|
|  | 44 | #include <math.h> | 
|---|
|  | 45 |  | 
|---|
|  | 46 | // NEEDS_WORK: replace use of const char* with <string>, once standard | 
|---|
|  | 47 | // library is widely supported. | 
|---|
|  | 48 |  | 
|---|
|  | 49 | BZ_NAMESPACE(blitz) | 
|---|
|  | 50 |  | 
|---|
|  | 51 | // Declaration of class BenchmarkExt<T> | 
|---|
|  | 52 | // The template parameter T is the parameter type which is varied in | 
|---|
|  | 53 | // the benchmark.  Typically T will be an unsigned, and will represent | 
|---|
|  | 54 | // the length of a vector, size of an array, etc. | 
|---|
|  | 55 |  | 
|---|
|  | 56 | template<class P_parameter = unsigned> | 
|---|
|  | 57 | class BenchmarkExt { | 
|---|
|  | 58 |  | 
|---|
|  | 59 | public: | 
|---|
|  | 60 | typedef P_parameter T_parameter; | 
|---|
|  | 61 |  | 
|---|
|  | 62 | BenchmarkExt(const char* description, int numImplementations); | 
|---|
|  | 63 |  | 
|---|
|  | 64 | ~BenchmarkExt(); | 
|---|
|  | 65 |  | 
|---|
|  | 66 | void setNumParameters(int numParameters); | 
|---|
|  | 67 | void setParameterVector(Vector<T_parameter> parms); | 
|---|
|  | 68 | void setParameterDescription(const char* string); | 
|---|
|  | 69 | void setIterations(Vector<long> iters); | 
|---|
|  | 70 | void setFlopsPerIteration(Vector<double> flopsPerIteration); | 
|---|
|  | 71 | void setRateDescription(const char* string); | 
|---|
|  | 72 |  | 
|---|
|  | 73 | void beginBenchmarking(); | 
|---|
|  | 74 |  | 
|---|
|  | 75 | void beginImplementation(const char* description); | 
|---|
|  | 76 |  | 
|---|
|  | 77 | _bz_bool doneImplementationBenchmark() const; | 
|---|
|  | 78 |  | 
|---|
|  | 79 | T_parameter getParameter() const; | 
|---|
|  | 80 | long        getIterations() const; | 
|---|
|  | 81 |  | 
|---|
|  | 82 | inline void start(); | 
|---|
|  | 83 | inline void stop(); | 
|---|
|  | 84 |  | 
|---|
|  | 85 | void startOverhead(); | 
|---|
|  | 86 | void stopOverhead(); | 
|---|
|  | 87 |  | 
|---|
|  | 88 | void endImplementation(); | 
|---|
|  | 89 |  | 
|---|
|  | 90 | void endBenchmarking(); | 
|---|
|  | 91 |  | 
|---|
|  | 92 | double getMflops(unsigned implementation, unsigned parameterNum) const; | 
|---|
|  | 93 |  | 
|---|
|  | 94 | void saveMatlabGraph(const char* filename) const; | 
|---|
|  | 95 |  | 
|---|
|  | 96 | protected: | 
|---|
|  | 97 | BenchmarkExt(const BenchmarkExt<P_parameter>&) { } | 
|---|
|  | 98 | void operator=(const BenchmarkExt<P_parameter>&) { } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | enum { initializing, benchmarking, benchmarkingImplementation, | 
|---|
|  | 101 | running, runningOverhead, done } state_; | 
|---|
|  | 102 |  | 
|---|
|  | 103 | unsigned numImplementations_; | 
|---|
|  | 104 | unsigned implementationNumber_; | 
|---|
|  | 105 |  | 
|---|
|  | 106 | const char* description_; | 
|---|
|  | 107 | Vector<const char*> implementationDescriptions_; | 
|---|
|  | 108 |  | 
|---|
|  | 109 | Matrix<double,RowMajor> times_;       // Elapsed time | 
|---|
|  | 110 |  | 
|---|
|  | 111 | Vector<T_parameter> parameters_; | 
|---|
|  | 112 | Vector<long> iterations_; | 
|---|
|  | 113 | Vector<double> flopsPerIteration_; | 
|---|
|  | 114 |  | 
|---|
|  | 115 | Timer timer_; | 
|---|
|  | 116 | Timer overheadTimer_; | 
|---|
|  | 117 |  | 
|---|
|  | 118 | const char* parameterDescription_; | 
|---|
|  | 119 | const char* rateDescription_; | 
|---|
|  | 120 |  | 
|---|
|  | 121 | int numParameters_; | 
|---|
|  | 122 | int parameterNumber_; | 
|---|
|  | 123 | }; | 
|---|
|  | 124 |  | 
|---|
|  | 125 | BZ_NAMESPACE_END | 
|---|
|  | 126 |  | 
|---|
|  | 127 | #include <blitz/benchext.cc> | 
|---|
|  | 128 |  | 
|---|
|  | 129 | #endif // BZ_BENCHEXT_H | 
|---|