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"
7 using namespace Eigen;
8 
9 #ifndef SCALAR
10 #error SCALAR must be defined
11 #endif
12 
13 typedef SCALAR Scalar;
14 
16 
17 template<typename Func>
19 double 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 
48 template<typename Func>
49 int 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 }
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
main_gemm
int main_gemm(int argc, char **argv, const Func &f)
Definition: gemm_common.h:49
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
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
Scalar
SCALAR Scalar
Definition: gemm_common.h:13
relicense.filename
filename
Definition: relicense.py:57
Eigen::BenchTimer
Definition: BenchTimer.h:59
BENCH
#define BENCH(TIMER, TRIES, REP, CODE)
Definition: BenchTimer.h:174
Mat
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition: gemm_common.h:15
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
bench
EIGEN_DONT_INLINE double bench(long m, long n, long k, const Func &f)
Definition: gemm_common.h:19
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
Eigen::Matrix< Scalar, Dynamic, Dynamic >
Eigen::PlainObjectBase::setZero
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:562
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
EIGEN_DONT_INLINE
#define EIGEN_DONT_INLINE
Definition: Macros.h:940


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:19