mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 04:35:57 +08:00
Extended the tensor benchmark suite to support types other than floats
This commit is contained in:
parent
f442a5a5b3
commit
8cb9bfab87
@ -15,7 +15,7 @@ using Eigen::TensorMap;
|
|||||||
|
|
||||||
// TODO(bsteiner): also templatize on the input type since we have users
|
// TODO(bsteiner): also templatize on the input type since we have users
|
||||||
// for int8 as well as floats.
|
// for int8 as well as floats.
|
||||||
template <typename Device> class BenchmarkSuite {
|
template <typename Device, typename T> class BenchmarkSuite {
|
||||||
public:
|
public:
|
||||||
BenchmarkSuite(const Device& device, size_t m, size_t k, size_t n)
|
BenchmarkSuite(const Device& device, size_t m, size_t k, size_t n)
|
||||||
: m_(m), k_(k), n_(n), device_(device) {
|
: m_(m), k_(k), n_(n), device_(device) {
|
||||||
@ -37,7 +37,7 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
eigen_assert(m_ == k_ && k_ == n_);
|
eigen_assert(m_ == k_ && k_ == n_);
|
||||||
StartBenchmarkTiming();
|
StartBenchmarkTiming();
|
||||||
for (int iter = 0; iter < num_iters; ++iter) {
|
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
|
// Record the number of values copied per second
|
||||||
finalizeBenchmark(static_cast<int64_t>(m_) * m_ * num_iters);
|
finalizeBenchmark(static_cast<int64_t>(m_) * m_ * num_iters);
|
||||||
@ -48,12 +48,12 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> sizes;
|
Eigen::array<TensorIndex, 2> sizes;
|
||||||
sizes[0] = m_;
|
sizes[0] = m_;
|
||||||
sizes[1] = k_;
|
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);
|
TensorMap<Tensor<int, 2, 0, TensorIndex>, Eigen::Aligned> B((int*)b_, sizes);
|
||||||
|
|
||||||
StartBenchmarkTiming();
|
StartBenchmarkTiming();
|
||||||
for (int iter = 0; iter < num_iters; ++iter) {
|
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
|
// Record the number of values copied per second
|
||||||
finalizeBenchmark(static_cast<int64_t>(m_) * k_ * num_iters);
|
finalizeBenchmark(static_cast<int64_t>(m_) * k_ * num_iters);
|
||||||
@ -64,7 +64,7 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> sizes;
|
Eigen::array<TensorIndex, 2> sizes;
|
||||||
sizes[0] = m_;
|
sizes[0] = m_;
|
||||||
sizes[1] = m_;
|
sizes[1] = m_;
|
||||||
TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizes);
|
TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizes);
|
||||||
|
|
||||||
StartBenchmarkTiming();
|
StartBenchmarkTiming();
|
||||||
for (int iter = 0; iter < num_iters; ++iter) {
|
for (int iter = 0; iter < num_iters; ++iter) {
|
||||||
@ -79,9 +79,9 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> sizes;
|
Eigen::array<TensorIndex, 2> sizes;
|
||||||
sizes[0] = m_;
|
sizes[0] = m_;
|
||||||
sizes[1] = m_;
|
sizes[1] = m_;
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizes);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizes);
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizes);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizes);
|
||||||
TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, 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> quarter_sizes(m_/2, m_/2);
|
||||||
const Eigen::DSizes<TensorIndex, 2> first_quadrant(0, 0);
|
const Eigen::DSizes<TensorIndex, 2> first_quadrant(0, 0);
|
||||||
@ -109,10 +109,10 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> input_size;
|
Eigen::array<TensorIndex, 2> input_size;
|
||||||
input_size[0] = k_;
|
input_size[0] = k_;
|
||||||
input_size[1] = n_;
|
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;
|
Eigen::array<TensorIndex, 1> output_size;
|
||||||
output_size[0] = n_;
|
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();
|
StartBenchmarkTiming();
|
||||||
for (int iter = 0; iter < num_iters; ++iter) {
|
for (int iter = 0; iter < num_iters; ++iter) {
|
||||||
@ -126,10 +126,10 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> input_size;
|
Eigen::array<TensorIndex, 2> input_size;
|
||||||
input_size[0] = k_;
|
input_size[0] = k_;
|
||||||
input_size[1] = n_;
|
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;
|
Eigen::array<TensorIndex, 1> output_size;
|
||||||
output_size[0] = n_;
|
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();
|
StartBenchmarkTiming();
|
||||||
for (int iter = 0; iter < num_iters; ++iter) {
|
for (int iter = 0; iter < num_iters; ++iter) {
|
||||||
@ -144,11 +144,11 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> size_a;
|
Eigen::array<TensorIndex, 2> size_a;
|
||||||
size_a[0] = m_;
|
size_a[0] = m_;
|
||||||
size_a[1] = k_;
|
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;
|
Eigen::array<TensorIndex, 2> size_b;
|
||||||
size_b[0] = k_;
|
size_b[0] = k_;
|
||||||
size_b[1] = m_;
|
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;
|
Eigen::array<int, 2> shuffle;
|
||||||
shuffle[0] = 1;
|
shuffle[0] = 1;
|
||||||
@ -167,11 +167,11 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> size_a;
|
Eigen::array<TensorIndex, 2> size_a;
|
||||||
size_a[0] = m_;
|
size_a[0] = m_;
|
||||||
size_a[1] = k_-3;
|
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;
|
Eigen::array<TensorIndex, 2> size_b;
|
||||||
size_b[0] = k_;
|
size_b[0] = k_;
|
||||||
size_b[1] = m_;
|
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;
|
Eigen::array<Eigen::IndexPair<TensorIndex>, 2> paddings;
|
||||||
paddings[0] = Eigen::IndexPair<TensorIndex>(0, 0);
|
paddings[0] = Eigen::IndexPair<TensorIndex>(0, 0);
|
||||||
@ -190,11 +190,11 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> size_a;
|
Eigen::array<TensorIndex, 2> size_a;
|
||||||
size_a[0] = m_;
|
size_a[0] = m_;
|
||||||
size_a[1] = k_;
|
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;
|
Eigen::array<TensorIndex, 2> size_b;
|
||||||
size_b[0] = m_;
|
size_b[0] = m_;
|
||||||
size_b[1] = k_/2;
|
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;
|
Eigen::array<TensorIndex, 2> strides;
|
||||||
strides[0] = 1;
|
strides[0] = 1;
|
||||||
@ -212,11 +212,11 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> size_a;
|
Eigen::array<TensorIndex, 2> size_a;
|
||||||
size_a[0] = m_;
|
size_a[0] = m_;
|
||||||
size_a[1] = 1;
|
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;
|
Eigen::array<TensorIndex, 2> size_c;
|
||||||
size_c[0] = m_;
|
size_c[0] = m_;
|
||||||
size_c[1] = n_;
|
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
|
#ifndef EIGEN_HAS_INDEX_LIST
|
||||||
Eigen::array<int, 2> broadcast;
|
Eigen::array<int, 2> broadcast;
|
||||||
@ -242,9 +242,9 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> sizes;
|
Eigen::array<TensorIndex, 2> sizes;
|
||||||
sizes[0] = m_;
|
sizes[0] = m_;
|
||||||
sizes[1] = m_;
|
sizes[1] = m_;
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizes);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizes);
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizes);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizes);
|
||||||
TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizes);
|
TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizes);
|
||||||
|
|
||||||
StartBenchmarkTiming();
|
StartBenchmarkTiming();
|
||||||
for (int iter = 0; iter < num_iters; ++iter) {
|
for (int iter = 0; iter < num_iters; ++iter) {
|
||||||
@ -260,9 +260,9 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> sizes;
|
Eigen::array<TensorIndex, 2> sizes;
|
||||||
sizes[0] = m_;
|
sizes[0] = m_;
|
||||||
sizes[1] = m_;
|
sizes[1] = m_;
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizes);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizes);
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizes);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizes);
|
||||||
TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizes);
|
TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizes);
|
||||||
|
|
||||||
StartBenchmarkTiming();
|
StartBenchmarkTiming();
|
||||||
for (int iter = 0; iter < num_iters; ++iter) {
|
for (int iter = 0; iter < num_iters; ++iter) {
|
||||||
@ -278,9 +278,9 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> sizes;
|
Eigen::array<TensorIndex, 2> sizes;
|
||||||
sizes[0] = m_;
|
sizes[0] = m_;
|
||||||
sizes[1] = m_;
|
sizes[1] = m_;
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizes);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizes);
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizes);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizes);
|
||||||
TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizes);
|
TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, sizes);
|
||||||
|
|
||||||
StartBenchmarkTiming();
|
StartBenchmarkTiming();
|
||||||
for (int iter = 0; iter < num_iters; ++iter) {
|
for (int iter = 0; iter < num_iters; ++iter) {
|
||||||
@ -296,9 +296,9 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> input_size;
|
Eigen::array<TensorIndex, 2> input_size;
|
||||||
input_size[0] = k_;
|
input_size[0] = k_;
|
||||||
input_size[1] = n_;
|
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_}};
|
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
|
#ifndef EIGEN_HAS_INDEX_LIST
|
||||||
Eigen::array<TensorIndex, 1> sum_along_dim;
|
Eigen::array<TensorIndex, 1> sum_along_dim;
|
||||||
@ -323,10 +323,10 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> input_size;
|
Eigen::array<TensorIndex, 2> input_size;
|
||||||
input_size[0] = k_;
|
input_size[0] = k_;
|
||||||
input_size[1] = n_;
|
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);
|
b_, input_size);
|
||||||
const Eigen::array<TensorIndex, 1> output_size = {{k_}};
|
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);
|
c_, output_size);
|
||||||
|
|
||||||
#ifndef EIGEN_HAS_INDEX_LIST
|
#ifndef EIGEN_HAS_INDEX_LIST
|
||||||
@ -359,11 +359,11 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
sizeC[0] = m_;
|
sizeC[0] = m_;
|
||||||
sizeC[1] = n_;
|
sizeC[1] = n_;
|
||||||
|
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> A(a_, sizeA);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> A(a_, sizeA);
|
||||||
const TensorMap<Tensor<float, 2>, Eigen::Aligned> B(b_, sizeB);
|
const TensorMap<Tensor<T, 2>, Eigen::Aligned> B(b_, sizeB);
|
||||||
TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, sizeC);
|
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;
|
Eigen::array<DimPair, 1> dims;
|
||||||
dims[0] = DimPair(1, 0);
|
dims[0] = DimPair(1, 0);
|
||||||
|
|
||||||
@ -380,16 +380,16 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
Eigen::array<TensorIndex, 2> input_sizes;
|
Eigen::array<TensorIndex, 2> input_sizes;
|
||||||
input_sizes[0] = m_;
|
input_sizes[0] = m_;
|
||||||
input_sizes[1] = n_;
|
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;
|
Eigen::array<TensorIndex, 2> kernel_sizes;
|
||||||
kernel_sizes[0] = kernel_x;
|
kernel_sizes[0] = kernel_x;
|
||||||
kernel_sizes[1] = kernel_y;
|
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;
|
Eigen::array<TensorIndex, 2> result_sizes;
|
||||||
result_sizes[0] = m_ - kernel_x + 1;
|
result_sizes[0] = m_ - kernel_x + 1;
|
||||||
result_sizes[1] = n_ - kernel_y + 1;
|
result_sizes[1] = n_ - kernel_y + 1;
|
||||||
TensorMap<Tensor<float, 2>, Eigen::Aligned> C(c_, result_sizes);
|
TensorMap<Tensor<T, 2>, Eigen::Aligned> C(c_, result_sizes);
|
||||||
Eigen::array<Tensor<float, 2>::Index, 2> dims;
|
Eigen::array<TensorIndex, 2> dims;
|
||||||
dims[0] = 0;
|
dims[0] = 0;
|
||||||
dims[1] = 1;
|
dims[1] = 1;
|
||||||
|
|
||||||
@ -405,15 +405,15 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void initialize() {
|
void initialize() {
|
||||||
a_ = (float *) device_.allocate(m_ * k_ * sizeof(float));
|
a_ = (T *) device_.allocate(m_ * k_ * sizeof(T));
|
||||||
b_ = (float *) device_.allocate(k_ * n_ * sizeof(float));
|
b_ = (T *) device_.allocate(k_ * n_ * sizeof(T));
|
||||||
c_ = (float *) device_.allocate(m_ * n_ * sizeof(float));
|
c_ = (T *) device_.allocate(m_ * n_ * sizeof(T));
|
||||||
|
|
||||||
// Initialize the content of the memory pools to prevent asan from
|
// Initialize the content of the memory pools to prevent asan from
|
||||||
// complaining.
|
// complaining.
|
||||||
device_.memset(a_, 12, m_ * k_ * sizeof(float));
|
device_.memset(a_, 12, m_ * k_ * sizeof(T));
|
||||||
device_.memset(b_, 23, k_ * n_ * sizeof(float));
|
device_.memset(b_, 23, k_ * n_ * sizeof(T));
|
||||||
device_.memset(c_, 31, m_ * n_ * sizeof(float));
|
device_.memset(c_, 31, m_ * n_ * sizeof(T));
|
||||||
|
|
||||||
//BenchmarkUseRealTime();
|
//BenchmarkUseRealTime();
|
||||||
}
|
}
|
||||||
@ -432,9 +432,9 @@ template <typename Device> class BenchmarkSuite {
|
|||||||
TensorIndex m_;
|
TensorIndex m_;
|
||||||
TensorIndex k_;
|
TensorIndex k_;
|
||||||
TensorIndex n_;
|
TensorIndex n_;
|
||||||
float* a_;
|
T* a_;
|
||||||
float* b_;
|
T* b_;
|
||||||
float* c_;
|
T* c_;
|
||||||
Device device_;
|
Device device_;
|
||||||
};
|
};
|
||||||
#endif // THIRD_PARTY_EIGEN3_TENSOR_BENCHMARKS_H_
|
#endif // THIRD_PARTY_EIGEN3_TENSOR_BENCHMARKS_H_
|
||||||
|
@ -9,13 +9,13 @@ Eigen::ThreadPool pool(threads); \
|
|||||||
Eigen::ThreadPoolDevice device(&pool, threads);
|
Eigen::ThreadPoolDevice device(&pool, threads);
|
||||||
|
|
||||||
// Simple functions
|
// Simple functions
|
||||||
#define BM_FuncCPU(FUNC, THREADS) \
|
#define BM_FuncCPU(FUNC, THREADS) \
|
||||||
static void BM_##FUNC##_##THREADS##T(int iters, int N) { \
|
static void BM_##FUNC##_##THREADS##T(int iters, int N) { \
|
||||||
StopBenchmarkTiming(); \
|
StopBenchmarkTiming(); \
|
||||||
CREATE_THREAD_POOL(THREADS); \
|
CREATE_THREAD_POOL(THREADS); \
|
||||||
BenchmarkSuite<Eigen::ThreadPoolDevice> suite(device, N); \
|
BenchmarkSuite<Eigen::ThreadPoolDevice, float> suite(device, N); \
|
||||||
suite.FUNC(iters); \
|
suite.FUNC(iters); \
|
||||||
} \
|
} \
|
||||||
BENCHMARK_RANGE(BM_##FUNC##_##THREADS##T, 10, 5000);
|
BENCHMARK_RANGE(BM_##FUNC##_##THREADS##T, 10, 5000);
|
||||||
|
|
||||||
BM_FuncCPU(memcpy, 4);
|
BM_FuncCPU(memcpy, 4);
|
||||||
@ -80,19 +80,19 @@ BM_FuncCPU(colReduction, 12);
|
|||||||
|
|
||||||
|
|
||||||
// Contractions
|
// Contractions
|
||||||
#define BM_FuncWithInputDimsCPU(FUNC, D1, D2, D3, THREADS) \
|
#define BM_FuncWithInputDimsCPU(FUNC, D1, D2, D3, THREADS) \
|
||||||
static void BM_##FUNC##_##D1##x##D2##x##D3##_##THREADS##T(int iters, int N) {\
|
static void BM_##FUNC##_##D1##x##D2##x##D3##_##THREADS##T(int iters, int N) { \
|
||||||
StopBenchmarkTiming(); \
|
StopBenchmarkTiming(); \
|
||||||
if (THREADS == 1) { \
|
if (THREADS == 1) { \
|
||||||
Eigen::DefaultDevice device; \
|
Eigen::DefaultDevice device; \
|
||||||
BenchmarkSuite<Eigen::DefaultDevice> suite(device, D1, D2, D3); \
|
BenchmarkSuite<Eigen::DefaultDevice, float> suite(device, D1, D2, D3); \
|
||||||
suite.FUNC(iters); \
|
suite.FUNC(iters); \
|
||||||
} else { \
|
} else { \
|
||||||
CREATE_THREAD_POOL(THREADS); \
|
CREATE_THREAD_POOL(THREADS); \
|
||||||
BenchmarkSuite<Eigen::ThreadPoolDevice> suite(device, D1, D2, D3); \
|
BenchmarkSuite<Eigen::ThreadPoolDevice, float> suite(device, D1, D2, D3); \
|
||||||
suite.FUNC(iters); \
|
suite.FUNC(iters); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
BENCHMARK_RANGE(BM_##FUNC##_##D1##x##D2##x##D3##_##THREADS##T, 10, 5000);
|
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) { \
|
static void BM_##FUNC##_##DIM1##x##DIM2##_##THREADS##T(int iters, int N) { \
|
||||||
StopBenchmarkTiming(); \
|
StopBenchmarkTiming(); \
|
||||||
CREATE_THREAD_POOL(THREADS); \
|
CREATE_THREAD_POOL(THREADS); \
|
||||||
BenchmarkSuite<Eigen::ThreadPoolDevice> suite(device, N); \
|
BenchmarkSuite<Eigen::ThreadPoolDevice, float> suite(device, N); \
|
||||||
suite.FUNC(iters, DIM1, DIM2); \
|
suite.FUNC(iters, DIM1, DIM2); \
|
||||||
} \
|
} \
|
||||||
BENCHMARK_RANGE(BM_##FUNC##_##DIM1##x##DIM2##_##THREADS##T, 128, 5000);
|
BENCHMARK_RANGE(BM_##FUNC##_##DIM1##x##DIM2##_##THREADS##T, 128, 5000);
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
StopBenchmarkTiming(); \
|
StopBenchmarkTiming(); \
|
||||||
Eigen::CudaStreamDevice stream; \
|
Eigen::CudaStreamDevice stream; \
|
||||||
Eigen::GpuDevice device(&stream); \
|
Eigen::GpuDevice device(&stream); \
|
||||||
BenchmarkSuite<Eigen::GpuDevice> suite(device, N); \
|
BenchmarkSuite<Eigen::GpuDevice, float> suite(device, N); \
|
||||||
cudaDeviceSynchronize(); \
|
cudaDeviceSynchronize(); \
|
||||||
suite.FUNC(iters); \
|
suite.FUNC(iters); \
|
||||||
} \
|
} \
|
||||||
@ -41,7 +41,7 @@ BM_FuncGPU(colReduction);
|
|||||||
StopBenchmarkTiming(); \
|
StopBenchmarkTiming(); \
|
||||||
Eigen::CudaStreamDevice stream; \
|
Eigen::CudaStreamDevice stream; \
|
||||||
Eigen::GpuDevice device(&stream); \
|
Eigen::GpuDevice device(&stream); \
|
||||||
BenchmarkSuite<Eigen::GpuDevice> suite(device, D1, D2, D3); \
|
BenchmarkSuite<Eigen::GpuDevice, float> suite(device, D1, D2, D3); \
|
||||||
cudaDeviceSynchronize(); \
|
cudaDeviceSynchronize(); \
|
||||||
suite.FUNC(iters); \
|
suite.FUNC(iters); \
|
||||||
} \
|
} \
|
||||||
@ -60,7 +60,7 @@ BM_FuncWithInputDimsGPU(contraction, N, N, 64);
|
|||||||
StopBenchmarkTiming(); \
|
StopBenchmarkTiming(); \
|
||||||
Eigen::CudaStreamDevice stream; \
|
Eigen::CudaStreamDevice stream; \
|
||||||
Eigen::GpuDevice device(&stream); \
|
Eigen::GpuDevice device(&stream); \
|
||||||
BenchmarkSuite<Eigen::GpuDevice> suite(device, N); \
|
BenchmarkSuite<Eigen::GpuDevice, float> suite(device, N); \
|
||||||
cudaDeviceSynchronize(); \
|
cudaDeviceSynchronize(); \
|
||||||
suite.FUNC(iters, DIM1, DIM2); \
|
suite.FUNC(iters, DIM1, DIM2); \
|
||||||
} \
|
} \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user