diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-11-12 10:44:57 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-11-12 10:44:57 +0000 |
commit | c8e26367ded09a6f5d205fd5b74e41b6d7d4af83 (patch) | |
tree | 6d03772ab44f77a9398e188d001ffd212ed67607 /eval | |
parent | cf0f2a8dc65a581bc55c3c3b66cf3e6ed2c23120 (diff) | |
parent | f4dc5e106ebc4a371a3e769228ff1a9557c68750 (diff) |
Merge branch 'master' into arnej/add-join-with-number-optimization
Conflicts:
eval/CMakeLists.txt
eval/src/vespa/eval/instruction/CMakeLists.txt
Diffstat (limited to 'eval')
-rw-r--r-- | eval/CMakeLists.txt | 14 | ||||
-rw-r--r-- | eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp | 4 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_dot_product_function/CMakeLists.txt (renamed from eval/src/tests/tensor/dense_dot_product_function/CMakeLists.txt) | 0 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_dot_product_function/dense_dot_product_function_test.cpp (renamed from eval/src/tests/tensor/dense_dot_product_function/dense_dot_product_function_test.cpp) | 40 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_matmul_function/CMakeLists.txt (renamed from eval/src/tests/tensor/dense_matmul_function/CMakeLists.txt) | 0 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_matmul_function/dense_matmul_function_test.cpp (renamed from eval/src/tests/tensor/dense_matmul_function/dense_matmul_function_test.cpp) | 52 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_multi_matmul_function/CMakeLists.txt (renamed from eval/src/tests/tensor/dense_multi_matmul_function/CMakeLists.txt) | 0 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_multi_matmul_function/dense_multi_matmul_function_test.cpp (renamed from eval/src/tests/tensor/dense_multi_matmul_function/dense_multi_matmul_function_test.cpp) | 53 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_simple_expand_function/CMakeLists.txt (renamed from eval/src/tests/tensor/dense_simple_expand_function/CMakeLists.txt) | 0 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_simple_expand_function/dense_simple_expand_function_test.cpp (renamed from eval/src/tests/tensor/dense_simple_expand_function/dense_simple_expand_function_test.cpp) | 34 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_tensor_peek_function/CMakeLists.txt (renamed from eval/src/tests/tensor/dense_tensor_peek_function/CMakeLists.txt) | 0 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_tensor_peek_function/dense_tensor_peek_function_test.cpp (renamed from eval/src/tests/tensor/dense_tensor_peek_function/dense_tensor_peek_function_test.cpp) | 30 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_xw_product_function/CMakeLists.txt (renamed from eval/src/tests/tensor/dense_xw_product_function/CMakeLists.txt) | 0 | ||||
-rw-r--r-- | eval/src/tests/instruction/dense_xw_product_function/dense_xw_product_function_test.cpp (renamed from eval/src/tests/tensor/dense_xw_product_function/dense_xw_product_function_test.cpp) | 45 | ||||
-rw-r--r-- | eval/src/tests/instruction/index_lookup_table/CMakeLists.txt (renamed from eval/src/tests/tensor/index_lookup_table/CMakeLists.txt) | 0 | ||||
-rw-r--r-- | eval/src/tests/instruction/index_lookup_table/index_lookup_table_test.cpp (renamed from eval/src/tests/tensor/index_lookup_table/index_lookup_table_test.cpp) | 3 | ||||
-rw-r--r-- | eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp | 6 | ||||
-rw-r--r-- | eval/src/vespa/eval/eval/fast_value.cpp | 6 | ||||
-rw-r--r-- | eval/src/vespa/eval/eval/fast_value.hpp | 12 | ||||
-rw-r--r-- | eval/src/vespa/eval/eval/optimize_tensor_function.cpp | 14 | ||||
-rw-r--r-- | eval/src/vespa/eval/eval/simple_value.cpp | 18 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/CMakeLists.txt | 10 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_cell_range_function.cpp | 49 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_cell_range_function.h (renamed from eval/src/vespa/eval/tensor/dense/dense_cell_range_function.h) | 12 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_dot_product_function.cpp (renamed from eval/src/vespa/eval/tensor/dense/dense_dot_product_function.cpp) | 48 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_dot_product_function.h | 23 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_lambda_peek_function.cpp (renamed from eval/src/vespa/eval/tensor/dense/dense_lambda_peek_function.cpp) | 24 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_lambda_peek_function.h (renamed from eval/src/vespa/eval/tensor/dense/dense_lambda_peek_function.h) | 16 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.cpp (renamed from eval/src/vespa/eval/tensor/dense/dense_lambda_peek_optimizer.cpp) | 15 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.h (renamed from eval/src/vespa/eval/tensor/dense/dense_lambda_peek_optimizer.h) | 4 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_matmul_function.cpp (renamed from eval/src/vespa/eval/tensor/dense/dense_matmul_function.cpp) | 54 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_matmul_function.h (renamed from eval/src/vespa/eval/tensor/dense/dense_matmul_function.h) | 24 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_multi_matmul_function.cpp (renamed from eval/src/vespa/eval/tensor/dense/dense_multi_matmul_function.cpp) | 29 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_multi_matmul_function.h (renamed from eval/src/vespa/eval/tensor/dense/dense_multi_matmul_function.h) | 20 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_simple_expand_function.cpp (renamed from eval/src/vespa/eval/tensor/dense/dense_simple_expand_function.cpp) | 31 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_simple_expand_function.h (renamed from eval/src/vespa/eval/tensor/dense/dense_simple_expand_function.h) | 16 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_tensor_peek_function.cpp (renamed from eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.cpp) | 33 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_tensor_peek_function.h (renamed from eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.h) | 12 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_xw_product_function.cpp (renamed from eval/src/vespa/eval/tensor/dense/dense_xw_product_function.cpp) | 51 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/dense_xw_product_function.h (renamed from eval/src/vespa/eval/tensor/dense/dense_xw_product_function.h) | 24 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/index_lookup_table.cpp (renamed from eval/src/vespa/eval/tensor/dense/index_lookup_table.cpp) | 7 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/index_lookup_table.h (renamed from eval/src/vespa/eval/tensor/dense/index_lookup_table.h) | 6 | ||||
-rw-r--r-- | eval/src/vespa/eval/tensor/default_tensor_engine.cpp | 28 | ||||
-rw-r--r-- | eval/src/vespa/eval/tensor/dense/CMakeLists.txt | 10 | ||||
-rw-r--r-- | eval/src/vespa/eval/tensor/dense/dense_cell_range_function.cpp | 54 | ||||
-rw-r--r-- | eval/src/vespa/eval/tensor/dense/dense_dot_product_function.h | 25 |
46 files changed, 494 insertions, 462 deletions
diff --git a/eval/CMakeLists.txt b/eval/CMakeLists.txt index 7d7d1c08f4e..76c76d64b79 100644 --- a/eval/CMakeLists.txt +++ b/eval/CMakeLists.txt @@ -37,6 +37,7 @@ vespa_define_module( src/tests/eval/value_codec src/tests/eval/value_type src/tests/gp/ponder_nov2017 + src/tests/instruction/dense_xw_product_function src/tests/instruction/generic_concat src/tests/instruction/generic_create src/tests/instruction/generic_join @@ -45,30 +46,29 @@ vespa_define_module( src/tests/instruction/generic_peek src/tests/instruction/generic_reduce src/tests/instruction/generic_rename + src/tests/instruction/dense_dot_product_function + src/tests/instruction/dense_matmul_function + src/tests/instruction/dense_multi_matmul_function + src/tests/instruction/dense_simple_expand_function + src/tests/instruction/dense_tensor_peek_function + src/tests/instruction/index_lookup_table src/tests/instruction/join_with_number src/tests/tensor/default_value_builder_factory src/tests/tensor/dense_add_dimension_optimizer src/tests/tensor/dense_dimension_combiner - src/tests/tensor/dense_dot_product_function src/tests/tensor/dense_fast_rename_optimizer src/tests/tensor/dense_generic_join src/tests/tensor/dense_inplace_join_function - src/tests/tensor/dense_matmul_function - src/tests/tensor/dense_multi_matmul_function src/tests/tensor/dense_number_join_function src/tests/tensor/dense_pow_as_map_optimizer src/tests/tensor/dense_remove_dimension_optimizer src/tests/tensor/dense_replace_type_function - src/tests/tensor/dense_simple_expand_function src/tests/tensor/dense_simple_join_function src/tests/tensor/dense_simple_map_function src/tests/tensor/dense_single_reduce_function src/tests/tensor/dense_tensor_create_function - src/tests/tensor/dense_tensor_peek_function - src/tests/tensor/dense_xw_product_function src/tests/tensor/direct_dense_tensor_builder src/tests/tensor/direct_sparse_tensor_builder - src/tests/tensor/index_lookup_table src/tests/tensor/instruction_benchmark src/tests/tensor/onnx_wrapper src/tests/tensor/packed_mappings diff --git a/eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp b/eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp index a2150c3d1bb..fc6a7e46576 100644 --- a/eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp +++ b/eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp @@ -8,8 +8,8 @@ #include <vespa/eval/eval/fast_value.h> #include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/eval/tensor/dense/dense_replace_type_function.h> -#include <vespa/eval/tensor/dense/dense_cell_range_function.h> -#include <vespa/eval/tensor/dense/dense_lambda_peek_function.h> +#include <vespa/eval/instruction/dense_cell_range_function.h> +#include <vespa/eval/instruction/dense_lambda_peek_function.h> #include <vespa/eval/tensor/dense/dense_lambda_function.h> #include <vespa/eval/tensor/dense/dense_fast_rename_optimizer.h> #include <vespa/eval/tensor/dense/dense_tensor.h> diff --git a/eval/src/tests/tensor/dense_dot_product_function/CMakeLists.txt b/eval/src/tests/instruction/dense_dot_product_function/CMakeLists.txt index 396c404b6cf..396c404b6cf 100644 --- a/eval/src/tests/tensor/dense_dot_product_function/CMakeLists.txt +++ b/eval/src/tests/instruction/dense_dot_product_function/CMakeLists.txt diff --git a/eval/src/tests/tensor/dense_dot_product_function/dense_dot_product_function_test.cpp b/eval/src/tests/instruction/dense_dot_product_function/dense_dot_product_function_test.cpp index 9bf97f449b3..ff4a92d4fff 100644 --- a/eval/src/tests/tensor/dense_dot_product_function/dense_dot_product_function_test.cpp +++ b/eval/src/tests/instruction/dense_dot_product_function/dense_dot_product_function_test.cpp @@ -1,15 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/tensor_function.h> -#include <vespa/eval/tensor/default_tensor_engine.h> -#include <vespa/eval/tensor/dense/dense_dot_product_function.h> -#include <vespa/eval/tensor/dense/dense_tensor.h> -#include <vespa/eval/tensor/dense/dense_tensor_view.h> -#include <vespa/eval/eval/test/tensor_model.hpp> #include <vespa/eval/eval/test/eval_fixture.h> -#include <vespa/vespalib/util/stringfmt.h> +#include <vespa/eval/eval/test/tensor_model.hpp> +#include <vespa/eval/instruction/dense_dot_product_function.h> +#include <vespa/eval/tensor/default_tensor_engine.h> +#include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stash.h> +#include <vespa/vespalib/util/stringfmt.h> #include <vespa/log/log.h> LOG_SETUP("dense_dot_product_function_test"); @@ -17,9 +16,9 @@ LOG_SETUP("dense_dot_product_function_test"); using namespace vespalib; using namespace vespalib::eval; using namespace vespalib::eval::test; -using namespace vespalib::tensor; -const TensorEngine &prod_engine = DefaultTensorEngine::ref(); +const TensorEngine &old_engine = tensor::DefaultTensorEngine::ref(); +const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get(); struct MyVecSeq : Sequence { double bias; @@ -47,11 +46,17 @@ void check_gen_with_result(size_t l, size_t r, double wanted) { param_repo.add("a", makeTensor(l, leftBias)); param_repo.add("b", makeTensor(r, rightBias)); vespalib::string expr = "reduce(a*b,sum,x)"; - EvalFixture evaluator(prod_engine, expr, param_repo, true); + EvalFixture evaluator(prod_factory, expr, param_repo, true); EXPECT_EQUAL(spec(wanted), evaluator.result()); EXPECT_EQUAL(evaluator.result(), EvalFixture::ref(expr, param_repo)); auto info = evaluator.find_all<DenseDotProductFunction>(); EXPECT_EQUAL(info.size(), 1u); + + EvalFixture old_evaluator(old_engine, expr, param_repo, true); + EXPECT_EQUAL(spec(wanted), old_evaluator.result()); + EXPECT_EQUAL(old_evaluator.result(), EvalFixture::ref(expr, param_repo)); + info = old_evaluator.find_all<DenseDotProductFunction>(); + EXPECT_EQUAL(info.size(), 1u); }; // this should not be possible to set up: @@ -110,18 +115,29 @@ EvalFixture::ParamRepo make_params() { EvalFixture::ParamRepo param_repo = make_params(); void assertOptimized(const vespalib::string &expr) { - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture fixture(prod_factory, expr, param_repo, true); EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); auto info = fixture.find_all<DenseDotProductFunction>(); ASSERT_EQUAL(info.size(), 1u); EXPECT_TRUE(info[0]->result_is_mutable()); + + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQUAL(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + info = old_fixture.find_all<DenseDotProductFunction>(); + ASSERT_EQUAL(info.size(), 1u); + EXPECT_TRUE(info[0]->result_is_mutable()); } void assertNotOptimized(const vespalib::string &expr) { - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture fixture(prod_factory, expr, param_repo, true); EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); auto info = fixture.find_all<DenseDotProductFunction>(); EXPECT_TRUE(info.empty()); + + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQUAL(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + info = old_fixture.find_all<DenseDotProductFunction>(); + EXPECT_TRUE(info.empty()); } TEST("require that dot product works with tensor function") { diff --git a/eval/src/tests/tensor/dense_matmul_function/CMakeLists.txt b/eval/src/tests/instruction/dense_matmul_function/CMakeLists.txt index 7234e8b9e69..7234e8b9e69 100644 --- a/eval/src/tests/tensor/dense_matmul_function/CMakeLists.txt +++ b/eval/src/tests/instruction/dense_matmul_function/CMakeLists.txt diff --git a/eval/src/tests/tensor/dense_matmul_function/dense_matmul_function_test.cpp b/eval/src/tests/instruction/dense_matmul_function/dense_matmul_function_test.cpp index 92fdbfade46..1269d82a1e0 100644 --- a/eval/src/tests/tensor/dense_matmul_function/dense_matmul_function_test.cpp +++ b/eval/src/tests/instruction/dense_matmul_function/dense_matmul_function_test.cpp @@ -1,27 +1,23 @@ // Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/eval/eval/tensor_function.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/operation.h> -#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_matmul_function.h> -#include <vespa/eval/tensor/dense/dense_tensor.h> -#include <vespa/eval/tensor/dense/dense_tensor_view.h> -#include <vespa/eval/eval/test/tensor_model.hpp> +#include <vespa/eval/eval/tensor_function.h> #include <vespa/eval/eval/test/eval_fixture.h> - -#include <vespa/vespalib/util/stringfmt.h> +#include <vespa/eval/eval/test/tensor_model.hpp> +#include <vespa/eval/instruction/dense_matmul_function.h> +#include <vespa/eval/tensor/default_tensor_engine.h> +#include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stash.h> +#include <vespa/vespalib/util/stringfmt.h> using namespace vespalib; using namespace vespalib::eval; using namespace vespalib::eval::test; -using namespace vespalib::tensor; using namespace vespalib::eval::tensor_function; -const TensorEngine &prod_engine = DefaultTensorEngine::ref(); +const TensorEngine &old_engine = tensor::DefaultTensorEngine::ref(); +const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get(); EvalFixture::ParamRepo make_params() { return EvalFixture::ParamRepo() @@ -38,8 +34,8 @@ void verify_optimized(const vespalib::string &expr, size_t lhs_size, size_t common_size, size_t rhs_size, bool lhs_inner, bool rhs_inner) { - EvalFixture slow_fixture(prod_engine, expr, param_repo, false); - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture slow_fixture(prod_factory, expr, param_repo, false); + EvalFixture fixture(prod_factory, expr, param_repo, true); EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); EXPECT_EQUAL(fixture.result(), slow_fixture.result()); auto info = fixture.find_all<DenseMatMulFunction>(); @@ -50,15 +46,35 @@ void verify_optimized(const vespalib::string &expr, EXPECT_EQUAL(info[0]->rhs_size(), rhs_size); EXPECT_EQUAL(info[0]->lhs_common_inner(), lhs_inner); EXPECT_EQUAL(info[0]->rhs_common_inner(), rhs_inner); + + EvalFixture old_slow_fixture(old_engine, expr, param_repo, false); + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQUAL(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + EXPECT_EQUAL(old_fixture.result(), old_slow_fixture.result()); + info = old_fixture.find_all<DenseMatMulFunction>(); + ASSERT_EQUAL(info.size(), 1u); + EXPECT_TRUE(info[0]->result_is_mutable()); + EXPECT_EQUAL(info[0]->lhs_size(), lhs_size); + EXPECT_EQUAL(info[0]->common_size(), common_size); + EXPECT_EQUAL(info[0]->rhs_size(), rhs_size); + EXPECT_EQUAL(info[0]->lhs_common_inner(), lhs_inner); + EXPECT_EQUAL(info[0]->rhs_common_inner(), rhs_inner); } void verify_not_optimized(const vespalib::string &expr) { - EvalFixture slow_fixture(prod_engine, expr, param_repo, false); - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture slow_fixture(prod_factory, expr, param_repo, false); + EvalFixture fixture(prod_factory, expr, param_repo, true); EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); EXPECT_EQUAL(fixture.result(), slow_fixture.result()); auto info = fixture.find_all<DenseMatMulFunction>(); EXPECT_TRUE(info.empty()); + + EvalFixture old_slow_fixture(old_engine, expr, param_repo, false); + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQUAL(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + EXPECT_EQUAL(old_fixture.result(), old_slow_fixture.result()); + info = old_fixture.find_all<DenseMatMulFunction>(); + EXPECT_TRUE(info.empty()); } TEST("require that matmul can be optimized") { @@ -84,7 +100,7 @@ TEST("require that expressions similar to matmul are not optimized") { } TEST("require that xw product can be debug dumped") { - EvalFixture fixture(prod_engine, "reduce(a2d3*b5d3,sum,d)", param_repo, true); + EvalFixture fixture(prod_factory, "reduce(a2d3*b5d3,sum,d)", param_repo, true); auto info = fixture.find_all<DenseMatMulFunction>(); ASSERT_EQUAL(info.size(), 1u); fprintf(stderr, "%s\n", info[0]->as_string().c_str()); diff --git a/eval/src/tests/tensor/dense_multi_matmul_function/CMakeLists.txt b/eval/src/tests/instruction/dense_multi_matmul_function/CMakeLists.txt index 1619f42c897..1619f42c897 100644 --- a/eval/src/tests/tensor/dense_multi_matmul_function/CMakeLists.txt +++ b/eval/src/tests/instruction/dense_multi_matmul_function/CMakeLists.txt diff --git a/eval/src/tests/tensor/dense_multi_matmul_function/dense_multi_matmul_function_test.cpp b/eval/src/tests/instruction/dense_multi_matmul_function/dense_multi_matmul_function_test.cpp index 31dae9e7cf8..8f4a06b2335 100644 --- a/eval/src/tests/tensor/dense_multi_matmul_function/dense_multi_matmul_function_test.cpp +++ b/eval/src/tests/instruction/dense_multi_matmul_function/dense_multi_matmul_function_test.cpp @@ -1,27 +1,23 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/eval/eval/tensor_function.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/operation.h> -#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_multi_matmul_function.h> -#include <vespa/eval/tensor/dense/dense_tensor.h> -#include <vespa/eval/tensor/dense/dense_tensor_view.h> -#include <vespa/eval/eval/test/tensor_model.hpp> +#include <vespa/eval/eval/tensor_function.h> #include <vespa/eval/eval/test/eval_fixture.h> - -#include <vespa/vespalib/util/stringfmt.h> +#include <vespa/eval/eval/test/tensor_model.hpp> +#include <vespa/eval/instruction/dense_multi_matmul_function.h> +#include <vespa/eval/tensor/default_tensor_engine.h> +#include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stash.h> +#include <vespa/vespalib/util/stringfmt.h> using namespace vespalib; using namespace vespalib::eval; using namespace vespalib::eval::test; -using namespace vespalib::tensor; using namespace vespalib::eval::tensor_function; -const TensorEngine &prod_engine = DefaultTensorEngine::ref(); +const TensorEngine &old_engine = tensor::DefaultTensorEngine::ref(); +const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get(); EvalFixture::ParamRepo make_params() { return EvalFixture::ParamRepo() @@ -45,8 +41,8 @@ void verify_optimized(const vespalib::string &expr, size_t lhs_size, size_t common_size, size_t rhs_size, size_t matmul_cnt, bool lhs_inner, bool rhs_inner) { - EvalFixture slow_fixture(prod_engine, expr, param_repo, false); - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture slow_fixture(prod_factory, expr, param_repo, false); + EvalFixture fixture(prod_factory, expr, param_repo, true); EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); EXPECT_EQUAL(fixture.result(), slow_fixture.result()); auto info = fixture.find_all<DenseMultiMatMulFunction>(); @@ -58,15 +54,36 @@ void verify_optimized(const vespalib::string &expr, EXPECT_EQUAL(info[0]->matmul_cnt(), matmul_cnt); EXPECT_EQUAL(info[0]->lhs_common_inner(), lhs_inner); EXPECT_EQUAL(info[0]->rhs_common_inner(), rhs_inner); + + EvalFixture old_slow_fixture(old_engine, expr, param_repo, false); + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQUAL(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + EXPECT_EQUAL(old_fixture.result(), old_slow_fixture.result()); + info = old_fixture.find_all<DenseMultiMatMulFunction>(); + ASSERT_EQUAL(info.size(), 1u); + EXPECT_TRUE(info[0]->result_is_mutable()); + EXPECT_EQUAL(info[0]->lhs_size(), lhs_size); + EXPECT_EQUAL(info[0]->common_size(), common_size); + EXPECT_EQUAL(info[0]->rhs_size(), rhs_size); + EXPECT_EQUAL(info[0]->matmul_cnt(), matmul_cnt); + EXPECT_EQUAL(info[0]->lhs_common_inner(), lhs_inner); + EXPECT_EQUAL(info[0]->rhs_common_inner(), rhs_inner); } void verify_not_optimized(const vespalib::string &expr) { - EvalFixture slow_fixture(prod_engine, expr, param_repo, false); - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture slow_fixture(prod_factory, expr, param_repo, false); + EvalFixture fixture(prod_factory, expr, param_repo, true); EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); EXPECT_EQUAL(fixture.result(), slow_fixture.result()); auto info = fixture.find_all<DenseMultiMatMulFunction>(); EXPECT_TRUE(info.empty()); + + EvalFixture old_slow_fixture(old_engine, expr, param_repo, false); + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQUAL(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + EXPECT_EQUAL(old_fixture.result(), old_slow_fixture.result()); + info = old_fixture.find_all<DenseMultiMatMulFunction>(); + EXPECT_TRUE(info.empty()); } TEST("require that multi matmul can be optimized") { @@ -116,7 +133,7 @@ TEST("require that multi matmul ignores trivial dimensions") { } TEST("require that multi matmul function can be debug dumped") { - EvalFixture fixture(prod_engine, "reduce(A2B1C3a2d3*A2B1C3b5d3,sum,d)", param_repo, true); + EvalFixture fixture(prod_factory, "reduce(A2B1C3a2d3*A2B1C3b5d3,sum,d)", param_repo, true); auto info = fixture.find_all<DenseMultiMatMulFunction>(); ASSERT_EQUAL(info.size(), 1u); fprintf(stderr, "%s\n", info[0]->as_string().c_str()); diff --git a/eval/src/tests/tensor/dense_simple_expand_function/CMakeLists.txt b/eval/src/tests/instruction/dense_simple_expand_function/CMakeLists.txt index 9bb22da7d88..9bb22da7d88 100644 --- a/eval/src/tests/tensor/dense_simple_expand_function/CMakeLists.txt +++ b/eval/src/tests/instruction/dense_simple_expand_function/CMakeLists.txt diff --git a/eval/src/tests/tensor/dense_simple_expand_function/dense_simple_expand_function_test.cpp b/eval/src/tests/instruction/dense_simple_expand_function/dense_simple_expand_function_test.cpp index 4b870bc0153..bf9b8a181aa 100644 --- a/eval/src/tests/tensor/dense_simple_expand_function/dense_simple_expand_function_test.cpp +++ b/eval/src/tests/instruction/dense_simple_expand_function/dense_simple_expand_function_test.cpp @@ -1,10 +1,11 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/tensor_function.h> #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_simple_expand_function.h> +#include <vespa/eval/instruction/dense_simple_expand_function.h> #include <vespa/eval/eval/test/eval_fixture.h> #include <vespa/eval/eval/test/tensor_model.hpp> #include <vespa/vespalib/gtest/gtest.h> @@ -13,11 +14,11 @@ using namespace vespalib; using namespace vespalib::eval; using namespace vespalib::eval::test; using namespace vespalib::eval::tensor_function; -using namespace vespalib::tensor; using Inner = DenseSimpleExpandFunction::Inner; -const TensorEngine &prod_engine = DefaultTensorEngine::ref(); +const TensorEngine &old_engine = tensor::DefaultTensorEngine::ref(); +const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get(); EvalFixture::ParamRepo make_params() { return EvalFixture::ParamRepo() @@ -37,8 +38,8 @@ EvalFixture::ParamRepo make_params() { EvalFixture::ParamRepo param_repo = make_params(); void verify_optimized(const vespalib::string &expr, Inner inner) { - EvalFixture slow_fixture(prod_engine, expr, param_repo, false); - EvalFixture fixture(prod_engine, expr, param_repo, true, true); + EvalFixture slow_fixture(prod_factory, expr, param_repo, false); + EvalFixture fixture(prod_factory, expr, param_repo, true, true); EXPECT_EQ(fixture.result(), EvalFixture::ref(expr, param_repo)); EXPECT_EQ(fixture.result(), slow_fixture.result()); auto info = fixture.find_all<DenseSimpleExpandFunction>(); @@ -48,15 +49,34 @@ void verify_optimized(const vespalib::string &expr, Inner inner) { ASSERT_EQ(fixture.num_params(), 2); EXPECT_TRUE(!(fixture.get_param(0) == fixture.result())); EXPECT_TRUE(!(fixture.get_param(1) == fixture.result())); + + EvalFixture old_slow_fixture(old_engine, expr, param_repo, false); + EvalFixture old_fixture(old_engine, expr, param_repo, true, true); + EXPECT_EQ(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + EXPECT_EQ(old_fixture.result(), old_slow_fixture.result()); + info = old_fixture.find_all<DenseSimpleExpandFunction>(); + ASSERT_EQ(info.size(), 1u); + EXPECT_TRUE(info[0]->result_is_mutable()); + EXPECT_EQ(info[0]->inner(), inner); + ASSERT_EQ(old_fixture.num_params(), 2); + EXPECT_TRUE(!(old_fixture.get_param(0) == old_fixture.result())); + EXPECT_TRUE(!(old_fixture.get_param(1) == old_fixture.result())); } void verify_not_optimized(const vespalib::string &expr) { - EvalFixture slow_fixture(prod_engine, expr, param_repo, false); - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture slow_fixture(prod_factory, expr, param_repo, false); + EvalFixture fixture(prod_factory, expr, param_repo, true); EXPECT_EQ(fixture.result(), EvalFixture::ref(expr, param_repo)); EXPECT_EQ(fixture.result(), slow_fixture.result()); auto info = fixture.find_all<DenseSimpleExpandFunction>(); EXPECT_TRUE(info.empty()); + + EvalFixture old_slow_fixture(old_engine, expr, param_repo, false); + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQ(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + EXPECT_EQ(old_fixture.result(), old_slow_fixture.result()); + info = old_fixture.find_all<DenseSimpleExpandFunction>(); + EXPECT_TRUE(info.empty()); } TEST(ExpandTest, simple_expand_is_optimized) { diff --git a/eval/src/tests/tensor/dense_tensor_peek_function/CMakeLists.txt b/eval/src/tests/instruction/dense_tensor_peek_function/CMakeLists.txt index a4d1bbf6fac..a4d1bbf6fac 100644 --- a/eval/src/tests/tensor/dense_tensor_peek_function/CMakeLists.txt +++ b/eval/src/tests/instruction/dense_tensor_peek_function/CMakeLists.txt diff --git a/eval/src/tests/tensor/dense_tensor_peek_function/dense_tensor_peek_function_test.cpp b/eval/src/tests/instruction/dense_tensor_peek_function/dense_tensor_peek_function_test.cpp index 5bbdfeaf543..df9271784b9 100644 --- a/eval/src/tests/tensor/dense_tensor_peek_function/dense_tensor_peek_function_test.cpp +++ b/eval/src/tests/instruction/dense_tensor_peek_function/dense_tensor_peek_function_test.cpp @@ -1,25 +1,22 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/tensor_function.h> -#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_tensor_peek_function.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> - -#include <vespa/vespalib/util/stringfmt.h> +#include <vespa/eval/eval/test/tensor_model.hpp> +#include <vespa/eval/instruction/dense_tensor_peek_function.h> +#include <vespa/eval/tensor/default_tensor_engine.h> +#include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stash.h> +#include <vespa/vespalib/util/stringfmt.h> using namespace vespalib; using namespace vespalib::eval; using namespace vespalib::eval::test; -using namespace vespalib::tensor; using namespace vespalib::eval::tensor_function; -const TensorEngine &prod_engine = DefaultTensorEngine::ref(); +const TensorEngine &old_engine = tensor::DefaultTensorEngine::ref(); +const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get(); EvalFixture::ParamRepo make_params() { return EvalFixture::ParamRepo() @@ -36,7 +33,7 @@ EvalFixture::ParamRepo make_params() { EvalFixture::ParamRepo param_repo = make_params(); void verify(const vespalib::string &expr, double expect, size_t expect_optimized_cnt, size_t expect_not_optimized_cnt) { - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture fixture(prod_factory, expr, param_repo, true); auto expect_spec = TensorSpec("double").add({}, expect); EXPECT_EQUAL(EvalFixture::ref(expr, param_repo), expect_spec); EXPECT_EQUAL(fixture.result(), expect_spec); @@ -46,6 +43,15 @@ void verify(const vespalib::string &expr, double expect, size_t expect_optimized EXPECT_TRUE(info[i]->result_is_mutable()); } EXPECT_EQUAL(fixture.find_all<Peek>().size(), expect_not_optimized_cnt); + + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQUAL(old_fixture.result(), expect_spec); + info = old_fixture.find_all<DenseTensorPeekFunction>(); + EXPECT_EQUAL(info.size(), expect_optimized_cnt); + for (size_t i = 0; i < info.size(); ++i) { + EXPECT_TRUE(info[i]->result_is_mutable()); + } + EXPECT_EQUAL(old_fixture.find_all<Peek>().size(), expect_not_optimized_cnt); } //----------------------------------------------------------------------------- diff --git a/eval/src/tests/tensor/dense_xw_product_function/CMakeLists.txt b/eval/src/tests/instruction/dense_xw_product_function/CMakeLists.txt index 648c10e64bd..648c10e64bd 100644 --- a/eval/src/tests/tensor/dense_xw_product_function/CMakeLists.txt +++ b/eval/src/tests/instruction/dense_xw_product_function/CMakeLists.txt diff --git a/eval/src/tests/tensor/dense_xw_product_function/dense_xw_product_function_test.cpp b/eval/src/tests/instruction/dense_xw_product_function/dense_xw_product_function_test.cpp index 3ecc3f66cda..769657ae0a2 100644 --- a/eval/src/tests/tensor/dense_xw_product_function/dense_xw_product_function_test.cpp +++ b/eval/src/tests/instruction/dense_xw_product_function/dense_xw_product_function_test.cpp @@ -1,16 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/eval/eval/tensor_function.h> #include <vespa/eval/eval/operation.h> -#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_xw_product_function.h> -#include <vespa/eval/tensor/dense/dense_tensor.h> -#include <vespa/eval/tensor/dense/dense_tensor_view.h> -#include <vespa/eval/eval/test/tensor_model.hpp> +#include <vespa/eval/eval/fast_value.h> +#include <vespa/eval/eval/tensor_function.h> #include <vespa/eval/eval/test/eval_fixture.h> +#include <vespa/eval/eval/test/tensor_model.hpp> +#include <vespa/eval/instruction/dense_xw_product_function.h> +#include <vespa/eval/tensor/default_tensor_engine.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/stash.h> @@ -18,10 +15,10 @@ using namespace vespalib; using namespace vespalib::eval; using namespace vespalib::eval::test; -using namespace vespalib::tensor; using namespace vespalib::eval::tensor_function; -const TensorEngine &prod_engine = DefaultTensorEngine::ref(); +const TensorEngine &old_engine = tensor::DefaultTensorEngine::ref(); +const ValueBuilderFactory &prod_factory = FastValueBuilderFactory::get(); struct First { bool value; @@ -71,8 +68,8 @@ EvalFixture::ParamRepo make_params() { EvalFixture::ParamRepo param_repo = make_params(); void verify_optimized(const vespalib::string &expr, size_t vec_size, size_t res_size, bool happy) { - EvalFixture slow_fixture(prod_engine, expr, param_repo, false); - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture slow_fixture(prod_factory, expr, param_repo, false); + EvalFixture fixture(prod_factory, expr, param_repo, true); EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); EXPECT_EQUAL(fixture.result(), slow_fixture.result()); auto info = fixture.find_all<DenseXWProductFunction>(); @@ -81,6 +78,17 @@ void verify_optimized(const vespalib::string &expr, size_t vec_size, size_t res_ EXPECT_EQUAL(info[0]->vector_size(), vec_size); EXPECT_EQUAL(info[0]->result_size(), res_size); EXPECT_EQUAL(info[0]->common_inner(), happy); + + EvalFixture old_slow_fixture(old_engine, expr, param_repo, false); + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQUAL(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + EXPECT_EQUAL(old_fixture.result(), old_slow_fixture.result()); + info = old_fixture.find_all<DenseXWProductFunction>(); + ASSERT_EQUAL(info.size(), 1u); + EXPECT_TRUE(info[0]->result_is_mutable()); + EXPECT_EQUAL(info[0]->vector_size(), vec_size); + EXPECT_EQUAL(info[0]->result_size(), res_size); + EXPECT_EQUAL(info[0]->common_inner(), happy); } vespalib::string make_expr(const vespalib::string &a, const vespalib::string &b, const vespalib::string &common, @@ -105,12 +113,19 @@ void verify_optimized_multi(const vespalib::string &a, const vespalib::string &b } void verify_not_optimized(const vespalib::string &expr) { - EvalFixture slow_fixture(prod_engine, expr, param_repo, false); - EvalFixture fixture(prod_engine, expr, param_repo, true); + EvalFixture slow_fixture(prod_factory, expr, param_repo, false); + EvalFixture fixture(prod_factory, expr, param_repo, true); EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo)); EXPECT_EQUAL(fixture.result(), slow_fixture.result()); auto info = fixture.find_all<DenseXWProductFunction>(); EXPECT_TRUE(info.empty()); + + EvalFixture old_slow_fixture(old_engine, expr, param_repo, false); + EvalFixture old_fixture(old_engine, expr, param_repo, true); + EXPECT_EQUAL(old_fixture.result(), EvalFixture::ref(expr, param_repo)); + EXPECT_EQUAL(old_fixture.result(), old_slow_fixture.result()); + info = old_fixture.find_all<DenseXWProductFunction>(); + EXPECT_TRUE(info.empty()); } TEST("require that xw product gives same results as reference join/reduce") { @@ -146,7 +161,7 @@ TEST("require that expressions similar to xw product are not optimized") { } TEST("require that xw product can be debug dumped") { - EvalFixture fixture(prod_engine, "reduce(y5*x8y5,sum,y)", param_repo, true); + EvalFixture fixture(prod_factory, "reduce(y5*x8y5,sum,y)", param_repo, true); auto info = fixture.find_all<DenseXWProductFunction>(); ASSERT_EQUAL(info.size(), 1u); EXPECT_TRUE(info[0]->result_is_mutable()); diff --git a/eval/src/tests/tensor/index_lookup_table/CMakeLists.txt b/eval/src/tests/instruction/index_lookup_table/CMakeLists.txt index 0343ed75978..0343ed75978 100644 --- a/eval/src/tests/tensor/index_lookup_table/CMakeLists.txt +++ b/eval/src/tests/instruction/index_lookup_table/CMakeLists.txt diff --git a/eval/src/tests/tensor/index_lookup_table/index_lookup_table_test.cpp b/eval/src/tests/instruction/index_lookup_table/index_lookup_table_test.cpp index 3f806e8252c..cc0a7e33c1d 100644 --- a/eval/src/tests/tensor/index_lookup_table/index_lookup_table_test.cpp +++ b/eval/src/tests/instruction/index_lookup_table/index_lookup_table_test.cpp @@ -1,12 +1,11 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/eval/tensor/dense/index_lookup_table.h> +#include <vespa/eval/instruction/index_lookup_table.h> #include <vespa/eval/eval/function.h> #include <vespa/eval/eval/value_type.h> #include <vespa/vespalib/gtest/gtest.h> using namespace vespalib::eval; -using namespace vespalib::tensor; std::vector<uint32_t> make_table(std::vector<uint32_t> list) { return list; } diff --git a/eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp b/eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp index 9ea27ff2f10..8887f2cb6aa 100644 --- a/eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp +++ b/eval/src/tests/tensor/instruction_benchmark/instruction_benchmark.cpp @@ -705,6 +705,12 @@ TEST(DenseJoin, no_overlap) { benchmark_join("dense no overlap multiply", lhs, rhs, operation::Mul::f); } +TEST(DenseJoin, simple_expand) { + auto lhs = make_cube(D::idx("a", 5), D::idx("b", 4), D::idx("c", 4), 1.0); + auto rhs = make_cube(D::idx("d", 4), D::idx("e", 4), D::idx("f", 5), 2.0); + benchmark_join("dense simple expand multiply", lhs, rhs, operation::Mul::f); +} + TEST(DenseJoin, multiply_by_number) { auto lhs = make_spec(3.0); auto rhs = make_cube(D::idx("a", 16), D::idx("b", 16), D::idx("c", 16), 2.0); diff --git a/eval/src/vespa/eval/eval/fast_value.cpp b/eval/src/vespa/eval/eval/fast_value.cpp index b7ae3f30609..116e561a868 100644 --- a/eval/src/vespa/eval/eval/fast_value.cpp +++ b/eval/src/vespa/eval/eval/fast_value.cpp @@ -35,11 +35,11 @@ FastValueIndex::create_view(const std::vector<size_t> &dims) const if (map.num_dims() == 0) { return TrivialIndex::get().create_view(dims); } else if (dims.empty()) { - return std::make_unique<IterateView>(map); + return std::make_unique<FastIterateView>(map); } else if (dims.size() == map.num_dims()) { - return std::make_unique<LookupView>(map); + return std::make_unique<FastLookupView>(map); } else { - return std::make_unique<FilterView>(map, dims); + return std::make_unique<FastFilterView>(map, dims); } } diff --git a/eval/src/vespa/eval/eval/fast_value.hpp b/eval/src/vespa/eval/eval/fast_value.hpp index 932924cd409..ff94f94efbc 100644 --- a/eval/src/vespa/eval/eval/fast_value.hpp +++ b/eval/src/vespa/eval/eval/fast_value.hpp @@ -16,12 +16,12 @@ namespace { //----------------------------------------------------------------------------- // look up a full address in the map directly -struct LookupView : public Value::Index::View { +struct FastLookupView : public Value::Index::View { const FastSparseMap ↦ size_t subspace; - LookupView(const FastSparseMap &map_in) + FastLookupView(const FastSparseMap &map_in) : map(map_in), subspace(FastSparseMap::npos()) {} void lookup(ConstArrayRef<const vespalib::stringref*> addr) override { @@ -41,7 +41,7 @@ struct LookupView : public Value::Index::View { //----------------------------------------------------------------------------- // find matching mappings for a partial address with brute force filtering -struct FilterView : public Value::Index::View { +struct FastFilterView : public Value::Index::View { using Label = FastSparseMap::HashedLabel; @@ -61,7 +61,7 @@ struct FilterView : public Value::Index::View { return true; } - FilterView(const FastSparseMap &map, const std::vector<size_t> &match_dims_in) + FastFilterView(const FastSparseMap &map, const std::vector<size_t> &match_dims_in) : num_mapped_dims(map.num_dims()), labels(map.labels()), match_dims(match_dims_in), extract_dims(), query(match_dims.size(), Label()), pos(labels.size()) { @@ -105,7 +105,7 @@ struct FilterView : public Value::Index::View { //----------------------------------------------------------------------------- // iterate all mappings -struct IterateView : public Value::Index::View { +struct FastIterateView : public Value::Index::View { using Labels = std::vector<FastSparseMap::HashedLabel>; @@ -113,7 +113,7 @@ struct IterateView : public Value::Index::View { const Labels &labels; size_t pos; - IterateView(const FastSparseMap &map) + FastIterateView(const FastSparseMap &map) : num_mapped_dims(map.num_dims()), labels(map.labels()), pos(labels.size()) {} void lookup(ConstArrayRef<const vespalib::stringref*>) override { diff --git a/eval/src/vespa/eval/eval/optimize_tensor_function.cpp b/eval/src/vespa/eval/eval/optimize_tensor_function.cpp index 75ae3307599..28e1111ac48 100644 --- a/eval/src/vespa/eval/eval/optimize_tensor_function.cpp +++ b/eval/src/vespa/eval/eval/optimize_tensor_function.cpp @@ -5,24 +5,24 @@ #include "tensor_engine.h" #include "simple_value.h" -#include <vespa/eval/tensor/dense/dense_dot_product_function.h> -#include <vespa/eval/tensor/dense/dense_xw_product_function.h> -#include <vespa/eval/tensor/dense/dense_matmul_function.h> -#include <vespa/eval/tensor/dense/dense_multi_matmul_function.h> +#include <vespa/eval/instruction/dense_dot_product_function.h> +#include <vespa/eval/instruction/dense_xw_product_function.h> +#include <vespa/eval/instruction/dense_matmul_function.h> +#include <vespa/eval/instruction/dense_multi_matmul_function.h> #include <vespa/eval/tensor/dense/dense_fast_rename_optimizer.h> #include <vespa/eval/tensor/dense/dense_add_dimension_optimizer.h> #include <vespa/eval/tensor/dense/dense_single_reduce_function.h> #include <vespa/eval/tensor/dense/dense_remove_dimension_optimizer.h> -#include <vespa/eval/tensor/dense/dense_lambda_peek_optimizer.h> +#include <vespa/eval/instruction/dense_lambda_peek_optimizer.h> #include <vespa/eval/tensor/dense/dense_lambda_function.h> -#include <vespa/eval/tensor/dense/dense_simple_expand_function.h> +#include <vespa/eval/instruction/dense_simple_expand_function.h> #include <vespa/eval/tensor/dense/dense_simple_join_function.h> #include <vespa/eval/instruction/join_with_number_function.h> #include <vespa/eval/tensor/dense/dense_pow_as_map_optimizer.h> #include <vespa/eval/tensor/dense/dense_simple_map_function.h> #include <vespa/eval/tensor/dense/vector_from_doubles_function.h> #include <vespa/eval/tensor/dense/dense_tensor_create_function.h> -#include <vespa/eval/tensor/dense/dense_tensor_peek_function.h> +#include <vespa/eval/instruction/dense_tensor_peek_function.h> #include <vespa/log/log.h> LOG_SETUP(".eval.eval.optimize_tensor_function"); diff --git a/eval/src/vespa/eval/eval/simple_value.cpp b/eval/src/vespa/eval/eval/simple_value.cpp index 734a92be788..766a4f1eb23 100644 --- a/eval/src/vespa/eval/eval/simple_value.cpp +++ b/eval/src/vespa/eval/eval/simple_value.cpp @@ -28,7 +28,7 @@ struct CreateSimpleValueBuilderBase { //----------------------------------------------------------------------------- // look up a full address in the map directly -struct LookupView : public Value::Index::View { +struct SimpleLookupView : public Value::Index::View { using Labels = std::vector<vespalib::string>; using Map = std::map<Labels, size_t>; @@ -37,7 +37,7 @@ struct LookupView : public Value::Index::View { Labels my_addr; Map::const_iterator pos; - LookupView(const Map &map_in, size_t num_dims) + SimpleLookupView(const Map &map_in, size_t num_dims) : map(map_in), my_addr(num_dims, ""), pos(map.end()) {} void lookup(ConstArrayRef<const vespalib::stringref*> addr) override { @@ -61,7 +61,7 @@ struct LookupView : public Value::Index::View { //----------------------------------------------------------------------------- // find matching mappings for a partial address with brute force filtering -struct FilterView : public Value::Index::View { +struct SimpleFilterView : public Value::Index::View { using Labels = std::vector<vespalib::string>; using Map = std::map<Labels, size_t>; @@ -81,7 +81,7 @@ struct FilterView : public Value::Index::View { return true; } - FilterView(const Map &map_in, const std::vector<size_t> &match_dims_in, size_t num_dims) + SimpleFilterView(const Map &map_in, const std::vector<size_t> &match_dims_in, size_t num_dims) : map(map_in), match_dims(match_dims_in), extract_dims(), query(match_dims.size(), ""), pos(map.end()) { auto my_pos = match_dims.begin(); @@ -124,7 +124,7 @@ struct FilterView : public Value::Index::View { //----------------------------------------------------------------------------- // iterate all mappings -struct IterateView : public Value::Index::View { +struct SimpleIterateView : public Value::Index::View { using Labels = std::vector<vespalib::string>; using Map = std::map<Labels, size_t>; @@ -132,7 +132,7 @@ struct IterateView : public Value::Index::View { const Map ↦ Map::const_iterator pos; - IterateView(const Map &map_in) + SimpleIterateView(const Map &map_in) : map(map_in), pos(map.end()) {} void lookup(ConstArrayRef<const vespalib::stringref*>) override { @@ -197,11 +197,11 @@ std::unique_ptr<Value::Index::View> SimpleValue::create_view(const std::vector<size_t> &dims) const { if (dims.empty()) { - return std::make_unique<IterateView>(_index); + return std::make_unique<SimpleIterateView>(_index); } else if (dims.size() == _num_mapped_dims) { - return std::make_unique<LookupView>(_index, _num_mapped_dims); + return std::make_unique<SimpleLookupView>(_index, _num_mapped_dims); } else { - return std::make_unique<FilterView>(_index, dims, _num_mapped_dims); + return std::make_unique<SimpleFilterView>(_index, dims, _num_mapped_dims); } } diff --git a/eval/src/vespa/eval/instruction/CMakeLists.txt b/eval/src/vespa/eval/instruction/CMakeLists.txt index 7211ebbfb49..4f2c59e34e1 100644 --- a/eval/src/vespa/eval/instruction/CMakeLists.txt +++ b/eval/src/vespa/eval/instruction/CMakeLists.txt @@ -2,6 +2,15 @@ vespa_add_library(eval_instruction OBJECT SOURCES + dense_cell_range_function.cpp + dense_dot_product_function.cpp + dense_lambda_peek_function.cpp + dense_lambda_peek_optimizer.cpp + dense_matmul_function.cpp + dense_multi_matmul_function.cpp + dense_simple_expand_function.cpp + dense_tensor_peek_function.cpp + dense_xw_product_function.cpp generic_concat.cpp generic_create.cpp generic_join.cpp @@ -11,5 +20,6 @@ vespa_add_library(eval_instruction OBJECT generic_peek.cpp generic_reduce.cpp generic_rename.cpp + index_lookup_table.cpp join_with_number_function.cpp ) diff --git a/eval/src/vespa/eval/instruction/dense_cell_range_function.cpp b/eval/src/vespa/eval/instruction/dense_cell_range_function.cpp new file mode 100644 index 00000000000..5f43e16088d --- /dev/null +++ b/eval/src/vespa/eval/instruction/dense_cell_range_function.cpp @@ -0,0 +1,49 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "dense_cell_range_function.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> +#include <vespa/eval/eval/value.h> + +namespace vespalib::eval { + +using namespace tensor_function; + +namespace { + +template <typename CT> +void my_cell_range_op(InterpretedFunction::State &state, uint64_t param) { + const auto &self = unwrap_param<DenseCellRangeFunction>(param); + auto old_cells = state.peek(0).cells().typify<CT>(); + ConstArrayRef<CT> new_cells(&old_cells[self.offset()], self.length()); + state.pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type(), TypedCells(new_cells))); +} + +struct MyCellRangeOp { + template <typename CT> + static auto invoke() { return my_cell_range_op<CT>; } +}; + +} // namespace <unnamed> + +DenseCellRangeFunction::DenseCellRangeFunction(const ValueType &result_type, + const TensorFunction &child, + size_t offset, size_t length) + : tensor_function::Op1(result_type, child), + _offset(offset), + _length(length) +{ +} + +DenseCellRangeFunction::~DenseCellRangeFunction() = default; + +InterpretedFunction::Instruction +DenseCellRangeFunction::compile_self(EngineOrFactory, Stash &) const +{ + assert(result_type().cell_type() == child().result_type().cell_type()); + + using MyTypify = TypifyCellType; + auto op = typify_invoke<1,MyTypify,MyCellRangeOp>(result_type().cell_type()); + return InterpretedFunction::Instruction(op, wrap_param<DenseCellRangeFunction>(*this)); +} + +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_cell_range_function.h b/eval/src/vespa/eval/instruction/dense_cell_range_function.h index adc1047f8f3..07793f5d72c 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_cell_range_function.h +++ b/eval/src/vespa/eval/instruction/dense_cell_range_function.h @@ -4,28 +4,28 @@ #include <vespa/eval/eval/tensor_function.h> -namespace vespalib::tensor { +namespace vespalib::eval { /** * Tensor function creating a view to a continuous range of cells in * another tensor. The value type will (typically) change, but the * cell type must remain the same. **/ -class DenseCellRangeFunction : public eval::tensor_function::Op1 +class DenseCellRangeFunction : public tensor_function::Op1 { private: size_t _offset; size_t _length; public: - DenseCellRangeFunction(const eval::ValueType &result_type, - const eval::TensorFunction &child, + DenseCellRangeFunction(const ValueType &result_type, + const TensorFunction &child, size_t offset, size_t length); ~DenseCellRangeFunction() override; size_t offset() const { return _offset; } size_t length() const { return _length; } - eval::InterpretedFunction::Instruction compile_self(eval::EngineOrFactory engine, Stash &stash) const override; + InterpretedFunction::Instruction compile_self(EngineOrFactory engine, Stash &stash) const override; bool result_is_mutable() const override { return child().result_is_mutable(); } }; -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_dot_product_function.cpp b/eval/src/vespa/eval/instruction/dense_dot_product_function.cpp index 7b68bb52e3a..cc746c4db83 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_dot_product_function.cpp +++ b/eval/src/vespa/eval/instruction/dense_dot_product_function.cpp @@ -1,26 +1,20 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "dense_dot_product_function.h" -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> #include <vespa/eval/eval/operation.h> #include <vespa/eval/eval/value.h> - #include <cblas.h> -namespace vespalib::tensor { +namespace vespalib::eval { -using eval::ValueType; -using eval::TensorFunction; -using eval::TensorEngine; -using eval::as; -using eval::Aggr; -using namespace eval::tensor_function; -using namespace eval::operation; +using namespace tensor_function; +using namespace operation; namespace { template <typename LCT, typename RCT> -void my_dot_product_op(eval::InterpretedFunction::State &state, uint64_t) { +void my_dot_product_op(InterpretedFunction::State &state, uint64_t) { auto lhs_cells = state.peek(1).cells().typify<LCT>(); auto rhs_cells = state.peek(0).cells().typify<RCT>(); double result = 0.0; @@ -29,21 +23,21 @@ void my_dot_product_op(eval::InterpretedFunction::State &state, uint64_t) { for (size_t i = 0; i < lhs_cells.size(); ++i) { result += ((*lhs++) * (*rhs++)); } - state.pop_pop_push(state.stash.create<eval::DoubleValue>(result)); + state.pop_pop_push(state.stash.create<DoubleValue>(result)); } -void my_cblas_double_dot_product_op(eval::InterpretedFunction::State &state, uint64_t) { +void my_cblas_double_dot_product_op(InterpretedFunction::State &state, uint64_t) { auto lhs_cells = state.peek(1).cells().typify<double>(); auto rhs_cells = state.peek(0).cells().typify<double>(); double result = cblas_ddot(lhs_cells.size(), lhs_cells.cbegin(), 1, rhs_cells.cbegin(), 1); - state.pop_pop_push(state.stash.create<eval::DoubleValue>(result)); + state.pop_pop_push(state.stash.create<DoubleValue>(result)); } -void my_cblas_float_dot_product_op(eval::InterpretedFunction::State &state, uint64_t) { +void my_cblas_float_dot_product_op(InterpretedFunction::State &state, uint64_t) { auto lhs_cells = state.peek(1).cells().typify<float>(); auto rhs_cells = state.peek(0).cells().typify<float>(); double result = cblas_sdot(lhs_cells.size(), lhs_cells.cbegin(), 1, rhs_cells.cbegin(), 1); - state.pop_pop_push(state.stash.create<eval::DoubleValue>(result)); + state.pop_pop_push(state.stash.create<DoubleValue>(result)); } struct MyDotProductOp { @@ -51,7 +45,7 @@ struct MyDotProductOp { static auto invoke() { return my_dot_product_op<LCT,RCT>; } }; -eval::InterpretedFunction::op_function my_select(CellType lct, CellType rct) { +InterpretedFunction::op_function my_select(ValueType::CellType lct, ValueType::CellType rct) { if (lct == rct) { if (lct == ValueType::CellType::DOUBLE) { return my_cblas_double_dot_product_op; @@ -60,23 +54,23 @@ eval::InterpretedFunction::op_function my_select(CellType lct, CellType rct) { return my_cblas_float_dot_product_op; } } - using MyTypify = eval::TypifyCellType; + using MyTypify = TypifyCellType; return typify_invoke<2,MyTypify,MyDotProductOp>(lct, rct); } -} // namespace vespalib::tensor::<unnamed> +} // namespace <unnamed> -DenseDotProductFunction::DenseDotProductFunction(const eval::TensorFunction &lhs_in, - const eval::TensorFunction &rhs_in) - : eval::tensor_function::Op2(eval::ValueType::double_type(), lhs_in, rhs_in) +DenseDotProductFunction::DenseDotProductFunction(const TensorFunction &lhs_in, + const TensorFunction &rhs_in) + : tensor_function::Op2(ValueType::double_type(), lhs_in, rhs_in) { } -eval::InterpretedFunction::Instruction -DenseDotProductFunction::compile_self(eval::EngineOrFactory, Stash &) const +InterpretedFunction::Instruction +DenseDotProductFunction::compile_self(EngineOrFactory, Stash &) const { auto op = my_select(lhs().result_type().cell_type(), rhs().result_type().cell_type()); - return eval::InterpretedFunction::Instruction(op); + return InterpretedFunction::Instruction(op); } bool @@ -86,7 +80,7 @@ DenseDotProductFunction::compatible_types(const ValueType &res, const ValueType } const TensorFunction & -DenseDotProductFunction::optimize(const eval::TensorFunction &expr, Stash &stash) +DenseDotProductFunction::optimize(const TensorFunction &expr, Stash &stash) { auto reduce = as<Reduce>(expr); if (reduce && (reduce->aggr() == Aggr::SUM)) { @@ -102,4 +96,4 @@ DenseDotProductFunction::optimize(const eval::TensorFunction &expr, Stash &stash return expr; } -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/instruction/dense_dot_product_function.h b/eval/src/vespa/eval/instruction/dense_dot_product_function.h new file mode 100644 index 00000000000..d1c1c0538fc --- /dev/null +++ b/eval/src/vespa/eval/instruction/dense_dot_product_function.h @@ -0,0 +1,23 @@ +// Copyright 2017 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::eval { + +/** + * Tensor function for a dot product between two 1-dimensional dense tensors. + */ +class DenseDotProductFunction : public tensor_function::Op2 +{ +public: + DenseDotProductFunction(const TensorFunction &lhs_in, + const TensorFunction &rhs_in); + InterpretedFunction::Instruction compile_self(EngineOrFactory engine, Stash &stash) const override; + bool result_is_mutable() const override { return true; } + static bool compatible_types(const ValueType &res, const ValueType &lhs, const ValueType &rhs); + static const TensorFunction &optimize(const TensorFunction &expr, Stash &stash); +}; + +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_lambda_peek_function.cpp b/eval/src/vespa/eval/instruction/dense_lambda_peek_function.cpp index cae17e5ebe2..0abcd452645 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_lambda_peek_function.cpp +++ b/eval/src/vespa/eval/instruction/dense_lambda_peek_function.cpp @@ -2,20 +2,12 @@ #include "dense_lambda_peek_function.h" #include "index_lookup_table.h" -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> #include <vespa/eval/eval/value.h> -namespace vespalib::tensor { +namespace vespalib::eval { -using eval::Function; -using eval::InterpretedFunction; -using eval::PassParams; -using eval::TensorEngine; -using eval::TensorFunction; -using eval::Value; -using eval::ValueType; -using eval::as; -using namespace eval::tensor_function; +using namespace tensor_function; namespace { @@ -40,7 +32,7 @@ void my_lambda_peek_op(InterpretedFunction::State &state, uint64_t param) { for (uint32_t idx: lookup_table) { *dst++ = src_cells[idx]; } - state.pop_push(state.stash.create<DenseTensorView>(self.result_type, TypedCells(dst_cells))); + state.pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type, TypedCells(dst_cells))); } struct MyLambdaPeekOp { @@ -48,7 +40,7 @@ struct MyLambdaPeekOp { static auto invoke() { return my_lambda_peek_op<DST_CT, SRC_CT>; } }; -} // namespace vespalib::tensor::<unnamed> +} // namespace <unnamed> DenseLambdaPeekFunction::DenseLambdaPeekFunction(const ValueType &result_type, const TensorFunction &child, @@ -61,10 +53,10 @@ DenseLambdaPeekFunction::DenseLambdaPeekFunction(const ValueType &result_type, DenseLambdaPeekFunction::~DenseLambdaPeekFunction() = default; InterpretedFunction::Instruction -DenseLambdaPeekFunction::compile_self(eval::EngineOrFactory, Stash &stash) const +DenseLambdaPeekFunction::compile_self(EngineOrFactory, Stash &stash) const { const Self &self = stash.create<Self>(result_type(), *_idx_fun); - using MyTypify = eval::TypifyCellType; + using MyTypify = TypifyCellType; auto op = typify_invoke<2,MyTypify,MyLambdaPeekOp>(result_type().cell_type(), child().result_type().cell_type()); assert(child().result_type().is_dense()); return InterpretedFunction::Instruction(op, wrap_param<Self>(self)); @@ -75,4 +67,4 @@ DenseLambdaPeekFunction::idx_fun_dump() const { return _idx_fun->dump_as_lambda(); } -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_lambda_peek_function.h b/eval/src/vespa/eval/instruction/dense_lambda_peek_function.h index 7358ef1427c..c7432ed72ee 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_lambda_peek_function.h +++ b/eval/src/vespa/eval/instruction/dense_lambda_peek_function.h @@ -4,7 +4,7 @@ #include <vespa/eval/eval/tensor_function.h> -namespace vespalib::tensor { +namespace vespalib::eval { /** * Tensor function creating a new dense tensor based on peeking cells @@ -13,19 +13,19 @@ namespace vespalib::tensor { * indexes of the tensor to be created into global cell indexes of the * tensor to be peeked. **/ -class DenseLambdaPeekFunction : public eval::tensor_function::Op1 +class DenseLambdaPeekFunction : public tensor_function::Op1 { private: - std::shared_ptr<eval::Function const> _idx_fun; + std::shared_ptr<Function const> _idx_fun; public: - DenseLambdaPeekFunction(const eval::ValueType &result_type, - const eval::TensorFunction &child, - std::shared_ptr<eval::Function const> idx_fun); + DenseLambdaPeekFunction(const ValueType &result_type, + const TensorFunction &child, + std::shared_ptr<Function const> idx_fun); ~DenseLambdaPeekFunction() override; - eval::InterpretedFunction::Instruction compile_self(eval::EngineOrFactory engine, Stash &stash) const override; + InterpretedFunction::Instruction compile_self(EngineOrFactory engine, Stash &stash) const override; vespalib::string idx_fun_dump() const; bool result_is_mutable() const override { return true; } }; -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_lambda_peek_optimizer.cpp b/eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.cpp index 54ea35e9efe..a2ea24dbf0a 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_lambda_peek_optimizer.cpp +++ b/eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.cpp @@ -1,10 +1,10 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "dense_lambda_peek_optimizer.h" -#include "dense_tensor_view.h" -#include "dense_replace_type_function.h" -#include "dense_cell_range_function.h" #include "dense_lambda_peek_function.h" +#include "dense_cell_range_function.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> +#include <vespa/eval/tensor/dense/dense_replace_type_function.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/node_tools.h> #include <vespa/eval/eval/basic_nodes.h> @@ -14,10 +14,9 @@ #include <vespa/eval/eval/llvm/compile_cache.h> #include <optional> -using namespace vespalib::eval; using namespace vespalib::eval::nodes; -namespace vespalib::tensor { +namespace vespalib::eval { namespace { @@ -164,7 +163,7 @@ struct PeekAnalyzer { } }; -} // namespace vespalib::tensor::<unnamed> +} // namespace <unnamed> const TensorFunction & DenseLambdaPeekOptimizer::optimize(const TensorFunction &expr, Stash &stash) @@ -184,7 +183,7 @@ DenseLambdaPeekOptimizer::optimize(const TensorFunction &expr, Stash &stash) if (result.cell_range && (dst_type.cell_type() == src_type.cell_type())) { auto cell_range = result.cell_range.value(); if (cell_range.is_full(src_type.dense_subspace_size())) { - return DenseReplaceTypeFunction::create_compact(dst_type, get_param, stash); + return tensor::DenseReplaceTypeFunction::create_compact(dst_type, get_param, stash); } else { return stash.create<DenseCellRangeFunction>(dst_type, get_param, cell_range.offset, cell_range.length); @@ -200,4 +199,4 @@ DenseLambdaPeekOptimizer::optimize(const TensorFunction &expr, Stash &stash) return expr; } -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_lambda_peek_optimizer.h b/eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.h index 7d2a0efde76..72a642569a3 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_lambda_peek_optimizer.h +++ b/eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.h @@ -4,7 +4,7 @@ #include <vespa/eval/eval/tensor_function.h> -namespace vespalib::tensor { +namespace vespalib::eval { /** * Tensor lambda optimizer for creating a new dense tensor based on @@ -12,7 +12,7 @@ namespace vespalib::tensor { * wide area of operations (reshape, gather, slice). **/ struct DenseLambdaPeekOptimizer { - static const eval::TensorFunction &optimize(const eval::TensorFunction &expr, Stash &stash); + static const TensorFunction &optimize(const TensorFunction &expr, Stash &stash); }; } diff --git a/eval/src/vespa/eval/tensor/dense/dense_matmul_function.cpp b/eval/src/vespa/eval/instruction/dense_matmul_function.cpp index 23bddc36bb1..554122a67b4 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_matmul_function.cpp +++ b/eval/src/vespa/eval/instruction/dense_matmul_function.cpp @@ -1,23 +1,17 @@ // Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "dense_matmul_function.h" -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> #include <vespa/vespalib/objects/objectvisitor.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/operation.h> #include <cassert> - #include <cblas.h> -namespace vespalib::tensor { +namespace vespalib::eval { -using eval::ValueType; -using eval::TensorFunction; -using eval::TensorEngine; -using eval::as; -using eval::Aggr; -using namespace eval::tensor_function; -using namespace eval::operation; +using namespace tensor_function; +using namespace operation; namespace { @@ -33,9 +27,9 @@ double my_dot_product(const LCT *lhs, const RCT *rhs, size_t lhs_size, size_t co } template <typename LCT, typename RCT, bool lhs_common_inner, bool rhs_common_inner> -void my_matmul_op(eval::InterpretedFunction::State &state, uint64_t param) { +void my_matmul_op(InterpretedFunction::State &state, uint64_t param) { const DenseMatMulFunction::Self &self = unwrap_param<DenseMatMulFunction::Self>(param); - using OCT = typename eval::UnifyCellTypes<LCT,RCT>::type; + using OCT = typename UnifyCellTypes<LCT,RCT>::type; auto lhs_cells = state.peek(1).cells().typify<LCT>(); auto rhs_cells = state.peek(0).cells().typify<RCT>(); auto dst_cells = state.stash.create_array<OCT>(self.lhs_size * self.rhs_size); @@ -49,11 +43,11 @@ void my_matmul_op(eval::InterpretedFunction::State &state, uint64_t param) { } lhs += (lhs_common_inner ? self.common_size : 1); } - state.pop_pop_push(state.stash.create<DenseTensorView>(self.result_type, TypedCells(dst_cells))); + state.pop_pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type, TypedCells(dst_cells))); } template <bool lhs_common_inner, bool rhs_common_inner> -void my_cblas_double_matmul_op(eval::InterpretedFunction::State &state, uint64_t param) { +void my_cblas_double_matmul_op(InterpretedFunction::State &state, uint64_t param) { const DenseMatMulFunction::Self &self = unwrap_param<DenseMatMulFunction::Self>(param); auto lhs_cells = state.peek(1).cells().typify<double>(); auto rhs_cells = state.peek(0).cells().typify<double>(); @@ -63,11 +57,11 @@ void my_cblas_double_matmul_op(eval::InterpretedFunction::State &state, uint64_t lhs_cells.cbegin(), lhs_common_inner ? self.common_size : self.lhs_size, rhs_cells.cbegin(), rhs_common_inner ? self.common_size : self.rhs_size, 0.0, dst_cells.begin(), self.rhs_size); - state.pop_pop_push(state.stash.create<DenseTensorView>(self.result_type, TypedCells(dst_cells))); + state.pop_pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type, TypedCells(dst_cells))); } template <bool lhs_common_inner, bool rhs_common_inner> -void my_cblas_float_matmul_op(eval::InterpretedFunction::State &state, uint64_t param) { +void my_cblas_float_matmul_op(InterpretedFunction::State &state, uint64_t param) { const DenseMatMulFunction::Self &self = unwrap_param<DenseMatMulFunction::Self>(param); auto lhs_cells = state.peek(1).cells().typify<float>(); auto rhs_cells = state.peek(0).cells().typify<float>(); @@ -77,15 +71,15 @@ void my_cblas_float_matmul_op(eval::InterpretedFunction::State &state, uint64_t lhs_cells.cbegin(), lhs_common_inner ? self.common_size : self.lhs_size, rhs_cells.cbegin(), rhs_common_inner ? self.common_size : self.rhs_size, 0.0, dst_cells.begin(), self.rhs_size); - state.pop_pop_push(state.stash.create<DenseTensorView>(self.result_type, TypedCells(dst_cells))); + state.pop_pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type, TypedCells(dst_cells))); } bool is_matrix(const ValueType &type) { return (type.is_dense() && (type.dimensions().size() == 2)); } -bool is_matmul(const eval::ValueType &a, const eval::ValueType &b, - const vespalib::string &reduce_dim, const eval::ValueType &result_type) +bool is_matmul(const ValueType &a, const ValueType &b, + const vespalib::string &reduce_dim, const ValueType &result_type) { size_t npos = ValueType::Dimension::npos; return (is_matrix(a) && is_matrix(b) && is_matrix(result_type) && @@ -131,9 +125,9 @@ struct MyGetFun { } }; -} // namespace vespalib::tensor::<unnamed> +} // namespace <unnamed> -DenseMatMulFunction::Self::Self(const eval::ValueType &result_type_in, +DenseMatMulFunction::Self::Self(const ValueType &result_type_in, size_t lhs_size_in, size_t common_size_in, size_t rhs_size_in) @@ -146,9 +140,9 @@ DenseMatMulFunction::Self::Self(const eval::ValueType &result_type_in, DenseMatMulFunction::Self::~Self() = default; -DenseMatMulFunction::DenseMatMulFunction(const eval::ValueType &result_type, - const eval::TensorFunction &lhs_in, - const eval::TensorFunction &rhs_in, +DenseMatMulFunction::DenseMatMulFunction(const ValueType &result_type, + const TensorFunction &lhs_in, + const TensorFunction &rhs_in, size_t lhs_size, size_t common_size, size_t rhs_size, @@ -165,15 +159,15 @@ DenseMatMulFunction::DenseMatMulFunction(const eval::ValueType &result_type, DenseMatMulFunction::~DenseMatMulFunction() = default; -eval::InterpretedFunction::Instruction -DenseMatMulFunction::compile_self(eval::EngineOrFactory, Stash &stash) const +InterpretedFunction::Instruction +DenseMatMulFunction::compile_self(EngineOrFactory, Stash &stash) const { - using MyTypify = TypifyValue<eval::TypifyCellType,TypifyBool>; + using MyTypify = TypifyValue<TypifyCellType,TypifyBool>; Self &self = stash.create<Self>(result_type(), _lhs_size, _common_size, _rhs_size); auto op = typify_invoke<4,MyTypify,MyGetFun>( lhs().result_type().cell_type(), rhs().result_type().cell_type(), _lhs_common_inner, _rhs_common_inner); - return eval::InterpretedFunction::Instruction(op, wrap_param<DenseMatMulFunction::Self>(self)); + return InterpretedFunction::Instruction(op, wrap_param<DenseMatMulFunction::Self>(self)); } void @@ -188,7 +182,7 @@ DenseMatMulFunction::visit_self(vespalib::ObjectVisitor &visitor) const } const TensorFunction & -DenseMatMulFunction::optimize(const eval::TensorFunction &expr, Stash &stash) +DenseMatMulFunction::optimize(const TensorFunction &expr, Stash &stash) { auto reduce = as<Reduce>(expr); if (reduce && (reduce->aggr() == Aggr::SUM) && (reduce->dimensions().size() == 1)) { @@ -204,4 +198,4 @@ DenseMatMulFunction::optimize(const eval::TensorFunction &expr, Stash &stash) return expr; } -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_matmul_function.h b/eval/src/vespa/eval/instruction/dense_matmul_function.h index bf9779177bb..6e4093e70f3 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_matmul_function.h +++ b/eval/src/vespa/eval/instruction/dense_matmul_function.h @@ -3,23 +3,23 @@ #pragma once #include <vespa/eval/eval/tensor_function.h> -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> -namespace vespalib::tensor { +namespace vespalib::eval { /** * Tensor function for dense matrix multiplication. **/ -class DenseMatMulFunction : public eval::tensor_function::Op2 +class DenseMatMulFunction : public tensor_function::Op2 { - using Super = eval::tensor_function::Op2; + using Super = tensor_function::Op2; public: struct Self { - eval::ValueType result_type; + ValueType result_type; size_t lhs_size; size_t common_size; size_t rhs_size; - Self(const eval::ValueType &result_type_in, + Self(const ValueType &result_type_in, size_t lhs_size_in, size_t common_size_in, size_t rhs_size_in); ~Self(); }; @@ -32,9 +32,9 @@ private: bool _rhs_common_inner; public: - DenseMatMulFunction(const eval::ValueType &result_type, - const eval::TensorFunction &lhs_in, - const eval::TensorFunction &rhs_in, + DenseMatMulFunction(const ValueType &result_type, + const TensorFunction &lhs_in, + const TensorFunction &rhs_in, size_t lhs_size, size_t common_size, size_t rhs_size, @@ -50,9 +50,9 @@ public: bool lhs_common_inner() const { return _lhs_common_inner; } bool rhs_common_inner() const { return _rhs_common_inner; } - eval::InterpretedFunction::Instruction compile_self(eval::EngineOrFactory engine, Stash &stash) const override; + InterpretedFunction::Instruction compile_self(EngineOrFactory engine, Stash &stash) const override; void visit_self(vespalib::ObjectVisitor &visitor) const override; - static const eval::TensorFunction &optimize(const eval::TensorFunction &expr, Stash &stash); + static const TensorFunction &optimize(const TensorFunction &expr, Stash &stash); }; -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_multi_matmul_function.cpp b/eval/src/vespa/eval/instruction/dense_multi_matmul_function.cpp index 8788d621693..cbca2ff14f2 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_multi_matmul_function.cpp +++ b/eval/src/vespa/eval/instruction/dense_multi_matmul_function.cpp @@ -1,24 +1,17 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "dense_multi_matmul_function.h" -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> #include <vespa/vespalib/objects/objectvisitor.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/operation.h> #include <cassert> - #include <cblas.h> -namespace vespalib::tensor { +namespace vespalib::eval { -using eval::ValueType; -using eval::TensorFunction; -using eval::InterpretedFunction; -using eval::TensorEngine; -using eval::as; -using eval::Aggr; -using namespace eval::tensor_function; -using namespace eval::operation; +using namespace tensor_function; +using namespace operation; using Dim = ValueType::Dimension; using DimList = std::vector<Dim>; @@ -43,7 +36,7 @@ void my_cblas_double_multi_matmul_op(InterpretedFunction::State &state, uint64_t rhs, self.rhs_common_inner() ? self.common_size() : self.rhs_size(), 0.0, dst, self.rhs_size()); } - state.pop_pop_push(state.stash.create<DenseTensorView>(self.result_type(), TypedCells(dst_cells))); + state.pop_pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type(), TypedCells(dst_cells))); } void my_cblas_float_multi_matmul_op(InterpretedFunction::State &state, uint64_t param) { @@ -64,10 +57,10 @@ void my_cblas_float_multi_matmul_op(InterpretedFunction::State &state, uint64_t rhs, self.rhs_common_inner() ? self.common_size() : self.rhs_size(), 0.0, dst, self.rhs_size()); } - state.pop_pop_push(state.stash.create<DenseTensorView>(self.result_type(), TypedCells(dst_cells))); + state.pop_pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type(), TypedCells(dst_cells))); } -InterpretedFunction::op_function my_select(CellType cell_type) { +InterpretedFunction::op_function my_select(ValueType::CellType cell_type) { if (cell_type == ValueType::CellType::DOUBLE) { return my_cblas_double_multi_matmul_op; } @@ -124,7 +117,7 @@ struct DimPrefix { bool check_input_type(const ValueType &type, const DimList &relevant) { return (type.is_dense() && (relevant.size() >= 2) && - ((type.cell_type() == CellType::FLOAT) || (type.cell_type() == CellType::DOUBLE))); + ((type.cell_type() == ValueType::CellType::FLOAT) || (type.cell_type() == ValueType::CellType::DOUBLE))); } bool is_multi_matmul(const ValueType &a, const ValueType &b, const vespalib::string &reduce_dim) { @@ -160,7 +153,7 @@ const TensorFunction &create_multi_matmul(const TensorFunction &a, const TensorF } } -} // namespace vespalib::tensor::<unnamed> +} // namespace <unnamed> DenseMultiMatMulFunction::DenseMultiMatMulFunction(const ValueType &result_type, const TensorFunction &lhs_in, @@ -184,7 +177,7 @@ DenseMultiMatMulFunction::DenseMultiMatMulFunction(const ValueType &result_type, DenseMultiMatMulFunction::~DenseMultiMatMulFunction() = default; InterpretedFunction::Instruction -DenseMultiMatMulFunction::compile_self(eval::EngineOrFactory, Stash &) const +DenseMultiMatMulFunction::compile_self(EngineOrFactory, Stash &) const { auto op = my_select(lhs().result_type().cell_type()); return InterpretedFunction::Instruction(op, wrap_param<DenseMultiMatMulFunction>(*this)); @@ -219,4 +212,4 @@ DenseMultiMatMulFunction::optimize(const TensorFunction &expr, Stash &stash) return expr; } -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_multi_matmul_function.h b/eval/src/vespa/eval/instruction/dense_multi_matmul_function.h index 17ad6438593..289ba6c4d89 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_multi_matmul_function.h +++ b/eval/src/vespa/eval/instruction/dense_multi_matmul_function.h @@ -2,19 +2,19 @@ #pragma once -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> #include <vespa/eval/eval/tensor_function.h> -namespace vespalib::tensor { +namespace vespalib::eval { /** * Tensor function for multiple dense matrix multiplications. This is * an extension to normal matrix multiplication where the tensors * combined may have more than 2 dimensions. **/ -class DenseMultiMatMulFunction : public eval::tensor_function::Op2 +class DenseMultiMatMulFunction : public tensor_function::Op2 { - using Super = eval::tensor_function::Op2; + using Super = tensor_function::Op2; private: size_t _lhs_size; size_t _common_size; @@ -24,9 +24,9 @@ private: bool _rhs_common_inner; public: - DenseMultiMatMulFunction(const eval::ValueType &result_type, - const eval::TensorFunction &lhs_in, - const eval::TensorFunction &rhs_in, + DenseMultiMatMulFunction(const ValueType &result_type, + const TensorFunction &lhs_in, + const TensorFunction &rhs_in, size_t lhs_size, size_t common_size, size_t rhs_size, @@ -44,9 +44,9 @@ public: bool lhs_common_inner() const { return _lhs_common_inner; } bool rhs_common_inner() const { return _rhs_common_inner; } - eval::InterpretedFunction::Instruction compile_self(eval::EngineOrFactory engine, Stash &stash) const override; + InterpretedFunction::Instruction compile_self(EngineOrFactory engine, Stash &stash) const override; void visit_self(vespalib::ObjectVisitor &visitor) const override; - static const eval::TensorFunction &optimize(const eval::TensorFunction &expr, Stash &stash); + static const TensorFunction &optimize(const TensorFunction &expr, Stash &stash); }; -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_simple_expand_function.cpp b/eval/src/vespa/eval/instruction/dense_simple_expand_function.cpp index b2cf390dc11..d0318d371f5 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_simple_expand_function.cpp +++ b/eval/src/vespa/eval/instruction/dense_simple_expand_function.cpp @@ -1,7 +1,7 @@ // Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "dense_simple_expand_function.h" -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> #include <vespa/vespalib/objects/objectvisitor.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/operation.h> @@ -10,25 +10,18 @@ #include <optional> #include <algorithm> -namespace vespalib::tensor { +namespace vespalib::eval{ using vespalib::ArrayRef; -using eval::Value; -using eval::ValueType; -using eval::TensorFunction; -using eval::TensorEngine; -using eval::TypifyCellType; -using eval::as; - -using namespace eval::operation; -using namespace eval::tensor_function; +using namespace operation; +using namespace tensor_function; using Inner = DenseSimpleExpandFunction::Inner; -using op_function = eval::InterpretedFunction::op_function; -using Instruction = eval::InterpretedFunction::Instruction; -using State = eval::InterpretedFunction::State; +using op_function = InterpretedFunction::op_function; +using Instruction = InterpretedFunction::Instruction; +using State = InterpretedFunction::State; namespace { @@ -44,7 +37,7 @@ template <typename LCT, typename RCT, typename Fun, bool rhs_inner> void my_simple_expand_op(State &state, uint64_t param) { using ICT = typename std::conditional<rhs_inner,RCT,LCT>::type; using OCT = typename std::conditional<rhs_inner,LCT,RCT>::type; - using DCT = typename eval::UnifyCellTypes<ICT,OCT>::type; + using DCT = typename UnifyCellTypes<ICT,OCT>::type; using OP = typename std::conditional<rhs_inner,SwapArgs2<Fun>,Fun>::type; const ExpandParams ¶ms = unwrap_param<ExpandParams>(param); OP my_op(params.function); @@ -56,7 +49,7 @@ void my_simple_expand_op(State &state, uint64_t param) { apply_op2_vec_num(dst, inner_cells.begin(), outer_cell, inner_cells.size(), my_op); dst += inner_cells.size(); } - state.pop_pop_push(state.stash.create<DenseTensorView>(params.result_type, TypedCells(dst_cells))); + state.pop_pop_push(state.stash.create<tensor::DenseTensorView>(params.result_type, TypedCells(dst_cells))); } //----------------------------------------------------------------------------- @@ -85,7 +78,7 @@ std::optional<Inner> detect_simple_expand(const TensorFunction &lhs, const Tenso } } -} // namespace vespalib::tensor::<unnamed> +} // namespace <unnamed> //----------------------------------------------------------------------------- @@ -102,7 +95,7 @@ DenseSimpleExpandFunction::DenseSimpleExpandFunction(const ValueType &result_typ DenseSimpleExpandFunction::~DenseSimpleExpandFunction() = default; Instruction -DenseSimpleExpandFunction::compile_self(eval::EngineOrFactory, Stash &stash) const +DenseSimpleExpandFunction::compile_self(EngineOrFactory, Stash &stash) const { size_t result_size = result_type().dense_subspace_size(); const ExpandParams ¶ms = stash.create<ExpandParams>(result_type(), result_size, function()); @@ -130,4 +123,4 @@ DenseSimpleExpandFunction::optimize(const TensorFunction &expr, Stash &stash) return expr; } -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_simple_expand_function.h b/eval/src/vespa/eval/instruction/dense_simple_expand_function.h index c5c40559c1b..cca051fcde9 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_simple_expand_function.h +++ b/eval/src/vespa/eval/instruction/dense_simple_expand_function.h @@ -5,7 +5,7 @@ #include <vespa/eval/eval/tensor_function.h> #include <vespa/eval/eval/operation.h> -namespace vespalib::tensor { +namespace vespalib::eval { /** * Tensor function for simple expanding join operations on dense @@ -16,24 +16,24 @@ namespace vespalib::tensor { * input is nested inside all the dimensions from the other input * within the result (trivial dimensions are again ignored). **/ -class DenseSimpleExpandFunction : public eval::tensor_function::Join +class DenseSimpleExpandFunction : public tensor_function::Join { - using Super = eval::tensor_function::Join; + using Super = tensor_function::Join; public: enum class Inner : uint8_t { LHS, RHS }; - using join_fun_t = vespalib::eval::operation::op2_t; + using join_fun_t = operation::op2_t; private: Inner _inner; public: - DenseSimpleExpandFunction(const eval::ValueType &result_type, + DenseSimpleExpandFunction(const ValueType &result_type, const TensorFunction &lhs, const TensorFunction &rhs, join_fun_t function_in, Inner inner_in); ~DenseSimpleExpandFunction() override; Inner inner() const { return _inner; } - eval::InterpretedFunction::Instruction compile_self(eval::EngineOrFactory engine, Stash &stash) const override; - static const eval::TensorFunction &optimize(const eval::TensorFunction &expr, Stash &stash); + InterpretedFunction::Instruction compile_self(EngineOrFactory engine, Stash &stash) const override; + static const TensorFunction &optimize(const TensorFunction &expr, Stash &stash); }; -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.cpp b/eval/src/vespa/eval/instruction/dense_tensor_peek_function.cpp index f4725cae803..daad4da947b 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.cpp +++ b/eval/src/vespa/eval/instruction/dense_tensor_peek_function.cpp @@ -1,28 +1,19 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "dense_tensor_peek_function.h" -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> #include <vespa/eval/eval/value.h> -#include <vespa/eval/tensor/tensor.h> -namespace vespalib::tensor { +namespace vespalib::eval { -using eval::Value; -using eval::DoubleValue; -using eval::ValueType; -using eval::TensorSpec; -using eval::TensorFunction; -using eval::TensorEngine; -using Child = eval::TensorFunction::Child; +using Child = TensorFunction::Child; using SpecVector = std::vector<std::pair<int64_t,size_t>>; -using eval::as; -using namespace eval::tensor_function; +using namespace tensor_function; namespace { - template <typename CT> -void my_tensor_peek_op(eval::InterpretedFunction::State &state, uint64_t param) { +void my_tensor_peek_op(InterpretedFunction::State &state, uint64_t param) { const SpecVector &spec = unwrap_param<SpecVector>(param); size_t idx = 0; size_t factor = 1; @@ -49,7 +40,7 @@ struct MyTensorPeekOp { static auto invoke() { return my_tensor_peek_op<CT>; } }; -} // namespace vespalib::tensor::<unnamed> +} // namespace <unnamed> DenseTensorPeekFunction::DenseTensorPeekFunction(std::vector<Child> children, std::vector<std::pair<int64_t,size_t>> spec) @@ -69,16 +60,16 @@ DenseTensorPeekFunction::push_children(std::vector<Child::CREF> &target) const } } -eval::InterpretedFunction::Instruction -DenseTensorPeekFunction::compile_self(eval::EngineOrFactory, Stash &) const +InterpretedFunction::Instruction +DenseTensorPeekFunction::compile_self(EngineOrFactory, Stash &) const { - using MyTypify = eval::TypifyCellType; + using MyTypify = TypifyCellType; auto op = typify_invoke<1,MyTypify,MyTensorPeekOp>(_children[0].get().result_type().cell_type()); - return eval::InterpretedFunction::Instruction(op, wrap_param<SpecVector>(_spec)); + return InterpretedFunction::Instruction(op, wrap_param<SpecVector>(_spec)); } const TensorFunction & -DenseTensorPeekFunction::optimize(const eval::TensorFunction &expr, Stash &stash) +DenseTensorPeekFunction::optimize(const TensorFunction &expr, Stash &stash) { if (auto peek = as<Peek>(expr)) { const ValueType &peek_type = peek->param_type(); @@ -106,4 +97,4 @@ DenseTensorPeekFunction::optimize(const eval::TensorFunction &expr, Stash &stash return expr; } -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.h b/eval/src/vespa/eval/instruction/dense_tensor_peek_function.h index e38bdab3811..37979cd592d 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.h +++ b/eval/src/vespa/eval/instruction/dense_tensor_peek_function.h @@ -4,12 +4,12 @@ #include <vespa/eval/eval/tensor_function.h> -namespace vespalib::tensor { +namespace vespalib::eval { /** * Tensor function for looking at the cell value of a dense tensor. */ -class DenseTensorPeekFunction : public eval::TensorFunction +class DenseTensorPeekFunction : public TensorFunction { private: // first child is the tensor we want to peek @@ -24,11 +24,11 @@ private: public: DenseTensorPeekFunction(std::vector<Child> children, std::vector<std::pair<int64_t,size_t>> spec); ~DenseTensorPeekFunction(); - const eval::ValueType &result_type() const override { return eval::DoubleValue::shared_type(); } + const ValueType &result_type() const override { return DoubleValue::shared_type(); } void push_children(std::vector<Child::CREF> &children) const override; - eval::InterpretedFunction::Instruction compile_self(eval::EngineOrFactory engine, Stash &stash) const override; + InterpretedFunction::Instruction compile_self(EngineOrFactory engine, Stash &stash) const override; bool result_is_mutable() const override { return true; } - static const eval::TensorFunction &optimize(const eval::TensorFunction &expr, Stash &stash); + static const TensorFunction &optimize(const TensorFunction &expr, Stash &stash); }; -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_xw_product_function.cpp b/eval/src/vespa/eval/instruction/dense_xw_product_function.cpp index 3e60109bbe6..fdcef97e277 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_xw_product_function.cpp +++ b/eval/src/vespa/eval/instruction/dense_xw_product_function.cpp @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "dense_xw_product_function.h" -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> #include <vespa/vespalib/objects/objectvisitor.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/operation.h> @@ -9,15 +9,10 @@ #include <cblas.h> -namespace vespalib::tensor { +namespace vespalib::eval { -using eval::ValueType; -using eval::TensorFunction; -using eval::TensorEngine; -using eval::as; -using eval::Aggr; -using namespace eval::tensor_function; -using namespace eval::operation; +using namespace tensor_function; +using namespace operation; namespace { @@ -33,9 +28,9 @@ double my_dot_product(const LCT *lhs, const RCT *rhs, size_t vector_size, size_t } template <typename LCT, typename RCT, bool common_inner> -void my_xw_product_op(eval::InterpretedFunction::State &state, uint64_t param) { +void my_xw_product_op(InterpretedFunction::State &state, uint64_t param) { const DenseXWProductFunction::Self &self = unwrap_param<DenseXWProductFunction::Self>(param); - using OCT = typename eval::UnifyCellTypes<LCT,RCT>::type; + using OCT = typename UnifyCellTypes<LCT,RCT>::type; auto vector_cells = state.peek(1).cells().typify<LCT>(); auto matrix_cells = state.peek(0).cells().typify<RCT>(); auto dst_cells = state.stash.create_array<OCT>(self.result_size); @@ -45,11 +40,11 @@ void my_xw_product_op(eval::InterpretedFunction::State &state, uint64_t param) { *dst++ = my_dot_product<LCT,RCT,common_inner>(vector_cells.cbegin(), matrix, self.vector_size, self.result_size); matrix += (common_inner ? self.vector_size : 1); } - state.pop_pop_push(state.stash.create<DenseTensorView>(self.result_type, TypedCells(dst_cells))); + state.pop_pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type, TypedCells(dst_cells))); } template <bool common_inner> -void my_cblas_double_xw_product_op(eval::InterpretedFunction::State &state, uint64_t param) { +void my_cblas_double_xw_product_op(InterpretedFunction::State &state, uint64_t param) { const DenseXWProductFunction::Self &self = unwrap_param<DenseXWProductFunction::Self>(param); auto vector_cells = state.peek(1).cells().typify<double>(); auto matrix_cells = state.peek(0).cells().typify<double>(); @@ -59,11 +54,11 @@ void my_cblas_double_xw_product_op(eval::InterpretedFunction::State &state, uint common_inner ? self.vector_size : self.result_size, 1.0, matrix_cells.cbegin(), common_inner ? self.vector_size : self.result_size, vector_cells.cbegin(), 1, 0.0, dst_cells.begin(), 1); - state.pop_pop_push(state.stash.create<DenseTensorView>(self.result_type, TypedCells(dst_cells))); + state.pop_pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type, TypedCells(dst_cells))); } template <bool common_inner> -void my_cblas_float_xw_product_op(eval::InterpretedFunction::State &state, uint64_t param) { +void my_cblas_float_xw_product_op(InterpretedFunction::State &state, uint64_t param) { const DenseXWProductFunction::Self &self = unwrap_param<DenseXWProductFunction::Self>(param); auto vector_cells = state.peek(1).cells().typify<float>(); auto matrix_cells = state.peek(0).cells().typify<float>(); @@ -73,7 +68,7 @@ void my_cblas_float_xw_product_op(eval::InterpretedFunction::State &state, uint6 common_inner ? self.vector_size : self.result_size, 1.0, matrix_cells.cbegin(), common_inner ? self.vector_size : self.result_size, vector_cells.cbegin(), 1, 0.0, dst_cells.begin(), 1); - state.pop_pop_push(state.stash.create<DenseTensorView>(self.result_type, TypedCells(dst_cells))); + state.pop_pop_push(state.stash.create<tensor::DenseTensorView>(self.result_type, TypedCells(dst_cells))); } bool isDenseTensor(const ValueType &type, size_t d) { @@ -117,9 +112,9 @@ struct MyXWProductOp { } }; -} // namespace vespalib::tensor::<unnamed> +} // namespace <unnamed> -DenseXWProductFunction::Self::Self(const eval::ValueType &result_type_in, +DenseXWProductFunction::Self::Self(const ValueType &result_type_in, size_t vector_size_in, size_t result_size_in) : result_type(result_type_in), vector_size(vector_size_in), @@ -128,28 +123,28 @@ DenseXWProductFunction::Self::Self(const eval::ValueType &result_type_in, } DenseXWProductFunction::Self::~Self() = default; -DenseXWProductFunction::DenseXWProductFunction(const eval::ValueType &result_type, - const eval::TensorFunction &vector_in, - const eval::TensorFunction &matrix_in, +DenseXWProductFunction::DenseXWProductFunction(const ValueType &result_type, + const TensorFunction &vector_in, + const TensorFunction &matrix_in, size_t vector_size, size_t result_size, bool common_inner) - : eval::tensor_function::Op2(result_type, vector_in, matrix_in), + : tensor_function::Op2(result_type, vector_in, matrix_in), _vector_size(vector_size), _result_size(result_size), _common_inner(common_inner) { } -eval::InterpretedFunction::Instruction -DenseXWProductFunction::compile_self(eval::EngineOrFactory, Stash &stash) const +InterpretedFunction::Instruction +DenseXWProductFunction::compile_self(EngineOrFactory, Stash &stash) const { Self &self = stash.create<Self>(result_type(), _vector_size, _result_size); - using MyTypify = TypifyValue<eval::TypifyCellType,vespalib::TypifyBool>; + using MyTypify = TypifyValue<TypifyCellType,vespalib::TypifyBool>; auto op = typify_invoke<3,MyTypify,MyXWProductOp>(lhs().result_type().cell_type(), rhs().result_type().cell_type(), _common_inner); - return eval::InterpretedFunction::Instruction(op, wrap_param<DenseXWProductFunction::Self>(self)); + return InterpretedFunction::Instruction(op, wrap_param<DenseXWProductFunction::Self>(self)); } void @@ -162,7 +157,7 @@ DenseXWProductFunction::visit_self(vespalib::ObjectVisitor &visitor) const } const TensorFunction & -DenseXWProductFunction::optimize(const eval::TensorFunction &expr, Stash &stash) +DenseXWProductFunction::optimize(const TensorFunction &expr, Stash &stash) { const Reduce *reduce = as<Reduce>(expr); if (reduce && (reduce->aggr() == Aggr::SUM)) { @@ -182,4 +177,4 @@ DenseXWProductFunction::optimize(const eval::TensorFunction &expr, Stash &stash) return expr; } -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/dense_xw_product_function.h b/eval/src/vespa/eval/instruction/dense_xw_product_function.h index fa0f8724aeb..e66afa72f93 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_xw_product_function.h +++ b/eval/src/vespa/eval/instruction/dense_xw_product_function.h @@ -3,22 +3,22 @@ #pragma once #include <vespa/eval/eval/tensor_function.h> -#include "dense_tensor_view.h" +#include <vespa/eval/tensor/dense/dense_tensor_view.h> -namespace vespalib::tensor { +namespace vespalib::eval { /** * Tensor function for product of one 1-dimensional and one 2-dimensional dense tensor. */ -class DenseXWProductFunction : public eval::tensor_function::Op2 +class DenseXWProductFunction : public tensor_function::Op2 { - using Super = eval::tensor_function::Op2; + using Super = tensor_function::Op2; public: struct Self { - eval::ValueType result_type; + ValueType result_type; size_t vector_size; size_t result_size; - Self(const eval::ValueType &result_type_in, + Self(const ValueType &result_type_in, size_t vector_size_in, size_t result_size_in); ~Self(); }; @@ -29,9 +29,9 @@ private: bool _common_inner; public: - DenseXWProductFunction(const eval::ValueType &result_type, - const eval::TensorFunction &vector_in, - const eval::TensorFunction &matrix_in, + DenseXWProductFunction(const ValueType &result_type, + const TensorFunction &vector_in, + const TensorFunction &matrix_in, size_t vector_size, size_t result_size, bool common_inner); @@ -44,10 +44,10 @@ public: size_t result_size() const { return _result_size; } bool common_inner() const { return _common_inner; } - eval::InterpretedFunction::Instruction compile_self(eval::EngineOrFactory engine, Stash &stash) const override; + InterpretedFunction::Instruction compile_self(EngineOrFactory engine, Stash &stash) const override; void visit_self(vespalib::ObjectVisitor &visitor) const override; - static const eval::TensorFunction &optimize(const eval::TensorFunction &expr, Stash &stash); + static const TensorFunction &optimize(const TensorFunction &expr, Stash &stash); }; -} // namespace vespalib::tensor +} // namespace diff --git a/eval/src/vespa/eval/tensor/dense/index_lookup_table.cpp b/eval/src/vespa/eval/instruction/index_lookup_table.cpp index 99a05762a34..629f43afd96 100644 --- a/eval/src/vespa/eval/tensor/dense/index_lookup_table.cpp +++ b/eval/src/vespa/eval/instruction/index_lookup_table.cpp @@ -5,12 +5,7 @@ #include <vespa/eval/eval/key_gen.h> #include <vespa/eval/eval/llvm/compiled_function.h> -namespace vespalib::tensor { - -using eval::CompiledFunction; -using eval::Function; -using eval::PassParams; -using eval::ValueType; +namespace vespalib::eval { namespace { diff --git a/eval/src/vespa/eval/tensor/dense/index_lookup_table.h b/eval/src/vespa/eval/instruction/index_lookup_table.h index ee5776ef5ca..ed26b0ba2f3 100644 --- a/eval/src/vespa/eval/tensor/dense/index_lookup_table.h +++ b/eval/src/vespa/eval/instruction/index_lookup_table.h @@ -8,11 +8,9 @@ #include <map> namespace vespalib::eval { + class ValueType; class Function; -} - -namespace vespalib::tensor { /** * Pre-computed index tables used by DenseLambdaPeekFunction. The @@ -63,7 +61,7 @@ public: IndexLookupTable() = delete; static size_t num_cached(); static size_t count_refs(); - static Token::UP create(const eval::Function &idx_fun, const eval::ValueType &type); + static Token::UP create(const Function &idx_fun, const ValueType &type); }; } diff --git a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp index b50092c88b5..04aad776e43 100644 --- a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp +++ b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp @@ -8,24 +8,24 @@ #include "sparse/direct_sparse_tensor_builder.h" #include "dense/dense_tensor.h" #include "dense/typed_dense_tensor_builder.h" -#include "dense/dense_dot_product_function.h" -#include "dense/dense_xw_product_function.h" -#include "dense/dense_matmul_function.h" -#include "dense/dense_multi_matmul_function.h" +#include <vespa/eval/instruction/dense_dot_product_function.h> +#include <vespa/eval/instruction/dense_xw_product_function.h> +#include <vespa/eval/instruction/dense_matmul_function.h> +#include <vespa/eval/instruction/dense_multi_matmul_function.h> #include "dense/dense_fast_rename_optimizer.h" #include "dense/dense_add_dimension_optimizer.h" #include "dense/dense_single_reduce_function.h" #include "dense/dense_remove_dimension_optimizer.h" -#include "dense/dense_lambda_peek_optimizer.h" +#include <vespa/eval/instruction/dense_lambda_peek_optimizer.h> #include "dense/dense_lambda_function.h" -#include "dense/dense_simple_expand_function.h" +#include <vespa/eval/instruction/dense_simple_expand_function.h> #include "dense/dense_simple_join_function.h" #include "dense/dense_number_join_function.h" #include "dense/dense_pow_as_map_optimizer.h" #include "dense/dense_simple_map_function.h" #include "dense/vector_from_doubles_function.h" #include "dense/dense_tensor_create_function.h" -#include "dense/dense_tensor_peek_function.h" +#include <vespa/eval/instruction/dense_tensor_peek_function.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/simple_value.h> @@ -284,10 +284,10 @@ DefaultTensorEngine::optimize(const TensorFunction &expr, Stash &stash) const } while (!nodes.empty()) { const Child &child = nodes.back().get(); - child.set(DenseDotProductFunction::optimize(child.get(), stash)); - child.set(DenseXWProductFunction::optimize(child.get(), stash)); - child.set(DenseMatMulFunction::optimize(child.get(), stash)); - child.set(DenseMultiMatMulFunction::optimize(child.get(), stash)); + child.set(eval::DenseDotProductFunction::optimize(child.get(), stash)); + child.set(eval::DenseXWProductFunction::optimize(child.get(), stash)); + child.set(eval::DenseMatMulFunction::optimize(child.get(), stash)); + child.set(eval::DenseMultiMatMulFunction::optimize(child.get(), stash)); nodes.pop_back(); } } @@ -298,13 +298,13 @@ DefaultTensorEngine::optimize(const TensorFunction &expr, Stash &stash) const } while (!nodes.empty()) { const Child &child = nodes.back().get(); - child.set(DenseSimpleExpandFunction::optimize(child.get(), stash)); + child.set(eval::DenseSimpleExpandFunction::optimize(child.get(), stash)); child.set(DenseAddDimensionOptimizer::optimize(child.get(), stash)); child.set(DenseRemoveDimensionOptimizer::optimize(child.get(), stash)); child.set(VectorFromDoublesFunction::optimize(child.get(), stash)); child.set(DenseTensorCreateFunction::optimize(child.get(), stash)); - child.set(DenseTensorPeekFunction::optimize(child.get(), stash)); - child.set(DenseLambdaPeekOptimizer::optimize(child.get(), stash)); + child.set(eval::DenseTensorPeekFunction::optimize(child.get(), stash)); + child.set(eval::DenseLambdaPeekOptimizer::optimize(child.get(), stash)); child.set(DenseLambdaFunction::optimize(child.get(), stash)); child.set(DenseFastRenameOptimizer::optimize(child.get(), stash)); child.set(DensePowAsMapOptimizer::optimize(child.get(), stash)); diff --git a/eval/src/vespa/eval/tensor/dense/CMakeLists.txt b/eval/src/vespa/eval/tensor/dense/CMakeLists.txt index 4ad4c3ac960..2c7732d7720 100644 --- a/eval/src/vespa/eval/tensor/dense/CMakeLists.txt +++ b/eval/src/vespa/eval/tensor/dense/CMakeLists.txt @@ -2,20 +2,13 @@ vespa_add_library(eval_tensor_dense OBJECT SOURCES dense_add_dimension_optimizer.cpp - dense_cell_range_function.cpp dense_dimension_combiner.cpp - dense_dot_product_function.cpp dense_fast_rename_optimizer.cpp dense_lambda_function.cpp - dense_lambda_peek_function.cpp - dense_lambda_peek_optimizer.cpp - dense_matmul_function.cpp - dense_multi_matmul_function.cpp dense_number_join_function.cpp dense_pow_as_map_optimizer.cpp dense_remove_dimension_optimizer.cpp dense_replace_type_function.cpp - dense_simple_expand_function.cpp dense_simple_join_function.cpp dense_simple_map_function.cpp dense_single_reduce_function.cpp @@ -24,12 +17,9 @@ vespa_add_library(eval_tensor_dense OBJECT dense_tensor_cells_iterator.cpp dense_tensor_create_function.cpp dense_tensor_modify.cpp - dense_tensor_peek_function.cpp dense_tensor_reduce.cpp dense_tensor_value_builder.cpp dense_tensor_view.cpp - dense_xw_product_function.cpp - index_lookup_table.cpp mutable_dense_tensor_view.cpp onnx_wrapper.cpp typed_cells_dispatch.cpp diff --git a/eval/src/vespa/eval/tensor/dense/dense_cell_range_function.cpp b/eval/src/vespa/eval/tensor/dense/dense_cell_range_function.cpp deleted file mode 100644 index a9ef5a89a1c..00000000000 --- a/eval/src/vespa/eval/tensor/dense/dense_cell_range_function.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "dense_cell_range_function.h" -#include "dense_tensor_view.h" -#include <vespa/eval/eval/value.h> - -namespace vespalib::tensor { - -using eval::Value; -using eval::ValueType; -using eval::TensorFunction; -using eval::TensorEngine; -using eval::as; -using namespace eval::tensor_function; - -namespace { - -template <typename CT> -void my_cell_range_op(eval::InterpretedFunction::State &state, uint64_t param) { - const auto &self = unwrap_param<DenseCellRangeFunction>(param); - auto old_cells = state.peek(0).cells().typify<CT>(); - ConstArrayRef<CT> new_cells(&old_cells[self.offset()], self.length()); - state.pop_push(state.stash.create<DenseTensorView>(self.result_type(), TypedCells(new_cells))); -} - -struct MyCellRangeOp { - template <typename CT> - static auto invoke() { return my_cell_range_op<CT>; } -}; - -} // namespace vespalib::tensor::<unnamed> - -DenseCellRangeFunction::DenseCellRangeFunction(const eval::ValueType &result_type, - const eval::TensorFunction &child, - size_t offset, size_t length) - : eval::tensor_function::Op1(result_type, child), - _offset(offset), - _length(length) -{ -} - -DenseCellRangeFunction::~DenseCellRangeFunction() = default; - -eval::InterpretedFunction::Instruction -DenseCellRangeFunction::compile_self(eval::EngineOrFactory, Stash &) const -{ - assert(result_type().cell_type() == child().result_type().cell_type()); - - using MyTypify = eval::TypifyCellType; - auto op = typify_invoke<1,MyTypify,MyCellRangeOp>(result_type().cell_type()); - return eval::InterpretedFunction::Instruction(op, wrap_param<DenseCellRangeFunction>(*this)); -} - -} // namespace vespalib::tensor diff --git a/eval/src/vespa/eval/tensor/dense/dense_dot_product_function.h b/eval/src/vespa/eval/tensor/dense/dense_dot_product_function.h deleted file mode 100644 index 28f49035860..00000000000 --- a/eval/src/vespa/eval/tensor/dense/dense_dot_product_function.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 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 a dot product between two 1-dimensional dense tensors. - */ -class DenseDotProductFunction : public eval::tensor_function::Op2 -{ -private: - using ValueType = eval::ValueType; -public: - DenseDotProductFunction(const eval::TensorFunction &lhs_in, - const eval::TensorFunction &rhs_in); - eval::InterpretedFunction::Instruction compile_self(eval::EngineOrFactory engine, Stash &stash) const override; - bool result_is_mutable() const override { return true; } - static bool compatible_types(const ValueType &res, const ValueType &lhs, const ValueType &rhs); - static const eval::TensorFunction &optimize(const eval::TensorFunction &expr, Stash &stash); -}; - -} // namespace vespalib::tensor |