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>
20 EIGEN_DONT_INLINE double bench(long m, long n, Func &f) {
21  Mat A(m, n);
22  Vec B(n);
23  Vec C(m);
24  A.setRandom();
25  B.setRandom();
26  C.setRandom();
27 
28  BenchTimer t;
29 
30  double up = 1e8 / sizeof(Scalar);
31  double tm0 = 4, tm1 = 10;
33  up /= 4;
34  tm0 = 2;
35  tm1 = 4;
36  }
37 
38  double flops = 2. * m * n;
39  long rep = std::max(1., std::min(100., up / flops));
40  long tries = std::max(tm0, std::min(tm1, up / flops));
41 
42  BENCH(t, tries, rep, f(A, B, C));
43 
44  return 1e-9 * rep * flops / t.best();
45 }
46 
47 template <typename Func>
48 int main_gemv(int argc, char **argv, Func &f) {
49  std::vector<double> results;
50 
51  std::string filename = std::string("gemv_settings.txt");
52  if (argc > 1) filename = std::string(argv[1]);
53  std::ifstream settings(filename);
54  long m, n;
55  while (settings >> m >> n) {
56  // std::cerr << " Testing " << m << " " << n << std::endl;
57  results.push_back(bench(m, n, f));
58  }
59 
60  std::cout << RowVectorXd::Map(results.data(), results.size());
61 
62  return 0;
63 }
#define BENCH(TIMER, TRIES, REP, CODE)
Definition: BenchTimer.h:150
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Array< double, 1, 3 > e(1./3., 0.5, 2.)
#define EIGEN_DONT_INLINE
Definition: Macros.h:853
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:49
#define SCALAR
Definition: bench_gemm.cpp:22
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:48
Definition: BenchTimer.h:55
Derived & setRandom(Index size)
Definition: Random.h:147
Definition: matrices.h:74
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
std::map< std::string, Array< float, 1, 8, DontAlign|RowMajor > > results
Definition: dense_solvers.cpp:10
SCALAR Scalar
Definition: gemv_common.h:14
Matrix< Scalar, Dynamic, 1 > Vec
Definition: gemv_common.h:17
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition: gemv_common.h:16
EIGEN_DONT_INLINE double bench(long m, long n, Func &f)
Definition: gemv_common.h:20
int main_gemv(int argc, char **argv, Func &f)
Definition: gemv_common.h:48
int * m
Definition: level2_cplx_impl.h:294
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
string filename
Definition: MergeRestartFiles.py:39
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
t
Definition: plotPSD.py:36
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217