gemm.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 #include <Eigen/Core>
5 #include "../../BenchTimer.h"
6 using namespace Eigen;
7 
8 #ifndef SCALAR
9 #error SCALAR must be defined
10 #endif
11 
12 typedef SCALAR Scalar;
13 
15 
17 void gemm(const Mat &A, const Mat &B, Mat &C)
18 {
19  C.noalias() += A * B;
20 }
21 
23 double bench(long m, long n, long k)
24 {
25  Mat A(m,k);
26  Mat B(k,n);
27  Mat C(m,n);
28  A.setRandom();
29  B.setRandom();
30  C.setZero();
31 
32  BenchTimer t;
33 
34  double up = 1e8*4/sizeof(Scalar);
35  double tm0 = 4, tm1 = 10;
37  {
38  up /= 4;
39  tm0 = 2;
40  tm1 = 4;
41  }
42 
43  double flops = 2. * m * n * k;
44  long rep = std::max(1., std::min(100., up/flops) );
45  long tries = std::max(tm0, std::min(tm1, up/flops) );
46 
47  BENCH(t, tries, rep, gemm(A,B,C));
48 
49  return 1e-9 * rep * flops / t.best();
50 }
51 
52 int main(int argc, char **argv)
53 {
54  std::vector<double> results;
55 
56  std::ifstream settings("gemm_settings.txt");
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) );
62  }
63 
64  std::cout << RowVectorXd::Map(results.data(), results.size());
65 
66  return 0;
67 }
Matrix3f m
#define max(a, b)
Definition: datatypes.h:20
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:150
Matrix< SCALARB, Dynamic, Dynamic > B
Definition: bench_gemm.cpp:36
#define EIGEN_DONT_INLINE
Definition: Macros.h:517
int main(int argc, char **argv)
Definition: gemm.cpp:52
EIGEN_DONT_INLINE double bench(long m, long n, long k)
Definition: gemm.cpp:23
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition: gemm.cpp:14
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:37
SCALAR Scalar
Definition: gemm.cpp:12
double best(int TIMER=CPU_TIMER) const
Definition: BenchTimer.h:107
#define SCALAR
Definition: bench_gemm.cpp:22
std::map< std::string, Array< float, 1, 8, DontAlign|RowMajor > > results
EIGEN_DONT_INLINE void gemm(const Mat &A, const Mat &B, Mat &C)
Definition: gemm.cpp:17
#define BENCH(TIMER, TRIES, REP, CODE)
Definition: BenchTimer.h:170
Derived & setRandom(Index size)
Definition: Random.h:151
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:05