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"
8 using namespace Eigen;
9 
10 #ifndef SCALAR
11 #error SCALAR must be defined
12 #endif
13 
14 typedef SCALAR Scalar;
15 
18 
19 template<typename Func>
21 double 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 
50 template<typename Func>
51 int 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 }
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
Eigen::PlainObjectBase::setRandom
Derived & setRandom(Index size)
Definition: Random.h:151
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
n
int n
Definition: BiCGSTAB_simple.cpp:1
relicense.filename
filename
Definition: relicense.py:57
Eigen::BenchTimer
Definition: BenchTimer.h:59
BENCH
#define BENCH(TIMER, TRIES, REP, CODE)
Definition: BenchTimer.h:174
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
SCALAR
#define SCALAR
Definition: bench_gemm.cpp:23
C
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:50
results
std::map< std::string, Array< float, 1, 8, DontAlign|RowMajor > > results
Definition: dense_solvers.cpp:10
min
#define min(a, b)
Definition: datatypes.h:19
main_gemv
int main_gemv(int argc, char **argv, Func &f)
Definition: gemv_common.h:51
Scalar
SCALAR Scalar
Definition: gemv_common.h:14
Eigen::Matrix< Scalar, Dynamic, Dynamic >
bench
EIGEN_DONT_INLINE double bench(long m, long n, Func &f)
Definition: gemv_common.h:21
align_3::t
Point2 t(10, 10)
max
#define max(a, b)
Definition: datatypes.h:20
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
Vec
Matrix< Scalar, Dynamic, 1 > Vec
Definition: gemv_common.h:17
EIGEN_DONT_INLINE
#define EIGEN_DONT_INLINE
Definition: Macros.h:940
Mat
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition: gemv_common.h:16


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:34