1 | /***************************************************************************
|
---|
2 | * blitz/bench.h Benchmark classes
|
---|
3 | *
|
---|
4 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU General Public License
|
---|
8 | * as published by the Free Software Foundation; either version 2
|
---|
9 | * of the License, or (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 | * Suggestions: blitz-suggest@cybervision.com
|
---|
17 | * Bugs: blitz-bugs@cybervision.com
|
---|
18 | *
|
---|
19 | * For more information, please see the Blitz++ Home Page:
|
---|
20 | * http://seurat.uwaterloo.ca/blitz/
|
---|
21 | *
|
---|
22 | ***************************************************************************
|
---|
23 | * $Log: not supported by cvs2svn $
|
---|
24 | * Revision 1.4 1998/03/14 00:04:47 tveldhui
|
---|
25 | * 0.2-alpha-05
|
---|
26 | *
|
---|
27 | * Revision 1.3 1997/07/16 14:51:20 tveldhui
|
---|
28 | * Update: Alpha release 0.2 (Arrays)
|
---|
29 | *
|
---|
30 | * Revision 1.2 1997/01/24 14:30:34 tveldhui
|
---|
31 | * Prior to rewrite of Bench class; in this version, Bench contains
|
---|
32 | * each benchmark implementation.
|
---|
33 | *
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef BZ_BENCH_H
|
---|
37 | #define BZ_BENCH_H
|
---|
38 |
|
---|
39 | #ifndef BZ_MATRIX_H
|
---|
40 | #include <blitz/matrix.h>
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #ifndef BZ_TIMER_H
|
---|
44 | #include <blitz/timer.h>
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #include <math.h>
|
---|
48 |
|
---|
49 | BZ_NAMESPACE(blitz)
|
---|
50 |
|
---|
51 | // Forward declaration
|
---|
52 | template<class P_parameter = unsigned>
|
---|
53 | class BenchmarkImplementation;
|
---|
54 |
|
---|
55 |
|
---|
56 | // Declaration of class Benchmark<T>
|
---|
57 | // The template parameter T is the parameter type which is varied in
|
---|
58 | // the benchmark. Typically T will be an unsigned, and will represent
|
---|
59 | // the length of a vector, size of an array, etc.
|
---|
60 |
|
---|
61 | template<class P_parameter = unsigned>
|
---|
62 | class Benchmark {
|
---|
63 |
|
---|
64 | public:
|
---|
65 | typedef P_parameter T_parameter;
|
---|
66 |
|
---|
67 | Benchmark(unsigned numImplementations);
|
---|
68 |
|
---|
69 | ~Benchmark();
|
---|
70 |
|
---|
71 | void addImplementation(BenchmarkImplementation<T_parameter>*
|
---|
72 | implementation);
|
---|
73 |
|
---|
74 | void run(ostream& log = cout);
|
---|
75 |
|
---|
76 | double getMflops(unsigned implementation, unsigned setting) const;
|
---|
77 |
|
---|
78 | double getRate(unsigned implementation, unsigned setting) const;
|
---|
79 |
|
---|
80 | void saveMatlabGraph(const char* filename) const;
|
---|
81 |
|
---|
82 | public:
|
---|
83 | // Virtual functions
|
---|
84 |
|
---|
85 | virtual const char* description() const
|
---|
86 | { return ""; }
|
---|
87 |
|
---|
88 | virtual const char* parameterDescription() const
|
---|
89 | { return "Vector length"; }
|
---|
90 |
|
---|
91 | virtual unsigned numParameterSettings() const
|
---|
92 | { return 19; }
|
---|
93 |
|
---|
94 | virtual T_parameter getParameterSetting(unsigned i) const
|
---|
95 | { return ::pow(10.0, (i+1)/4.0); }
|
---|
96 |
|
---|
97 | virtual long getIterationSetting(unsigned i) const
|
---|
98 | { return 1000000L / getParameterSetting(i); }
|
---|
99 |
|
---|
100 | private:
|
---|
101 | Benchmark(const Benchmark<P_parameter>&) { }
|
---|
102 | void operator=(const Benchmark<P_parameter>&) { }
|
---|
103 |
|
---|
104 | enum { uninitialized, initialized, running, done } state_;
|
---|
105 |
|
---|
106 | unsigned numImplementations_;
|
---|
107 | unsigned numStoredImplementations_;
|
---|
108 |
|
---|
109 | BenchmarkImplementation<T_parameter>** implementations_;
|
---|
110 |
|
---|
111 | Matrix<double,RowMajor> rates_; // Iterations per second array
|
---|
112 | Matrix<double,RowMajor> Mflops_;
|
---|
113 | };
|
---|
114 |
|
---|
115 | template<class P_parameter>
|
---|
116 | class BenchmarkImplementation {
|
---|
117 |
|
---|
118 | public:
|
---|
119 | typedef P_parameter T_parameter;
|
---|
120 |
|
---|
121 | virtual void initialize(P_parameter parameter) { }
|
---|
122 |
|
---|
123 | virtual void done() { }
|
---|
124 |
|
---|
125 | virtual const char* implementationName() const
|
---|
126 | { return ""; }
|
---|
127 |
|
---|
128 | virtual void run(long iterations) = 0;
|
---|
129 |
|
---|
130 | virtual void runOverhead(long iterations)
|
---|
131 | {
|
---|
132 | for (long i=0; i < iterations; ++i)
|
---|
133 | {
|
---|
134 | }
|
---|
135 | };
|
---|
136 |
|
---|
137 | virtual void tickle() { }
|
---|
138 |
|
---|
139 | virtual long flopsPerIteration() const
|
---|
140 | { return 0; }
|
---|
141 | };
|
---|
142 |
|
---|
143 | BZ_NAMESPACE_END
|
---|
144 |
|
---|
145 | #include <blitz/bench.cc>
|
---|
146 |
|
---|
147 | #endif // BZ_BENCH_H
|
---|