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 }
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:49
Matrix3f m
#define max(a, b)
Definition: datatypes.h:20
SCALAR Scalar
Definition: gemm_common.h:13
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
#define min(a, b)
Definition: datatypes.h:19
int n
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
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
EIGEN_DONT_INLINE double bench(long m, long n, long k, const Func &f)
Definition: gemm_common.h:19
#define EIGEN_DONT_INLINE
Definition: Macros.h:940
int main_gemm(int argc, char **argv, const Func &f)
Definition: gemm_common.h:49
double best(int TIMER=CPU_TIMER) const
Definition: BenchTimer.h:111
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
#define SCALAR
Definition: bench_gemm.cpp:23
std::map< std::string, Array< float, 1, 8, DontAlign|RowMajor > > results
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition: gemm_common.h:15
#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