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 }
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
Matrix3f m
#define max(a, b)
Definition: datatypes.h:20
#define min(a, b)
Definition: datatypes.h:19
int n
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition: gemv_common.h:16
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
#define EIGEN_DONT_INLINE
Definition: Macros.h:940
double best(int TIMER=CPU_TIMER) const
Definition: BenchTimer.h:111
int main_gemv(int argc, char **argv, Func &f)
Definition: gemv_common.h:51
SCALAR Scalar
Definition: gemv_common.h:14
EIGEN_DONT_INLINE double bench(long m, long n, Func &f)
Definition: gemv_common.h:21
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:50
Matrix< Scalar, Dynamic, 1 > Vec
Definition: gemv_common.h:17
#define SCALAR
Definition: bench_gemm.cpp:23
std::map< std::string, Array< float, 1, 8, DontAlign|RowMajor > > results
#define BENCH(TIMER, TRIES, REP, CODE)
Definition: BenchTimer.h:174
Derived & setRandom(Index size)
Definition: Random.h:151
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:15