1#define EIGEN_USE_THREADS
2
3#include <string>
4
5#include "tensor_benchmarks.h"
6
7#define CREATE_THREAD_POOL(threads)             \
8Eigen::ThreadPool pool(threads);                \
9Eigen::ThreadPoolDevice device(&pool, threads);
10
11
12// Contractions for number of threads ranging from 1 to 32
13// Dimensions are Rows, Cols, Depth
14#define BM_ContractionCPU(D1, D2, D3)                                         \
15  static void BM_##Contraction##_##D1##x##D2##x##D3(int iters, int Threads) { \
16    StopBenchmarkTiming();                                                    \
17    CREATE_THREAD_POOL(Threads);                                              \
18    BenchmarkSuite<Eigen::ThreadPoolDevice, float> suite(device, D1, D2, D3); \
19    suite.contraction(iters);                                                 \
20  }                                                                           \
21  BENCHMARK_RANGE(BM_##Contraction##_##D1##x##D2##x##D3, 1, 32);
22
23
24// Vector Matrix and Matrix Vector products
25BM_ContractionCPU(1, 2000, 500);
26BM_ContractionCPU(2000, 1, 500);
27
28// Various skinny matrices
29BM_ContractionCPU(250, 3, 512);
30BM_ContractionCPU(1500, 3, 512);
31
32BM_ContractionCPU(512, 800, 4);
33BM_ContractionCPU(512, 80, 800);
34BM_ContractionCPU(512, 80, 13522);
35BM_ContractionCPU(1, 80, 13522);
36
37BM_ContractionCPU(3200, 512, 4);
38BM_ContractionCPU(3200, 512, 80);
39BM_ContractionCPU(3200, 80, 512);
40