TR-mbed 1.0
Loading...
Searching...
No Matches
gemm_common.h
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <vector>
4#include <string>
5#include "eigen_src/Eigen/Core"
6#include "../BenchTimer.h"
7using namespace Eigen;
8
9#ifndef SCALAR
10#error SCALAR must be defined
11#endif
12
13typedef SCALAR Scalar;
14
16
17template<typename Func>
19double bench(long m, long n, long k, const Func& f)
20{
21 Mat A(m,k);
22 Mat B(k,n);
23 Mat C(m,n);
24 A.setRandom();
25 B.setRandom();
26 C.setZero();
27
28 BenchTimer t;
29
30 double up = 1e8*4/sizeof(Scalar);
31 double tm0 = 4, tm1 = 10;
33 {
34 up /= 4;
35 tm0 = 2;
36 tm1 = 4;
37 }
38
39 double flops = 2. * m * n * k;
40 long rep = std::max(1., std::min(100., up/flops) );
41 long tries = std::max(tm0, std::min(tm1, up/flops) );
42
43 BENCH(t, tries, rep, f(A,B,C));
44
45 return 1e-9 * rep * flops / t.best();
46}
47
48template<typename Func>
49int main_gemm(int argc, char **argv, const Func& f)
50{
51 std::vector<double> results;
52
53 std::string filename = std::string("gemm_settings.txt");
54 if(argc>1)
55 filename = std::string(argv[1]);
56 std::ifstream settings(filename);
57 long m, n, k;
58 while(settings >> m >> n >> k)
59 {
60 //std::cerr << " Testing " << m << " " << n << " " << k << std::endl;
61 results.push_back( bench(m, n, k, f) );
62 }
63
64 std::cout << RowVectorXd::Map(results.data(), results.size());
65
66 return 0;
67}
Matrix3f m
Definition AngleAxis_mimic_euler.cpp:1
#define BENCH(TIMER, TRIES, REP, CODE)
Definition BenchTimer.h:174
int n
Definition BiCGSTAB_simple.cpp:1
Array< double, 1, 3 > e(1./3., 0.5, 2.)
#define EIGEN_DONT_INLINE
Definition Macros.h:940
#define SCALAR
Definition bench_gemm.cpp:23
Matrix< Scalar, Dynamic, Dynamic > C
Definition bench_gemm.cpp:50
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition bench_gemm.cpp:48
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition bench_gemm.cpp:49
Definition BenchTimer.h:60
double best(int TIMER=CPU_TIMER) const
Definition BenchTimer.h:111
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition CwiseNullaryOp.h:562
Derived & setRandom(Index size)
Definition Random.h:151
std::map< std::string, Array< float, 1, 8, DontAlign|RowMajor > > results
Definition dense_solvers.cpp:10
SCALAR Scalar
Definition gemm_common.h:13
int main_gemm(int argc, char **argv, const Func &f)
Definition gemm_common.h:49
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition gemm_common.h:15
EIGEN_DONT_INLINE double bench()
Definition lazy_gemm.cpp:26
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233