product_threshold.cpp
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <Eigen/Core>
4 #include <bench/BenchTimer.h>
5 
6 using namespace Eigen;
7 using namespace std;
8 
9 #define END 9
10 
11 template<int S> struct map_size { enum { ret = S }; };
12 template<> struct map_size<10> { enum { ret = 20 }; };
13 template<> struct map_size<11> { enum { ret = 50 }; };
14 template<> struct map_size<12> { enum { ret = 100 }; };
15 template<> struct map_size<13> { enum { ret = 300 }; };
16 
17 template<int M, int N,int K> struct alt_prod
18 {
19  enum {
20  ret = M==1 && N==1 ? InnerProduct
21  : K==1 ? OuterProduct
22  : M==1 ? GemvProduct
23  : N==1 ? GemvProduct
24  : GemmProduct
25  };
26 };
27 
28 void print_mode(int mode)
29 {
30  if(mode==InnerProduct) std::cout << "i";
31  if(mode==OuterProduct) std::cout << "o";
32  if(mode==CoeffBasedProductMode) std::cout << "c";
33  if(mode==LazyCoeffBasedProductMode) std::cout << "l";
34  if(mode==GemvProduct) std::cout << "v";
35  if(mode==GemmProduct) std::cout << "m";
36 }
37 
38 template<int Mode, typename Lhs, typename Rhs, typename Res>
39 EIGEN_DONT_INLINE void prod(const Lhs& a, const Rhs& b, Res& c)
40 {
41  c.noalias() += typename ProductReturnType<Lhs,Rhs,Mode>::Type(a,b);
42 }
43 
44 template<int M, int N, int K, typename Scalar, int Mode>
46 {
47  typedef Matrix<Scalar,M,K> Lhs; Lhs a; a.setRandom();
48  typedef Matrix<Scalar,K,N> Rhs; Rhs b; b.setRandom();
49  typedef Matrix<Scalar,M,N> Res; Res c; c.setRandom();
50 
51  BenchTimer t;
52  double n = 2.*double(M)*double(N)*double(K);
53  int rep = 100000./n;
54  rep /= 2;
55  if(rep<1) rep = 1;
56  do {
57  rep *= 2;
58  t.reset();
59  BENCH(t,1,rep,prod<CoeffBasedProductMode>(a,b,c));
60  } while(t.best()<0.1);
61 
62  t.reset();
63  BENCH(t,5,rep,prod<Mode>(a,b,c));
64 
65  print_mode(Mode);
66  std::cout << int(1e-6*n*rep/t.best()) << "\t";
67 }
68 
69 template<int N> struct print_n;
70 template<int M, int N, int K> struct loop_on_m;
71 template<int M, int N, int K, typename Scalar, int Mode> struct loop_on_n;
72 
73 template<int M, int N, int K>
74 struct loop_on_k
75 {
76  static void run()
77  {
78  std::cout << "K=" << K << "\t";
80  std::cout << "\n";
81 
83  std::cout << "\n\n";
84 
86  }
87 };
88 
89 template<int M, int N>
90 struct loop_on_k<M,N,END> { static void run(){} };
91 
92 
93 template<int M, int N, int K>
94 struct loop_on_m
95 {
96  static void run()
97  {
98  std::cout << M << "f\t";
100  std::cout << "\n";
101 
102  std::cout << M << "f\t";
104  std::cout << "\n";
105 
107  }
108 };
109 
110 template<int N, int K>
111 struct loop_on_m<END,N,K> { static void run(){} };
112 
113 template<int M, int N, int K, typename Scalar, int Mode>
114 struct loop_on_n
115 {
116  static void run()
117  {
118  bench_prod<M,N,K,Scalar,Mode==-1? alt_prod<M,N,K>::ret : Mode>();
119 
121  }
122 };
123 
124 template<int M, int K, typename Scalar, int Mode>
125 struct loop_on_n<M,END,K,Scalar,Mode> { static void run(){} };
126 
127 template<int N> struct print_n
128 {
129  static void run()
130  {
133  }
134 };
135 
136 template<> struct print_n<END> { static void run(){} };
137 
138 int main()
139 {
141 
142  return 0;
143 }
static void run()
SCALAR Scalar
Definition: bench_gemm.cpp:33
static void run()
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:38
Scalar * b
Definition: benchVecAdd.cpp:17
return int(ret)+1
int n
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
static void run()
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
Definition: Half.h:150
#define N
Definition: gksort.c:12
#define EIGEN_DONT_INLINE
Definition: Macros.h:517
Array33i a
static void run()
#define END
Key S(std::uint64_t j)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
double best(int TIMER=CPU_TIMER) const
Definition: BenchTimer.h:107
void print_mode(int mode)
DenseIndex ret
Definition: level1_impl.h:59
#define BENCH(TIMER, TRIES, REP, CODE)
Definition: BenchTimer.h:170
int main()
The matrix class, also used for vectors and row-vectors.
EIGEN_DONT_INLINE void bench_prod()
Point2 t(10, 10)
const Product< Lhs, Rhs > prod(const Lhs &lhs, const Rhs &rhs)
Definition: evaluators.cpp:8


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:34