aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/tensors
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2016-02-23 05:28:02 +0000
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2016-02-23 05:28:02 +0000
commit8cb9bfab870c1f55ea9c69233a832e92c8de189d (patch)
treea06ca43a0b4e4404b45a41f6d92cef2e03153f60 /bench/tensors
parentf442a5a5b34ede4ab4e8fe36d1c8237315ad3f04 (diff)
Extended the tensor benchmark suite to support types other than floats
Diffstat (limited to 'bench/tensors')
-rw-r--r--bench/tensors/tensor_benchmarks.h100
-rw-r--r--bench/tensors/tensor_benchmarks_cpu.cc42
-rw-r--r--bench/tensors/tensor_benchmarks_gpu.cu6
3 files changed, 74 insertions, 74 deletions
diff --git a/bench/tensors/tensor_benchmarks.h b/bench/tensors/tensor_benchmarks.h
index 688f558d0..b208a401a 100644
--- a/bench/tensors/tensor_benchmarks.h
+++ b/bench/tensors/tensor_benchmarks.h
@@ -15,7 +15,7 @@ using Eigen::TensorMap;
// TODO(bsteiner): also templatize on the input type since we have users
// for int8 as well as floats.
-template <typename Device> class BenchmarkSuite {
+template <typename Device, typename T> class BenchmarkSuite {
public:
BenchmarkSuite(const Device& device, size_t m, size_t k, size_t n)
: m_(m), k_(k), n_(n), device_(device) {
@@ -37,7 +37,7 @@ template <typename Device> class BenchmarkSuite {
eigen_assert(m_ == k_ && k_ == n_);
StartBenchmarkTiming();
for (int iter = 0; iter < num_iters; ++iter) {
- device_.memcpy(c_, a_, m_ * m_ * sizeof(float));
+ device_.memcpy(c_, a_, m_ * m_ * sizeof(T));
}
// Record the number of values copied per second
finalizeBenchmark(static_cast<int64_t>(m_) * m_ * num_iters);
@@ -48,12 +48,12 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> sizes;
sizes[0] = m_;
sizes[1] = k_;
- const TensorMap<Tensor<float, 2, 0, TensorIndex>, Eigen::Aligned> A(a_, sizes);
+ const TensorMap<Tensor<T, 2, 0, TensorIndex>, Eigen::Aligned> A(a_, sizes);
TensorMap<Tensor<int, 2, 0, TensorIndex>, Eigen::Aligned> B((int*)b_, sizes);
StartBenchmarkTiming();
for (int iter = 0; iter < num_iters; ++iter) {
- B.device(device_) = A.cast<int>();
+ B.device(device_) = A.template cast<int>();
}
// Record the number of values copied per second
finalizeBenchmark(static_cast<int64_t>(m_) * k_ * num_iters);
@@ -64,7 +64,7 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> sizes;
sizes[0] = m_;
sizes[1] = m_;
- TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizes);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizes);
StartBenchmarkTiming();
for (int iter = 0; iter < num_iters; ++iter) {
@@ -79,9 +79,9 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> sizes;
sizes[0] = m_;
sizes[1] = m_;
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizes);
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizes);
- TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizes);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizes);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizes);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizes);
const Eigen::DSizes<TensorIndex, 2> quarter_sizes(m_/2, m_/2);
const Eigen::DSizes<TensorIndex, 2> first_quadrant(0, 0);
@@ -109,10 +109,10 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> input_size;
input_size[0] = k_;
input_size[1] = n_;
- const TensorMap<Tensor<float, 2, 0, TensorIndex>, Eigen::Aligned> B(b_, input_size);
+ const TensorMap<Tensor<T, 2, 0, TensorIndex>, Eigen::Aligned> B(b_, input_size);
Eigen::array<TensorIndex, 1> output_size;
output_size[0] = n_;
- TensorMap<Tensor<float, 1, 0, TensorIndex>, Eigen::Aligned> C(c_, output_size);
+ TensorMap<Tensor<T, 1, 0, TensorIndex>, Eigen::Aligned> C(c_, output_size);
StartBenchmarkTiming();
for (int iter = 0; iter < num_iters; ++iter) {
@@ -126,10 +126,10 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> input_size;
input_size[0] = k_;
input_size[1] = n_;
- const TensorMap<Tensor<float, 2, 0, TensorIndex>, Eigen::Aligned> B(b_, input_size);
+ const TensorMap<Tensor<T, 2, 0, TensorIndex>, Eigen::Aligned> B(b_, input_size);
Eigen::array<TensorIndex, 1> output_size;
output_size[0] = n_;
- TensorMap<Tensor<float, 1, 0, TensorIndex>, Eigen::Aligned> C(c_, output_size);
+ TensorMap<Tensor<T, 1, 0, TensorIndex>, Eigen::Aligned> C(c_, output_size);
StartBenchmarkTiming();
for (int iter = 0; iter < num_iters; ++iter) {
@@ -144,11 +144,11 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> size_a;
size_a[0] = m_;
size_a[1] = k_;
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, size_a);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, size_a);
Eigen::array<TensorIndex, 2> size_b;
size_b[0] = k_;
size_b[1] = m_;
- TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, size_b);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, size_b);
Eigen::array<int, 2> shuffle;
shuffle[0] = 1;
@@ -167,11 +167,11 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> size_a;
size_a[0] = m_;
size_a[1] = k_-3;
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, size_a);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, size_a);
Eigen::array<TensorIndex, 2> size_b;
size_b[0] = k_;
size_b[1] = m_;
- TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, size_b);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, size_b);
Eigen::array<Eigen::IndexPair<TensorIndex>, 2> paddings;
paddings[0] = Eigen::IndexPair<TensorIndex>(0, 0);
@@ -190,11 +190,11 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> size_a;
size_a[0] = m_;
size_a[1] = k_;
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, size_a);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, size_a);
Eigen::array<TensorIndex, 2> size_b;
size_b[0] = m_;
size_b[1] = k_/2;
- TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, size_b);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, size_b);
Eigen::array<TensorIndex, 2> strides;
strides[0] = 1;
@@ -212,11 +212,11 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> size_a;
size_a[0] = m_;
size_a[1] = 1;
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, size_a);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, size_a);
Eigen::array<TensorIndex, 2> size_c;
size_c[0] = m_;
size_c[1] = n_;
- TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, size_c);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, size_c);
#ifndef EIGEN_HAS_INDEX_LIST
Eigen::array<int, 2> broadcast;
@@ -242,9 +242,9 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> sizes;
sizes[0] = m_;
sizes[1] = m_;
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizes);
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizes);
- TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizes);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizes);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizes);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizes);
StartBenchmarkTiming();
for (int iter = 0; iter < num_iters; ++iter) {
@@ -260,9 +260,9 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> sizes;
sizes[0] = m_;
sizes[1] = m_;
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizes);
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizes);
- TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizes);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizes);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizes);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizes);
StartBenchmarkTiming();
for (int iter = 0; iter < num_iters; ++iter) {
@@ -278,9 +278,9 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> sizes;
sizes[0] = m_;
sizes[1] = m_;
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizes);
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizes);
- TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizes);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizes);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizes);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizes);
StartBenchmarkTiming();
for (int iter = 0; iter < num_iters; ++iter) {
@@ -296,9 +296,9 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> input_size;
input_size[0] = k_;
input_size[1] = n_;
- const TensorMap<Tensor<float, 2, 0, TensorIndex>, Eigen::Aligned> B(b_, input_size);
+ const TensorMap<Tensor<T, 2, 0, TensorIndex>, Eigen::Aligned> B(b_, input_size);
const Eigen::array<TensorIndex, 1> output_size = {{n_}};
- TensorMap<Tensor<float, 1, 0, TensorIndex>, Eigen::Aligned> C(c_, output_size);
+ TensorMap<Tensor<T, 1, 0, TensorIndex>, Eigen::Aligned> C(c_, output_size);
#ifndef EIGEN_HAS_INDEX_LIST
Eigen::array<TensorIndex, 1> sum_along_dim;
@@ -323,10 +323,10 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> input_size;
input_size[0] = k_;
input_size[1] = n_;
- const TensorMap<Tensor<float, 2, 0, TensorIndex>, Eigen::Aligned> B(
+ const TensorMap<Tensor<T, 2, 0, TensorIndex>, Eigen::Aligned> B(
b_, input_size);
const Eigen::array<TensorIndex, 1> output_size = {{k_}};
- TensorMap<Tensor<float, 1, 0, TensorIndex>, Eigen::Aligned> C(
+ TensorMap<Tensor<T, 1, 0, TensorIndex>, Eigen::Aligned> C(
c_, output_size);
#ifndef EIGEN_HAS_INDEX_LIST
@@ -359,11 +359,11 @@ template <typename Device> class BenchmarkSuite {
sizeC[0] = m_;
sizeC[1] = n_;
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizeA);
- const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizeB);
- TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizeC);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizeA);
+ const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizeB);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizeC);
- typedef typename Tensor<float, 2>::DimensionPair DimPair;
+ typedef typename Tensor<T, 2>::DimensionPair DimPair;
Eigen::array<DimPair, 1> dims;
dims[0] = DimPair(1, 0);
@@ -380,16 +380,16 @@ template <typename Device> class BenchmarkSuite {
Eigen::array<TensorIndex, 2> input_sizes;
input_sizes[0] = m_;
input_sizes[1] = n_;
- TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, input_sizes);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, input_sizes);
Eigen::array<TensorIndex, 2> kernel_sizes;
kernel_sizes[0] = kernel_x;
kernel_sizes[1] = kernel_y;
- TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, kernel_sizes);
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, kernel_sizes);
Eigen::array<TensorIndex, 2> result_sizes;
result_sizes[0] = m_ - kernel_x + 1;
result_sizes[1] = n_ - kernel_y + 1;
- TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, result_sizes);
- Eigen::array<Tensor<float, 2>::Index, 2> dims;
+ TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, result_sizes);
+ Eigen::array<TensorIndex, 2> dims;
dims[0] = 0;
dims[1] = 1;
@@ -405,15 +405,15 @@ template <typename Device> class BenchmarkSuite {
private:
void initialize() {
- a_ = (float *) device_.allocate(m_ * k_ * sizeof(float));
- b_ = (float *) device_.allocate(k_ * n_ * sizeof(float));
- c_ = (float *) device_.allocate(m_ * n_ * sizeof(float));
+ a_ = (T *) device_.allocate(m_ * k_ * sizeof(T));
+ b_ = (T *) device_.allocate(k_ * n_ * sizeof(T));
+ c_ = (T *) device_.allocate(m_ * n_ * sizeof(T));
// Initialize the content of the memory pools to prevent asan from
// complaining.
- device_.memset(a_, 12, m_ * k_ * sizeof(float));
- device_.memset(b_, 23, k_ * n_ * sizeof(float));
- device_.memset(c_, 31, m_ * n_ * sizeof(float));
+ device_.memset(a_, 12, m_ * k_ * sizeof(T));
+ device_.memset(b_, 23, k_ * n_ * sizeof(T));
+ device_.memset(c_, 31, m_ * n_ * sizeof(T));
//BenchmarkUseRealTime();
}
@@ -432,9 +432,9 @@ template <typename Device> class BenchmarkSuite {
TensorIndex m_;
TensorIndex k_;
TensorIndex n_;
- float* a_;
- float* b_;
- float* c_;
+ T* a_;
+ T* b_;
+ T* c_;
Device device_;
};
#endif // THIRD_PARTY_EIGEN3_TENSOR_BENCHMARKS_H_
diff --git a/bench/tensors/tensor_benchmarks_cpu.cc b/bench/tensors/tensor_benchmarks_cpu.cc
index 6754e1a32..8947f4b7f 100644
--- a/bench/tensors/tensor_benchmarks_cpu.cc
+++ b/bench/tensors/tensor_benchmarks_cpu.cc
@@ -9,13 +9,13 @@ Eigen::ThreadPool pool(threads); \
Eigen::ThreadPoolDevice device(&pool, threads);
// Simple functions
-#define BM_FuncCPU(FUNC, THREADS) \
- static void BM_##FUNC##_##THREADS##T(int iters, int N) { \
- StopBenchmarkTiming(); \
- CREATE_THREAD_POOL(THREADS); \
- BenchmarkSuite<Eigen::ThreadPoolDevice> suite(device, N); \
- suite.FUNC(iters); \
- } \
+#define BM_FuncCPU(FUNC, THREADS) \
+ static void BM_##FUNC##_##THREADS##T(int iters, int N) { \
+ StopBenchmarkTiming(); \
+ CREATE_THREAD_POOL(THREADS); \
+ BenchmarkSuite<Eigen::ThreadPoolDevice, float> suite(device, N); \
+ suite.FUNC(iters); \
+ } \
BENCHMARK_RANGE(BM_##FUNC##_##THREADS##T, 10, 5000);
BM_FuncCPU(memcpy, 4);
@@ -80,19 +80,19 @@ BM_FuncCPU(colReduction, 12);
// Contractions
-#define BM_FuncWithInputDimsCPU(FUNC, D1, D2, D3, THREADS) \
- static void BM_##FUNC##_##D1##x##D2##x##D3##_##THREADS##T(int iters, int N) {\
- StopBenchmarkTiming(); \
- if (THREADS == 1) { \
- Eigen::DefaultDevice device; \
- BenchmarkSuite<Eigen::DefaultDevice> suite(device, D1, D2, D3); \
- suite.FUNC(iters); \
- } else { \
- CREATE_THREAD_POOL(THREADS); \
- BenchmarkSuite<Eigen::ThreadPoolDevice> suite(device, D1, D2, D3); \
- suite.FUNC(iters); \
- } \
- } \
+#define BM_FuncWithInputDimsCPU(FUNC, D1, D2, D3, THREADS) \
+ static void BM_##FUNC##_##D1##x##D2##x##D3##_##THREADS##T(int iters, int N) { \
+ StopBenchmarkTiming(); \
+ if (THREADS == 1) { \
+ Eigen::DefaultDevice device; \
+ BenchmarkSuite<Eigen::DefaultDevice, float> suite(device, D1, D2, D3); \
+ suite.FUNC(iters); \
+ } else { \
+ CREATE_THREAD_POOL(THREADS); \
+ BenchmarkSuite<Eigen::ThreadPoolDevice, float> suite(device, D1, D2, D3); \
+ suite.FUNC(iters); \
+ } \
+ } \
BENCHMARK_RANGE(BM_##FUNC##_##D1##x##D2##x##D3##_##THREADS##T, 10, 5000);
@@ -138,7 +138,7 @@ BM_FuncWithInputDimsCPU(contraction, N, N, 1, 16);
static void BM_##FUNC##_##DIM1##x##DIM2##_##THREADS##T(int iters, int N) { \
StopBenchmarkTiming(); \
CREATE_THREAD_POOL(THREADS); \
- BenchmarkSuite<Eigen::ThreadPoolDevice> suite(device, N); \
+ BenchmarkSuite<Eigen::ThreadPoolDevice, float> suite(device, N); \
suite.FUNC(iters, DIM1, DIM2); \
} \
BENCHMARK_RANGE(BM_##FUNC##_##DIM1##x##DIM2##_##THREADS##T, 128, 5000);
diff --git a/bench/tensors/tensor_benchmarks_gpu.cu b/bench/tensors/tensor_benchmarks_gpu.cu
index 611e8197b..a6f594382 100644
--- a/bench/tensors/tensor_benchmarks_gpu.cu
+++ b/bench/tensors/tensor_benchmarks_gpu.cu
@@ -12,7 +12,7 @@
StopBenchmarkTiming(); \
Eigen::CudaStreamDevice stream; \
Eigen::GpuDevice device(&stream); \
- BenchmarkSuite<Eigen::GpuDevice> suite(device, N); \
+ BenchmarkSuite<Eigen::GpuDevice, float> suite(device, N); \
cudaDeviceSynchronize(); \
suite.FUNC(iters); \
} \
@@ -41,7 +41,7 @@ BM_FuncGPU(colReduction);
StopBenchmarkTiming(); \
Eigen::CudaStreamDevice stream; \
Eigen::GpuDevice device(&stream); \
- BenchmarkSuite<Eigen::GpuDevice> suite(device, D1, D2, D3); \
+ BenchmarkSuite<Eigen::GpuDevice, float> suite(device, D1, D2, D3); \
cudaDeviceSynchronize(); \
suite.FUNC(iters); \
} \
@@ -60,7 +60,7 @@ BM_FuncWithInputDimsGPU(contraction, N, N, 64);
StopBenchmarkTiming(); \
Eigen::CudaStreamDevice stream; \
Eigen::GpuDevice device(&stream); \
- BenchmarkSuite<Eigen::GpuDevice> suite(device, N); \
+ BenchmarkSuite<Eigen::GpuDevice, float> suite(device, N); \
cudaDeviceSynchronize(); \
suite.FUNC(iters, DIM1, DIM2); \
} \