TR-mbed 1.0
Loading...
Searching...
No Matches
gemv_common.h
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <vector>
4#include <string>
5#include <functional>
6#include "eigen_src/Eigen/Core"
7#include "../BenchTimer.h"
8using namespace Eigen;
9
10#ifndef SCALAR
11#error SCALAR must be defined
12#endif
13
14typedef SCALAR Scalar;
15
18
19template<typename Func>
21double bench(long m, long n, Func &f)
22{
23 Mat A(m,n);
24 Vec B(n);
25 Vec C(m);
26 A.setRandom();
27 B.setRandom();
28 C.setRandom();
29
30 BenchTimer t;
31
32 double up = 1e8/sizeof(Scalar);
33 double tm0 = 4, tm1 = 10;
35 {
36 up /= 4;
37 tm0 = 2;
38 tm1 = 4;
39 }
40
41 double flops = 2. * m * n;
42 long rep = std::max(1., std::min(100., up/flops) );
43 long tries = std::max(tm0, std::min(tm1, up/flops) );
44
45 BENCH(t, tries, rep, f(A,B,C));
46
47 return 1e-9 * rep * flops / t.best();
48}
49
50template<typename Func>
51int main_gemv(int argc, char **argv, Func& f)
52{
53 std::vector<double> results;
54
55 std::string filename = std::string("gemv_settings.txt");
56 if(argc>1)
57 filename = std::string(argv[1]);
58 std::ifstream settings(filename);
59 long m, n;
60 while(settings >> m >> n)
61 {
62 //std::cerr << " Testing " << m << " " << n << std::endl;
63 results.push_back( bench(m, n, f) );
64 }
65
66 std::cout << RowVectorXd::Map(results.data(), results.size());
67
68 return 0;
69}
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
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 gemv_common.h:14
int main_gemv(int argc, char **argv, Func &f)
Definition gemv_common.h:51
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition gemv_common.h:16
Matrix< Scalar, Dynamic, 1 > Vec
Definition gemv_common.h:17
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