aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_test.cc
diff options
context:
space:
mode:
authorGravatar Eugene Brevdo <ebrevdo@gmail.com>2016-02-12 19:33:52 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-02-14 23:14:43 -0800
commit7824e4043ee5229a6872a54a2ba11caf865610bd (patch)
treef1c3d7cf150a68d7820c75a1017415358d1ce2f2 /tensorflow/core/kernels/sparse_tensor_dense_matmul_op_test.cc
parent31973b38cbdeda9ba1f6151f8dbbca4fca7fa1c3 (diff)
Added SparseDenseMatMul Op.
Benchmarks: $ .../tensorflow/python/sparse_tensor_dense_matmul_op_test --benchmarks DenseDense MatMul (w/ Sparse Flag) vs. SparseDense MatMul Matrix sizes: A sparse [m, k] with % nonzero values between 1% and 80% B dense [k, n] % nonzero n gpu m k dt(dense) dt(sparse) dt(sparse)/dt(dense) 0.01 1 True 100 100 0.000198262 9.8618e-05 0.497413 0.01 1 True 100 1000 0.000308075 9.71129e-05 0.315225 0.01 1 True 1000 100 0.000297211 9.97391e-05 0.335583 0.01 1 True 1000 1000 0.000749049 0.00011149 0.148842 0.01 1 False 100 100 0.000207866 9.79061e-05 0.471006 0.01 1 False 100 1000 0.000306979 9.8314e-05 0.320263 0.01 1 False 1000 100 0.000297263 9.7379e-05 0.327585 0.01 1 False 1000 1000 0.000858516 0.000112162 0.130647 0.01 10 True 100 100 0.000201347 9.71699e-05 0.482599 0.01 10 True 100 1000 0.00031786 0.000132792 0.417769 0.01 10 True 1000 100 0.000309127 0.000128658 0.416198 0.01 10 True 1000 1000 0.000779245 0.000133656 0.17152 0.01 10 False 100 100 0.000204979 9.80191e-05 0.478191 0.01 10 False 100 1000 0.000313234 0.000147974 0.472406 0.01 10 False 1000 100 0.00030785 0.000128056 0.415969 0.01 10 False 1000 1000 0.000797414 0.00013211 0.165673 0.01 25 True 100 100 0.000207293 0.000120325 0.580458 0.01 25 True 100 1000 0.000323452 0.000144444 0.44657 0.01 25 True 1000 100 0.000380279 0.000160515 0.422098 0.01 25 True 1000 1000 0.000859035 0.000211458 0.246158 0.01 25 False 100 100 0.000209623 0.000121898 0.58151 0.01 25 False 100 1000 0.000323748 0.000142495 0.440142 0.01 25 False 1000 100 0.000382699 0.000160281 0.418818 0.01 25 False 1000 1000 0.000840479 0.000211661 0.251834 0.2 1 True 100 100 0.000204974 9.70461e-05 0.473455 0.2 1 True 100 1000 0.000346863 0.000153119 0.441439 0.2 1 True 1000 100 0.000320219 0.000115405 0.360393 0.2 1 True 1000 1000 0.00100825 0.000204601 0.202927 0.2 1 False 100 100 0.000216355 9.8609e-05 0.455774 0.2 1 False 100 1000 0.000346128 0.000153136 0.442426 0.2 1 False 1000 100 0.000352324 0.00011737 0.333131 0.2 1 False 1000 1000 0.000990642 0.000205285 0.207224 0.2 10 True 100 100 0.000210795 0.000123959 0.588055 0.2 10 True 100 1000 0.000389961 0.000163421 0.41907 0.2 10 True 1000 100 0.000337358 0.000150689 0.446674 0.2 10 True 1000 1000 0.00108544 0.000857206 0.789729 0.2 10 False 100 100 0.000211931 0.000122924 0.580019 0.2 10 False 100 1000 0.00038925 0.000165562 0.425336 0.2 10 False 1000 100 0.000334816 0.000151162 0.451478 0.2 10 False 1000 1000 0.00109655 0.000843113 0.768877 0.2 25 True 100 100 0.000220397 0.000142263 0.645486 0.2 25 True 100 1000 0.000401368 0.000302446 0.753538 0.2 25 True 1000 100 0.000410934 0.000279523 0.680214 0.2 25 True 1000 1000 0.00127376 0.00244192 1.9171 0.2 25 False 100 100 0.000222309 0.000142203 0.639663 0.2 25 False 100 1000 0.000408741 0.000304749 0.745579 0.2 25 False 1000 100 0.000419264 0.000307255 0.732844 0.2 25 False 1000 1000 0.00126944 0.00249004 1.96152 0.5 1 True 100 100 0.00023428 0.000102918 0.439295 0.5 1 True 100 1000 0.000427166 0.000237494 0.555976 0.5 1 True 1000 100 0.000380724 0.00012818 0.336674 0.5 1 True 1000 1000 0.00160976 0.000481297 0.298987 0.5 1 False 100 100 0.000222527 0.000103388 0.464609 0.5 1 False 100 1000 0.000411102 0.000228725 0.556371 0.5 1 False 1000 100 0.000355794 0.000123535 0.347209 0.5 1 False 1000 1000 0.00141619 0.000490552 0.346388 0.5 10 True 100 100 0.000227675 0.000122795 0.539343 0.5 10 True 100 1000 0.000457623 0.000332977 0.727623 0.5 10 True 1000 100 0.000383134 0.000230231 0.600915 0.5 10 True 1000 1000 0.00156323 0.00226315 1.44774 0.5 10 False 100 100 0.000229292 0.000123618 0.539129 0.5 10 False 100 1000 0.000472363 0.000333602 0.706241 0.5 10 False 1000 100 0.000377634 0.000231078 0.61191 0.5 10 False 1000 1000 0.00157633 0.00225711 1.43188 0.5 25 True 100 100 0.000233055 0.00016205 0.695329 0.5 25 True 100 1000 0.000494024 0.000650206 1.31614 0.5 25 True 1000 100 0.00045893 0.000600457 1.30838 0.5 25 True 1000 1000 0.00186364 0.00606201 3.25278 0.5 25 False 100 100 0.000228475 0.00016268 0.712026 0.5 25 False 100 1000 0.000493242 0.000646534 1.31078 0.5 25 False 1000 100 0.000460567 0.000595119 1.29214 0.5 25 False 1000 1000 0.00167901 0.00613069 3.65137 0.8 1 True 100 100 0.000217078 0.000122763 0.565525 0.8 1 True 100 1000 0.000427521 0.000351477 0.822128 0.8 1 True 1000 100 0.0003469 0.000141773 0.408685 0.8 1 True 1000 1000 0.00148282 0.000691401 0.466273 0.8 1 False 100 100 0.000213548 0.000123152 0.576695 0.8 1 False 100 1000 0.000439499 0.000354205 0.805929 0.8 1 False 1000 100 0.000374365 0.000143963 0.384552 0.8 1 False 1000 1000 0.00138026 0.000737316 0.534186 0.8 10 True 100 100 0.000225083 0.00012419 0.551751 0.8 10 True 100 1000 0.000497607 0.000566593 1.13864 0.8 10 True 1000 100 0.000380098 0.000323333 0.850657 0.8 10 True 1000 1000 0.00164113 0.00375094 2.28558 0.8 10 False 100 100 0.00023011 0.0001231 0.534962 0.8 10 False 100 1000 0.000497115 0.000599468 1.20589 0.8 10 False 1000 100 0.000378207 0.000321302 0.849539 0.8 10 False 1000 1000 0.00163274 0.00371959 2.27813 0.8 25 True 100 100 0.000232235 0.000179456 0.772734 0.8 25 True 100 1000 0.000565002 0.00108429 1.91909 0.8 25 True 1000 100 0.000462347 0.000887741 1.92007 0.8 25 True 1000 1000 0.00187698 0.0105369 5.61375 0.8 25 False 100 100 0.00024654 0.000194484 0.788853 0.8 25 False 100 1000 0.000572626 0.00111752 1.95156 0.8 25 False 1000 100 0.000471096 0.000893812 1.8973 0.8 25 False 1000 1000 0.00188041 0.0104448 5.55452 Change: 114590991
Diffstat (limited to 'tensorflow/core/kernels/sparse_tensor_dense_matmul_op_test.cc')
-rw-r--r--tensorflow/core/kernels/sparse_tensor_dense_matmul_op_test.cc120
1 files changed, 120 insertions, 0 deletions
diff --git a/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_test.cc b/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_test.cc
new file mode 100644
index 0000000000..47295eabdc
--- /dev/null
+++ b/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_test.cc
@@ -0,0 +1,120 @@
+/* Copyright 2015 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+#include <random>
+
+#include "tensorflow/core/common_runtime/kernel_benchmark_testlib.h"
+#include "tensorflow/core/framework/tensor.h"
+#include "tensorflow/core/graph/node_builder.h"
+#include "tensorflow/core/platform/test.h"
+#include "tensorflow/core/platform/test_benchmark.h"
+
+namespace tensorflow {
+
+Node* SparseTensorDenseMatMulNode(Graph* g, Node* a_indices, Node* a_values,
+ Node* a_shape, Node* b, bool adjoint_a,
+ bool adjoint_b) {
+ Node* ret;
+ TF_CHECK_OK(NodeBuilder(g->NewName("n"), "SparseTensorDenseMatMul")
+ .Input(a_indices)
+ .Input(a_values)
+ .Input(a_shape)
+ .Input(b)
+ .Attr("T", DT_FLOAT)
+ .Attr("adjoint_a", adjoint_a)
+ .Attr("adjoint_b", adjoint_b)
+ .Finalize(g, &ret));
+ return ret;
+}
+
+static Graph* SparseTensorDenseMatmul(int nnz, int m, int k, int n,
+ bool adjoint_a, bool adjoint_b) {
+ Graph* g = new Graph(OpRegistry::Global());
+ Tensor a_values(DT_FLOAT, TensorShape({nnz}));
+ Tensor a_indices(DT_INT64, TensorShape({nnz, 2}));
+ Tensor a_shape(DT_INT64, TensorShape({2}));
+ auto a_shape_t = a_shape.vec<int64>();
+ a_shape_t(0) = adjoint_a ? k : m;
+ a_shape_t(1) = adjoint_a ? m : k;
+ a_values.flat<float>().setRandom();
+ auto a_indices_t = a_indices.matrix<int64>();
+ std::random_device rd;
+ std::mt19937 gen(rd());
+ std::uniform_int_distribution<> a_lhs_dist(0, a_shape_t(0) - 1);
+ std::uniform_int_distribution<> a_rhs_dist(0, a_shape_t(1) - 1);
+ for (int32 i = 0; i < nnz; ++i) {
+ a_indices_t(i, 0) = a_lhs_dist(gen);
+ a_indices_t(i, 1) = a_rhs_dist(gen);
+ }
+ Tensor b(DT_FLOAT, adjoint_b ? TensorShape({n, k}) : TensorShape({k, n}));
+ b.flat<float>().setRandom();
+
+ SparseTensorDenseMatMulNode(
+ g, test::graph::Constant(g, a_indices),
+ test::graph::Constant(g, a_values), test::graph::HostConstant(g, a_shape),
+ test::graph::Constant(g, b), adjoint_a, adjoint_b);
+ return g;
+}
+
+#define BM_SparseTensorDenseMatmulDev(NNZ, M, K, N, TA, TB, DEVICE) \
+ static void \
+ BM_SparseTensorDenseMatmul##_##NNZ##_##M##_##K##_##N##_##TA##_##TB##_##DEVICE( \
+ int iters) { \
+ int64 items_per_iter = (static_cast<int64>(NNZ) * (TB ? K : N)); \
+ testing::ItemsProcessed(static_cast<int64>(iters) * items_per_iter); \
+ testing::BytesProcessed(static_cast<int64>(iters) * items_per_iter * \
+ sizeof(float)); \
+ test::Benchmark(#DEVICE, SparseTensorDenseMatmul(NNZ, M, K, N, TA, TB)) \
+ .Run(iters); \
+ } \
+ BENCHMARK( \
+ BM_SparseTensorDenseMatmul##_##NNZ##_##M##_##K##_##N##_##TA##_##TB##_##DEVICE);
+
+#define BM_SparseTensorDenseMatmul(NNZ, M, K, N, TA, TB) \
+ BM_SparseTensorDenseMatmulDev(NNZ, M, K, N, TA, TB, cpu); \
+ BM_SparseTensorDenseMatmulDev(NNZ, M, K, N, TA, TB, gpu);
+
+BM_SparseTensorDenseMatmul(128, 8, 512, 1, false, false);
+BM_SparseTensorDenseMatmul(128, 16, 512, 1, false, false);
+BM_SparseTensorDenseMatmul(128, 128, 512, 1, false, false);
+
+BM_SparseTensorDenseMatmul(128, 4096, 4096, 1, false, false);
+BM_SparseTensorDenseMatmul(1024, 4096, 4096, 1, false, false);
+BM_SparseTensorDenseMatmul(16384, 4096, 4096, 1, false, false);
+
+BM_SparseTensorDenseMatmul(128, 8, 1024, 16, false, false);
+BM_SparseTensorDenseMatmul(128, 16, 1024, 16, false, false);
+BM_SparseTensorDenseMatmul(128, 128, 1024, 16, false, false);
+BM_SparseTensorDenseMatmul(128, 4096, 4096, 128, false, false);
+BM_SparseTensorDenseMatmul(128, 4096, 4096, 1024, false, false);
+
+BM_SparseTensorDenseMatmul(1024, 8, 1024, 16, false, false);
+BM_SparseTensorDenseMatmul(1024, 16, 1024, 16, false, false);
+BM_SparseTensorDenseMatmul(1024, 128, 1024, 16, false, false);
+BM_SparseTensorDenseMatmul(1024, 4096, 4096, 128, false, false);
+BM_SparseTensorDenseMatmul(1024, 4096, 4096, 1024, false, false);
+
+BM_SparseTensorDenseMatmul(16384, 8, 1024, 16, false, false);
+BM_SparseTensorDenseMatmul(16384, 16, 1024, 16, false, false);
+BM_SparseTensorDenseMatmul(16384, 128, 1024, 16, false, false);
+BM_SparseTensorDenseMatmul(16384, 4096, 4096, 128, false, false);
+BM_SparseTensorDenseMatmul(16384, 4096, 4096, 1024, false, false);
+
+BM_SparseTensorDenseMatmul(16384, 4096, 4096, 4096, false, false);
+BM_SparseTensorDenseMatmul(16384, 4096, 4096, 4096, false, true);
+BM_SparseTensorDenseMatmul(16384, 4096, 4096, 4096, true, false);
+BM_SparseTensorDenseMatmul(16384, 4096, 4096, 4096, true, true);
+
+} // end namespace tensorflow