summaryrefslogtreecommitdiffstats
path: root/eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-10-12 11:28:32 +0000
committerArne Juul <arnej@verizonmedia.com>2020-10-13 08:51:58 +0000
commit679838d8f79aa1cc34527ffdab7f57f54f9277ab (patch)
tree251e956f6186d2920d5f94c2059bbbe431e0829b /eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp
parentef36dfee0259436338751a2d801699b2cdf7fb8c (diff)
benchmark GenericMap also
Diffstat (limited to 'eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp')
-rw-r--r--eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp b/eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp
index e340b5d75b3..27fbbc2eb7a 100644
--- a/eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp
+++ b/eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp
@@ -27,6 +27,7 @@
#include <vespa/eval/instruction/generic_join.h>
#include <vespa/eval/instruction/generic_reduce.h>
#include <vespa/eval/instruction/generic_rename.h>
+#include <vespa/eval/instruction/generic_map.h>
#include <vespa/eval/instruction/generic_merge.h>
#include <vespa/eval/eval/simple_tensor_engine.h>
#include <vespa/eval/eval/tensor_spec.h>
@@ -98,6 +99,12 @@ struct Impl {
const auto &concat_node = tensor_function::concat(lhs_node, rhs_node, dimension, stash);
return concat_node.compile_self(engine, stash);
}
+ Instruction create_map(const ValueType &lhs, operation::op1_t function, Stash &stash) const {
+ // create a complete tensor function, but only compile the relevant instruction
+ const auto &lhs_node = tensor_function::inject(lhs, 0, stash);
+ const auto &map_node = tensor_function::map(lhs_node, function, stash);
+ return map_node.compile_self(engine, stash);
+ }
};
//-----------------------------------------------------------------------------
@@ -321,6 +328,22 @@ void benchmark_merge(const vespalib::string &desc, const TensorSpec &lhs,
//-----------------------------------------------------------------------------
+void benchmark_map(const vespalib::string &desc, const TensorSpec &lhs, operation::op1_t function)
+{
+ Stash stash;
+ ValueType lhs_type = ValueType::from_spec(lhs.type());
+ ASSERT_FALSE(lhs_type.is_error());
+ std::vector<EvalOp::UP> list;
+ for (const Impl &impl: impl_list) {
+ auto op = impl.create_map(lhs_type, function, stash);
+ std::vector<CREF<TensorSpec>> stack_spec({lhs});
+ list.push_back(std::make_unique<EvalOp>(op, stack_spec, impl));
+ }
+ benchmark(desc, list);
+}
+
+//-----------------------------------------------------------------------------
+
void benchmark_concat(const vespalib::string &desc, const TensorSpec &lhs,
const TensorSpec &rhs, const std::string &dimension)
{
@@ -612,6 +635,28 @@ TEST(MergeBench, mixed_merge) {
//-----------------------------------------------------------------------------
+TEST(MapBench, dense_map) {
+ auto lhs = make_matrix(D::idx("a", 64), D::idx("b", 64), 1.75);
+ benchmark_map("dense map", lhs, operation::Floor::f);
+}
+
+TEST(MapBench, sparse_map_small) {
+ auto lhs = make_matrix(D::map("a", 4, 1), D::map("b", 4, 1), 1.75);
+ benchmark_map("sparse map small", lhs, operation::Floor::f);
+}
+
+TEST(MapBench, sparse_map_big_small) {
+ auto lhs = make_matrix(D::map("a", 64, 1), D::map("b", 64, 1), 1.75);
+ benchmark_map("sparse map big", lhs, operation::Floor::f);
+}
+
+TEST(MapBench, mixed_map) {
+ auto lhs = make_matrix(D::map("a", 64, 1), D::idx("b", 64), 1.75);
+ benchmark_map("mixed map", lhs, operation::Floor::f);
+}
+
+//-----------------------------------------------------------------------------
+
void print_results(const vespalib::string &desc, const std::vector<BenchmarkResult> &results) {
if (results.empty()) {
return;