aboutsummaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2018-03-16 10:25:16 +0000
committerHåvard Pettersen <havardpe@oath.com>2018-03-16 10:25:16 +0000
commitb740e9b638e8ec554bc271867e874da6fe1df97c (patch)
treeb68004be450c29af6406411dbb8e7490a643aa40 /eval
parente73ea62e515f6ff1f92928320553e7bfd3888b27 (diff)
'fast rename' is now an optimizer using the 'replace type' function
Diffstat (limited to 'eval')
-rw-r--r--eval/CMakeLists.txt2
-rw-r--r--eval/src/tests/tensor/dense_fast_rename_function/CMakeLists.txt8
-rw-r--r--eval/src/tests/tensor/dense_fast_rename_optimizer/CMakeLists.txt8
-rw-r--r--eval/src/tests/tensor/dense_fast_rename_optimizer/dense_fast_rename_optimizer_test.cpp (renamed from eval/src/tests/tensor/dense_fast_rename_function/dense_fast_rename_function_test.cpp)36
-rw-r--r--eval/src/vespa/eval/tensor/default_tensor_engine.cpp4
-rw-r--r--eval/src/vespa/eval/tensor/dense/CMakeLists.txt2
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_fast_rename_function.h24
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_fast_rename_optimizer.cpp (renamed from eval/src/vespa/eval/tensor/dense/dense_fast_rename_function.cpp)39
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_fast_rename_optimizer.h17
9 files changed, 46 insertions, 94 deletions
diff --git a/eval/CMakeLists.txt b/eval/CMakeLists.txt
index 0a2ca730ec8..faa94fd6719 100644
--- a/eval/CMakeLists.txt
+++ b/eval/CMakeLists.txt
@@ -26,7 +26,7 @@ vespa_define_module(
src/tests/eval/value_type
src/tests/gp/ponder_nov2017
src/tests/tensor/dense_dot_product_function
- src/tests/tensor/dense_fast_rename_function
+ src/tests/tensor/dense_fast_rename_optimizer
src/tests/tensor/dense_inplace_join_function
src/tests/tensor/dense_inplace_map_function
src/tests/tensor/dense_replace_type_function
diff --git a/eval/src/tests/tensor/dense_fast_rename_function/CMakeLists.txt b/eval/src/tests/tensor/dense_fast_rename_function/CMakeLists.txt
deleted file mode 100644
index a5c3b223ce5..00000000000
--- a/eval/src/tests/tensor/dense_fast_rename_function/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-vespa_add_executable(eval_dense_fast_rename_function_test_app TEST
- SOURCES
- dense_fast_rename_function_test.cpp
- DEPENDS
- vespaeval
-)
-vespa_add_test(NAME eval_dense_fast_rename_function_test_app COMMAND eval_dense_fast_rename_function_test_app)
diff --git a/eval/src/tests/tensor/dense_fast_rename_optimizer/CMakeLists.txt b/eval/src/tests/tensor/dense_fast_rename_optimizer/CMakeLists.txt
new file mode 100644
index 00000000000..32cf6c45d1e
--- /dev/null
+++ b/eval/src/tests/tensor/dense_fast_rename_optimizer/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(eval_dense_fast_rename_optimizer_test_app TEST
+ SOURCES
+ dense_fast_rename_optimizer_test.cpp
+ DEPENDS
+ vespaeval
+)
+vespa_add_test(NAME eval_dense_fast_rename_optimizer_test_app COMMAND eval_dense_fast_rename_optimizer_test_app)
diff --git a/eval/src/tests/tensor/dense_fast_rename_function/dense_fast_rename_function_test.cpp b/eval/src/tests/tensor/dense_fast_rename_optimizer/dense_fast_rename_optimizer_test.cpp
index 45b38b48481..c892ed02808 100644
--- a/eval/src/tests/tensor/dense_fast_rename_function/dense_fast_rename_function_test.cpp
+++ b/eval/src/tests/tensor/dense_fast_rename_optimizer/dense_fast_rename_optimizer_test.cpp
@@ -5,7 +5,8 @@
#include <vespa/eval/eval/simple_tensor.h>
#include <vespa/eval/eval/simple_tensor_engine.h>
#include <vespa/eval/tensor/default_tensor_engine.h>
-#include <vespa/eval/tensor/dense/dense_fast_rename_function.h>
+#include <vespa/eval/tensor/dense/dense_replace_type_function.h>
+#include <vespa/eval/tensor/dense/dense_fast_rename_optimizer.h>
#include <vespa/eval/tensor/dense/dense_tensor.h>
#include <vespa/eval/eval/test/tensor_model.hpp>
#include <vespa/eval/eval/test/eval_fixture.h>
@@ -24,25 +25,23 @@ const TensorEngine &prod_engine = DefaultTensorEngine::ref();
EvalFixture::ParamRepo make_params() {
return EvalFixture::ParamRepo()
.add("x5", spec({x(5)}, N()))
- .add_mutable("mut_x5", spec({x(5)}, N()))
.add("x5_u", spec({x(5)}, N()), "tensor(x[])")
.add("x_m", spec({x({"a", "b", "c"})}, N()))
.add("x5y3", spec({x(5),y(3)}, N()));
}
EvalFixture::ParamRepo param_repo = make_params();
-void verify_optimized(const vespalib::string &expr, bool expect_mutable = false) {
- EvalFixture fixture(prod_engine, expr, param_repo, true, true);
+void verify_optimized(const vespalib::string &expr) {
+ EvalFixture fixture(prod_engine, expr, param_repo, true);
EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo));
- auto info = fixture.find_all<DenseFastRenameFunction>();
- ASSERT_EQUAL(info.size(), 1u);
- EXPECT_EQUAL(info[0]->result_is_mutable(), expect_mutable);
+ auto info = fixture.find_all<DenseReplaceTypeFunction>();
+ EXPECT_EQUAL(info.size(), 1u);
}
void verify_not_optimized(const vespalib::string &expr) {
EvalFixture fixture(prod_engine, expr, param_repo, true);
EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo));
- auto info = fixture.find_all<DenseFastRenameFunction>();
+ auto info = fixture.find_all<DenseReplaceTypeFunction>();
EXPECT_TRUE(info.empty());
}
@@ -73,25 +72,8 @@ TEST("require that non-dense renames are not optimized") {
TEST_DO(verify_not_optimized("rename(x_m,x,y)"));
}
-TEST("require that renaming a mutable result retains mutability") {
- TEST_DO(verify_optimized("rename(mut_x5,x,y)", true));
-}
-
-TEST("require that child mutability changed under-the-hood is still reflected") {
- Stash stash;
- const Node &a = inject(ValueType::from_spec("tensor(x[2])"), 0, stash);
- const Node &tmp = map(a, operation::Neg::f, stash); // will be mutable
- DenseFastRenameFunction my_rename(ValueType::from_spec("tensor(y[2])"), a);
- EXPECT_TRUE(!my_rename.result_is_mutable());
- {
- std::vector<TensorFunction::Child::CREF> list;
- my_rename.push_children(list);
- ASSERT_EQUAL(list.size(), 1u);
- EXPECT_EQUAL(&(list[0].get().get()), &a);
- const TensorFunction::Child &child = list[0];
- child.set(tmp);
- }
- EXPECT_TRUE(my_rename.result_is_mutable());
+TEST("require that chained optimized renames are compacted into a single operation") {
+ TEST_DO(verify_optimized("rename(rename(x5,x,y),y,z)"));
}
TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp
index 82f30b4cb34..768ed4b1907 100644
--- a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp
+++ b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp
@@ -9,7 +9,7 @@
#include "dense/dense_tensor_builder.h"
#include "dense/dense_dot_product_function.h"
#include "dense/dense_xw_product_function.h"
-#include "dense/dense_fast_rename_function.h"
+#include "dense/dense_fast_rename_optimizer.h"
#include "dense/dense_inplace_join_function.h"
#include "dense/dense_inplace_map_function.h"
#include "dense/vector_from_doubles_function.h"
@@ -228,7 +228,7 @@ DefaultTensorEngine::optimize(const TensorFunction &expr, Stash &stash) const
child.set(VectorFromDoublesFunction::optimize(child.get(), stash));
child.set(DenseDotProductFunction::optimize(child.get(), stash));
child.set(DenseXWProductFunction::optimize(child.get(), stash));
- child.set(DenseFastRenameFunction::optimize(child.get(), stash));
+ child.set(DenseFastRenameOptimizer::optimize(child.get(), stash));
child.set(DenseInplaceMapFunction::optimize(child.get(), stash));
child.set(DenseInplaceJoinFunction::optimize(child.get(), stash));
nodes.pop_back();
diff --git a/eval/src/vespa/eval/tensor/dense/CMakeLists.txt b/eval/src/vespa/eval/tensor/dense/CMakeLists.txt
index f3498d44a3d..fc4f7922410 100644
--- a/eval/src/vespa/eval/tensor/dense/CMakeLists.txt
+++ b/eval/src/vespa/eval/tensor/dense/CMakeLists.txt
@@ -2,7 +2,7 @@
vespa_add_library(eval_tensor_dense OBJECT
SOURCES
dense_dot_product_function.cpp
- dense_fast_rename_function.cpp
+ dense_fast_rename_optimizer.cpp
dense_inplace_join_function.cpp
dense_inplace_map_function.cpp
dense_replace_type_function.cpp
diff --git a/eval/src/vespa/eval/tensor/dense/dense_fast_rename_function.h b/eval/src/vespa/eval/tensor/dense/dense_fast_rename_function.h
deleted file mode 100644
index 1ca61d52915..00000000000
--- a/eval/src/vespa/eval/tensor/dense/dense_fast_rename_function.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vespa/eval/eval/tensor_function.h>
-
-namespace vespalib::tensor {
-
-/**
- * Tensor function for efficient non-transposing rename of a dense
- * tensor.
- **/
-class DenseFastRenameFunction : public eval::tensor_function::Op1
-{
-public:
- DenseFastRenameFunction(const eval::ValueType &result_type,
- const eval::TensorFunction &child);
- ~DenseFastRenameFunction();
- eval::InterpretedFunction::Instruction compile_self(Stash &stash) const override;
- bool result_is_mutable() const override { return child().result_is_mutable(); }
- static const eval::TensorFunction &optimize(const eval::TensorFunction &expr, Stash &stash);
-};
-
-} // namespace vespalib::tensor
diff --git a/eval/src/vespa/eval/tensor/dense/dense_fast_rename_function.cpp b/eval/src/vespa/eval/tensor/dense/dense_fast_rename_optimizer.cpp
index dda95d5a657..dbed0cfa5d0 100644
--- a/eval/src/vespa/eval/tensor/dense/dense_fast_rename_function.cpp
+++ b/eval/src/vespa/eval/tensor/dense/dense_fast_rename_optimizer.cpp
@@ -1,6 +1,7 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "dense_fast_rename_function.h"
+#include "dense_fast_rename_optimizer.h"
+#include "dense_replace_type_function.h"
#include "dense_tensor.h"
#include "dense_tensor_view.h"
#include <vespa/eval/eval/value.h>
@@ -17,17 +18,6 @@ using namespace eval::tensor_function;
namespace {
-CellsRef getCellsRef(const eval::Value &value) {
- const DenseTensorView &denseTensor = static_cast<const DenseTensorView &>(value);
- return denseTensor.cellsRef();
-}
-
-void my_fast_rename_op(eval::InterpretedFunction::State &state, uint64_t param) {
- const ValueType *type = (const ValueType *)(param);
- CellsRef cells = getCellsRef(state.peek(0));
- state.pop_push(state.stash.create<DenseTensorView>(*type, cells));
-}
-
bool is_concrete_dense_stable_rename(const ValueType &from_type, const ValueType &to_type,
const std::vector<vespalib::string> &from,
const std::vector<vespalib::string> &to)
@@ -51,31 +41,18 @@ bool is_concrete_dense_stable_rename(const ValueType &from_type, const ValueType
} // namespace vespalib::tensor::<unnamed>
-
-DenseFastRenameFunction::DenseFastRenameFunction(const eval::ValueType &result_type,
- const eval::TensorFunction &child)
- : eval::tensor_function::Op1(result_type, child)
-{
-}
-
-DenseFastRenameFunction::~DenseFastRenameFunction()
-{
-}
-
-eval::InterpretedFunction::Instruction
-DenseFastRenameFunction::compile_self(Stash &) const
-{
- return eval::InterpretedFunction::Instruction(my_fast_rename_op, (uint64_t)&(result_type()));
-}
-
const TensorFunction &
-DenseFastRenameFunction::optimize(const eval::TensorFunction &expr, Stash &stash)
+DenseFastRenameOptimizer::optimize(const eval::TensorFunction &expr, Stash &stash)
{
if (auto rename = as<Rename>(expr)) {
const ValueType &from_type = rename->child().result_type();
const ValueType &to_type = expr.result_type();
if (is_concrete_dense_stable_rename(from_type, to_type, rename->from(), rename->to())) {
- return stash.create<DenseFastRenameFunction>(to_type, rename->child());
+ if (auto replace = as<DenseReplaceTypeFunction>(rename->child())) {
+ return stash.create<DenseReplaceTypeFunction>(to_type, replace->child());
+ } else {
+ return stash.create<DenseReplaceTypeFunction>(to_type, rename->child());
+ }
}
}
return expr;
diff --git a/eval/src/vespa/eval/tensor/dense/dense_fast_rename_optimizer.h b/eval/src/vespa/eval/tensor/dense/dense_fast_rename_optimizer.h
new file mode 100644
index 00000000000..bbcb38e1f80
--- /dev/null
+++ b/eval/src/vespa/eval/tensor/dense/dense_fast_rename_optimizer.h
@@ -0,0 +1,17 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/eval/eval/tensor_function.h>
+
+namespace vespalib::tensor {
+
+/**
+ * Tensor function optimizer for efficient non-transposing rename of a
+ * dense tensor.
+ **/
+struct DenseFastRenameOptimizer {
+ static const eval::TensorFunction &optimize(const eval::TensorFunction &expr, Stash &stash);
+};
+
+} // namespace vespalib::tensor