diff options
author | HÃ¥vard Pettersen <3535158+havardpe@users.noreply.github.com> | 2020-12-04 23:30:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-04 23:30:44 +0100 |
commit | 57a44319f652817b5841d4d3d476a070235970f5 (patch) | |
tree | 62358c0d4ef6d332ba9598f6574463a63e9b67b5 | |
parent | a90709008ec0d108ee9a2e26bda20e39a10424b5 (diff) | |
parent | 15fe399eff5ade4ea12dded37c28ec4629899015 (diff) |
Merge pull request #15678 from vespa-engine/havardpe/remove-engine-or-factory
remove EngineOrFactory
27 files changed, 73 insertions, 356 deletions
diff --git a/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp b/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp index 183caa7e3e0..cc3aed67387 100644 --- a/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/tensorfieldvalue.cpp @@ -4,14 +4,14 @@ #include <vespa/document/base/exceptions.h> #include <vespa/document/datatype/tensor_data_type.h> #include <vespa/vespalib/util/xmlstream.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value_codec.h> #include <vespa/eval/eval/value.h> #include <ostream> #include <cassert> -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::TensorSpec; using vespalib::eval::ValueType; using namespace vespalib::xml; @@ -51,7 +51,7 @@ TensorFieldValue::TensorFieldValue(const TensorFieldValue &rhs) _altered(true) { if (rhs._tensor) { - _tensor = EngineOrFactory::get().copy(*rhs._tensor); + _tensor = FastValueBuilderFactory::get().copy(*rhs._tensor); } } @@ -78,7 +78,7 @@ TensorFieldValue::operator=(const TensorFieldValue &rhs) if (&_dataType == &rhs._dataType || !rhs._tensor || _dataType.isAssignableType(rhs._tensor->type())) { if (rhs._tensor) { - _tensor = EngineOrFactory::get().copy(*rhs._tensor); + _tensor = FastValueBuilderFactory::get().copy(*rhs._tensor); } else { _tensor.reset(); } @@ -109,7 +109,7 @@ TensorFieldValue::make_empty_if_not_existing() { if (!_tensor) { TensorSpec empty_spec(_dataType.getTensorType().to_spec()); - _tensor = EngineOrFactory::get().from_spec(empty_spec); + _tensor = value_from_spec(empty_spec, FastValueBuilderFactory::get()); } } diff --git a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp index eaa5a484ad1..6567b8cb6b5 100644 --- a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp @@ -22,7 +22,8 @@ #include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/backtrace.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/eval/eval/value.h> #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/base/exceptions.h> @@ -41,7 +42,7 @@ using vespalib::nbostream; using vespalib::Memory; using vespalib::stringref; using vespalib::compression::CompressionConfig; -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; namespace document { @@ -372,7 +373,7 @@ VespaDocumentDeserializer::readTensor() std::unique_ptr<vespalib::eval::Value> tensor; if (length != 0) { nbostream wrapStream(_stream.peek(), length); - tensor = EngineOrFactory::get().decode(wrapStream); + tensor = vespalib::eval::decode_value(wrapStream, FastValueBuilderFactory::get()); if (wrapStream.size() != 0) { throw DeserializeException("Leftover bytes deserializing tensor field value.", VESPA_STRLOC); } diff --git a/document/src/vespa/document/update/tensor_add_update.cpp b/document/src/vespa/document/update/tensor_add_update.cpp index d71ab7d922c..c9ffad2a789 100644 --- a/document/src/vespa/document/update/tensor_add_update.cpp +++ b/document/src/vespa/document/update/tensor_add_update.cpp @@ -9,7 +9,7 @@ #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/document/util/serializableexceptions.h> #include <vespa/eval/eval/value.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/tensor/partial_update.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/stllike/asciistream.h> @@ -20,7 +20,7 @@ using vespalib::IllegalArgumentException; using vespalib::IllegalStateException; using vespalib::make_string; -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; using vespalib::tensor::TensorPartialUpdate; namespace document { @@ -86,8 +86,8 @@ TensorAddUpdate::applyTo(const vespalib::eval::Value &tensor) const { auto addTensor = _tensor->getAsTensorPtr(); if (addTensor) { - auto engine = EngineOrFactory::get(); - return TensorPartialUpdate::add(tensor, *addTensor, engine); + const auto &factory = FastValueBuilderFactory::get(); + return TensorPartialUpdate::add(tensor, *addTensor, factory); } return {}; } diff --git a/document/src/vespa/document/update/tensor_modify_update.cpp b/document/src/vespa/document/update/tensor_modify_update.cpp index 970550b7c88..4da93d0ae46 100644 --- a/document/src/vespa/document/update/tensor_modify_update.cpp +++ b/document/src/vespa/document/update/tensor_modify_update.cpp @@ -10,7 +10,7 @@ #include <vespa/document/util/serializableexceptions.h> #include <vespa/eval/eval/operation.h> #include <vespa/eval/eval/value.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/tensor/partial_update.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/stllike/asciistream.h> @@ -22,7 +22,7 @@ using vespalib::IllegalArgumentException; using vespalib::IllegalStateException; using vespalib::make_string; using vespalib::eval::ValueType; -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; using vespalib::tensor::TensorPartialUpdate; using join_fun_t = double (*)(double, double); @@ -163,8 +163,8 @@ TensorModifyUpdate::applyTo(const vespalib::eval::Value &tensor) const { auto cellsTensor = _tensor->getAsTensorPtr(); if (cellsTensor) { - auto engine = EngineOrFactory::get(); - return TensorPartialUpdate::modify(tensor, getJoinFunction(_operation), *cellsTensor, engine); + const auto &factory = FastValueBuilderFactory::get(); + return TensorPartialUpdate::modify(tensor, getJoinFunction(_operation), *cellsTensor, factory); } return {}; } @@ -213,8 +213,7 @@ verifyCellsTensorIsSparse(const vespalib::eval::Value *cellsTensor) if (cellsTensor == nullptr) { return; } - auto engine = EngineOrFactory::get(); - if (TensorPartialUpdate::check_suitably_sparse(*cellsTensor, engine)) { + if (cellsTensor->type().is_sparse()) { return; } vespalib::string err = make_string("Expected cells tensor to be sparse, but has type '%s'", diff --git a/document/src/vespa/document/update/tensor_remove_update.cpp b/document/src/vespa/document/update/tensor_remove_update.cpp index f04728e95a4..7b81581aeed 100644 --- a/document/src/vespa/document/update/tensor_remove_update.cpp +++ b/document/src/vespa/document/update/tensor_remove_update.cpp @@ -6,7 +6,7 @@ #include <vespa/document/fieldvalue/document.h> #include <vespa/document/fieldvalue/tensorfieldvalue.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/tensor/partial_update.h> #include <vespa/eval/eval/value.h> #include <vespa/vespalib/objects/nbostream.h> @@ -19,7 +19,7 @@ using vespalib::IllegalStateException; using vespalib::make_string; using vespalib::eval::Value; using vespalib::eval::ValueType; -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; using vespalib::tensor::TensorPartialUpdate; namespace document { @@ -110,8 +110,8 @@ TensorRemoveUpdate::applyTo(const vespalib::eval::Value &tensor) const { auto addressTensor = _tensor->getAsTensorPtr(); if (addressTensor) { - auto engine = EngineOrFactory::get(); - return TensorPartialUpdate::remove(tensor, *addressTensor, engine); + const auto &factory = FastValueBuilderFactory::get(); + return TensorPartialUpdate::remove(tensor, *addressTensor, factory); } return {}; } @@ -160,8 +160,7 @@ verifyAddressTensorIsSparse(const Value *addressTensor) if (addressTensor == nullptr) { throw IllegalStateException("Address tensor is not set", VESPA_STRLOC); } - auto engine = EngineOrFactory::get(); - if (TensorPartialUpdate::check_suitably_sparse(*addressTensor, engine)) { + if (addressTensor->type().is_sparse()) { return; } auto err = make_string("Expected address tensor to be sparse, but has type '%s'", diff --git a/eval/CMakeLists.txt b/eval/CMakeLists.txt index c4fd211897b..d9dc7e587b0 100644 --- a/eval/CMakeLists.txt +++ b/eval/CMakeLists.txt @@ -15,7 +15,6 @@ vespa_define_module( src/tests/eval/array_array_map src/tests/eval/compile_cache src/tests/eval/compiled_function - src/tests/eval/engine_or_factory src/tests/eval/fast_sparse_map src/tests/eval/fast_value src/tests/eval/function diff --git a/eval/src/tests/eval/engine_or_factory/CMakeLists.txt b/eval/src/tests/eval/engine_or_factory/CMakeLists.txt deleted file mode 100644 index f0bd0f63251..00000000000 --- a/eval/src/tests/eval/engine_or_factory/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(eval_engine_or_factory_test_app TEST - SOURCES - engine_or_factory_test.cpp - DEPENDS - vespaeval - GTest::GTest -) -vespa_add_test(NAME eval_engine_or_factory_test_app COMMAND eval_engine_or_factory_test_app) -vespa_add_executable(eval_engine_or_factory_override_test_app TEST - SOURCES - engine_or_factory_override_test.cpp - DEPENDS - vespaeval - GTest::GTest -) -vespa_add_test(NAME eval_engine_or_factory_override_test_app COMMAND eval_engine_or_factory_override_test_app) diff --git a/eval/src/tests/eval/engine_or_factory/engine_or_factory_override_test.cpp b/eval/src/tests/eval/engine_or_factory/engine_or_factory_override_test.cpp deleted file mode 100644 index b06e2723d74..00000000000 --- a/eval/src/tests/eval/engine_or_factory/engine_or_factory_override_test.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/eval/eval/engine_or_factory.h> -#include <vespa/eval/eval/fast_value.h> -#include <vespa/eval/eval/simple_value.h> -#include <vespa/vespalib/util/exceptions.h> -#include <vespa/vespalib/gtest/gtest.h> - -using namespace vespalib::eval; - -TEST(EngineOrFactoryOverrideTest, set_can_override_get_result) { - EngineOrFactory::set(SimpleValueBuilderFactory::get()); - EXPECT_EQ(EngineOrFactory::get().to_string(), "SimpleValueBuilderFactory"); -} - -TEST(EngineOrFactoryOverrideTest, set_with_same_value_is_allowed) { - EngineOrFactory::set(SimpleValueBuilderFactory::get()); -} - -TEST(EngineOrFactoryOverrideTest, set_with_another_value_is_not_allowed) { - EXPECT_THROW(EngineOrFactory::set(FastValueBuilderFactory::get()), vespalib::IllegalStateException); -} - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/eval/src/tests/eval/engine_or_factory/engine_or_factory_test.cpp b/eval/src/tests/eval/engine_or_factory/engine_or_factory_test.cpp deleted file mode 100644 index 26e8e8e75ec..00000000000 --- a/eval/src/tests/eval/engine_or_factory/engine_or_factory_test.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/eval/eval/engine_or_factory.h> -#include <vespa/eval/eval/fast_value.h> -#include <vespa/eval/eval/simple_value.h> -#include <vespa/vespalib/util/exceptions.h> -#include <vespa/vespalib/gtest/gtest.h> - -using namespace vespalib::eval; - -TEST(EngineOrFactoryTest, default_is_fast_value_builder_factory) { - EXPECT_EQ(EngineOrFactory::get().to_string(), "FastValueBuilderFactory"); -} - -TEST(EngineOrFactoryTest, set_with_same_value_is_allowed) { - EngineOrFactory::set(FastValueBuilderFactory::get()); -} - -TEST(EngineOrFactoryTest, set_with_another_value_is_not_allowed) { - EXPECT_THROW(EngineOrFactory::set(SimpleValueBuilderFactory::get()), vespalib::IllegalStateException); -} - -GTEST_MAIN_RUN_ALL_TESTS() diff --git a/eval/src/vespa/eval/eval/CMakeLists.txt b/eval/src/vespa/eval/eval/CMakeLists.txt index 66c807565cc..d32841520a6 100644 --- a/eval/src/vespa/eval/eval/CMakeLists.txt +++ b/eval/src/vespa/eval/eval/CMakeLists.txt @@ -9,7 +9,6 @@ vespa_add_library(eval_eval OBJECT compile_tensor_function.cpp delete_node.cpp double_value_builder.cpp - engine_or_factory.cpp fast_forest.cpp fast_sparse_map.cpp fast_value.cpp diff --git a/eval/src/vespa/eval/eval/engine_or_factory.cpp b/eval/src/vespa/eval/eval/engine_or_factory.cpp deleted file mode 100644 index 5b46fd61951..00000000000 --- a/eval/src/vespa/eval/eval/engine_or_factory.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "engine_or_factory.h" -#include "fast_value.h" -#include "simple_value.h" -#include "value_codec.h" -#include <vespa/eval/instruction/generic_concat.h> -#include <vespa/eval/instruction/generic_join.h> -#include <vespa/eval/instruction/generic_map.h> -#include <vespa/eval/instruction/generic_merge.h> -#include <vespa/eval/instruction/generic_reduce.h> -#include <vespa/eval/instruction/generic_rename.h> -#include "tensor_engine.h" -#include <vespa/vespalib/data/memory.h> -#include <vespa/vespalib/objects/nbostream.h> -#include <vespa/vespalib/util/exceptions.h> -#include <vespa/vespalib/util/stash.h> -#include <vespa/vespalib/util/stringfmt.h> - -using vespalib::make_string_short::fmt; - -using namespace vespalib::eval::instruction; - -namespace vespalib::eval { - -EngineOrFactory EngineOrFactory::_default{FastValueBuilderFactory::get()}; - - -EngineOrFactory -EngineOrFactory::get_shared(EngineOrFactory hint) -{ - static EngineOrFactory shared{hint}; - return shared; -} - -TensorSpec -EngineOrFactory::to_spec(const Value &value) const -{ - if (is_engine()) { - return engine().to_spec(value); - } else { - return factory(), spec_from_value(value); - } -} - -std::unique_ptr<Value> -EngineOrFactory::from_spec(const TensorSpec &spec) const -{ - if (is_engine()) { - return engine().from_spec(spec); - } else { - return value_from_spec(spec, factory()); - } -} - -void -EngineOrFactory::encode(const Value &value, nbostream &output) const -{ - if (is_engine()) { - return engine().encode(value, output); - } else { - return factory(), encode_value(value, output); - } -} - -std::unique_ptr<Value> -EngineOrFactory::decode(nbostream &input) const -{ - if (is_engine()) { - return engine().decode(input); - } else { - return decode_value(input, factory()); - } -} - -std::unique_ptr<Value> -EngineOrFactory::copy(const Value &value) -{ - nbostream stream; - encode(value, stream); - return decode(stream); -} - -void -EngineOrFactory::set(EngineOrFactory wanted) -{ - assert(wanted.is_factory()); - auto engine = get_shared(wanted); - if (engine._value != wanted._value) { - auto msg = fmt("EngineOrFactory: trying to set implementation to [%s] when [%s] is already in use", - wanted.to_string().c_str(), engine.to_string().c_str()); - throw IllegalStateException(msg); - } -} - -EngineOrFactory -EngineOrFactory::get() -{ - return get_shared(_default); -} - -vespalib::string -EngineOrFactory::to_string() const -{ - if (is_factory()) { - if (&factory() == &FastValueBuilderFactory::get()) { - return "FastValueBuilderFactory"; - } - if (&factory() == &SimpleValueBuilderFactory::get()) { - return "SimpleValueBuilderFactory"; - } - } - return "???"; -} - -} diff --git a/eval/src/vespa/eval/eval/engine_or_factory.h b/eval/src/vespa/eval/eval/engine_or_factory.h deleted file mode 100644 index 7269f22159d..00000000000 --- a/eval/src/vespa/eval/eval/engine_or_factory.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include "aggr.h" -#include "tensor_spec.h" -#include "operation.h" -#include <variant> - -namespace vespalib { -class Stash; -class nbostream; -} - -namespace vespalib::eval { - -struct TensorEngine; -struct ValueBuilderFactory; -struct TensorFunction; - -/** - * This utility class contains a reference to either a TensorEngine or - * a ValueBuilderFactory. This is needed during a transition period to - * support both evaluation models. We want to get rid of the - * TensorEngine concept since using the Value API directly removes the - * need to constrain operations to only calculate on tensors belonging - * to the same tensor engine. The factory is a hint to the preferred - * Value implementation. - **/ -class EngineOrFactory { -private: - using engine_t = const TensorEngine *; - using factory_t = const ValueBuilderFactory *; - std::variant<engine_t,factory_t> _value; - static EngineOrFactory _default; - static EngineOrFactory get_shared(EngineOrFactory hint); -public: - EngineOrFactory(const ValueBuilderFactory &factory_in) : _value(&factory_in) {} - bool is_engine() const { return std::holds_alternative<engine_t>(_value); } - bool is_factory() const { return std::holds_alternative<factory_t>(_value); } - const TensorEngine &engine() const { return *std::get<engine_t>(_value); } - const ValueBuilderFactory &factory() const { return *std::get<factory_t>(_value); } - // functions that can be called with either engine or factory - TensorSpec to_spec(const Value &value) const; - std::unique_ptr<Value> from_spec(const TensorSpec &spec) const; - void encode(const Value &value, nbostream &output) const; - std::unique_ptr<Value> decode(nbostream &input) const; - std::unique_ptr<Value> copy(const Value &value); - // global switch with default; call set before get to override the default - static void set(EngineOrFactory wanted); - static EngineOrFactory get(); - // try to describe the value held by this object as a human-readable string - vespalib::string to_string() const; -}; - -} diff --git a/eval/src/vespa/eval/eval/value.cpp b/eval/src/vespa/eval/eval/value.cpp index 267d2443112..7abc8d568cb 100644 --- a/eval/src/vespa/eval/eval/value.cpp +++ b/eval/src/vespa/eval/eval/value.cpp @@ -1,7 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "value.h" +#include "value_codec.h" #include <vespa/vespalib/util/typify.h> +#include <vespa/vespalib/objects/nbostream.h> namespace vespalib { namespace eval { @@ -62,5 +64,13 @@ ValueType ScalarValue<T>::_type = ValueType::make_type(get_cell_type<T>(), {}); template class ScalarValue<double>; template class ScalarValue<float>; +std::unique_ptr<Value> +ValueBuilderFactory::copy(const Value &value) const +{ + nbostream stream; + encode_value(value, stream); + return decode_value(stream, *this); +} + } // namespace vespalib::eval } // namespace vespalib diff --git a/eval/src/vespa/eval/eval/value.h b/eval/src/vespa/eval/eval/value.h index e876ba7b472..cf4e21029fc 100644 --- a/eval/src/vespa/eval/eval/value.h +++ b/eval/src/vespa/eval/eval/value.h @@ -198,6 +198,7 @@ struct ValueBuilderFactory { { return create_value_builder<T>(type, type.count_mapped_dimensions(), type.dense_subspace_size(), 1); } + std::unique_ptr<Value> copy(const Value &value) const; virtual ~ValueBuilderFactory() {} protected: virtual std::unique_ptr<ValueBuilderBase> create_value_builder_base(const ValueType &type, diff --git a/eval/src/vespa/eval/tensor/partial_update.cpp b/eval/src/vespa/eval/tensor/partial_update.cpp index 82cd5553741..0f3ebe9537b 100644 --- a/eval/src/vespa/eval/tensor/partial_update.cpp +++ b/eval/src/vespa/eval/tensor/partial_update.cpp @@ -417,42 +417,4 @@ TensorPartialUpdate::remove(const Value &input, const Value &remove_spec, const input, remove_spec, factory); } -Value::UP -TensorPartialUpdate::modify(const Value &input, join_fun_t function, - const Value &modifier, EngineOrFactory engine) -{ - if (engine.is_engine()) { - abort(); - } - return modify(input, function, modifier, engine.factory()); - -} - -Value::UP -TensorPartialUpdate::add(const Value &input, const Value &add_cells, EngineOrFactory engine) -{ - if (engine.is_engine()) { - abort(); - } - return add(input, add_cells, engine.factory()); -} - -Value::UP -TensorPartialUpdate::remove(const Value &input, const Value &remove_spec, EngineOrFactory engine) -{ - if (engine.is_engine()) { - abort(); - } - return remove(input, remove_spec, engine.factory()); -} - -bool -TensorPartialUpdate::check_suitably_sparse(const Value &modifier, const EngineOrFactory engine) -{ - if (engine.is_engine()) { - abort(); - } - return modifier.type().is_sparse(); -} - } // namespace diff --git a/eval/src/vespa/eval/tensor/partial_update.h b/eval/src/vespa/eval/tensor/partial_update.h index 6bbef6a8189..b3e9d32fca8 100644 --- a/eval/src/vespa/eval/tensor/partial_update.h +++ b/eval/src/vespa/eval/tensor/partial_update.h @@ -2,7 +2,7 @@ #pragma once -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/operation.h> @@ -39,15 +39,6 @@ struct TensorPartialUpdate { * Returns null pointer if these constraints are violated. **/ static Value::UP remove(const Value &input, const Value &remove_spec, const ValueBuilderFactory &factory); - - /* Backwards compatibility adapters. TODO: remove */ - using EngineOrFactory = vespalib::eval::EngineOrFactory; - static Value::UP modify(const Value &input, join_fun_t function, - const Value &modifier, EngineOrFactory factory); - static Value::UP add(const Value &input, const Value &add_cells, EngineOrFactory factory); - static Value::UP remove(const Value &input, const Value &remove_spec, EngineOrFactory factory); - /** Check if the given value can be used as a modifier or remove_spec */ - static bool check_suitably_sparse(const Value &modifier, EngineOrFactory factory); }; } // namespace diff --git a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp index 3c1fc8a4622..559e8fd14cd 100644 --- a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp +++ b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp @@ -11,7 +11,8 @@ #include <vespa/config/common/exceptions.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value_cache/constant_value.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/searchcommon/common/schemaconfigurer.h> #include <vespa/searchcore/config/config-ranking-constants.h> #include <vespa/searchcore/config/config-onnx-models.h> @@ -41,7 +42,7 @@ using vespa::config::search::core::OnnxModelsConfig; using vespa::config::search::core::VerifyRanksetupConfig; using vespalib::eval::BadConstantValue; using vespalib::eval::ConstantValue; -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::SimpleConstantValue; using vespalib::eval::TensorSpec; using vespalib::eval::Value; @@ -96,7 +97,7 @@ struct DummyConstantValueRepo : IConstantValueRepo { for (const auto &entry: cfg.constant) { if (entry.name == name) { try { - auto tensor = EngineOrFactory::get().from_spec(TensorSpec(entry.type)); + auto tensor = vespalib::eval::value_from_spec(TensorSpec(entry.type), FastValueBuilderFactory::get()); return std::make_unique<SimpleConstantValue>(std::move(tensor)); } catch (std::exception &) { return std::make_unique<BadConstantValue>(); diff --git a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp index 2f6625aaa11..6ad2f69ae7a 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/requestcontext.cpp @@ -1,7 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "requestcontext.h" -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/searchlib/attribute/attributevector.h> #include <vespa/searchlib/fef/properties.h> #include <vespa/vespalib/objects/nbostream.h> @@ -10,7 +11,7 @@ #include <vespa/log/log.h> LOG_SETUP(".proton.matching.requestcontext"); -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; namespace proton { @@ -52,7 +53,7 @@ RequestContext::get_query_tensor(const vespalib::string& tensor_name) const const vespalib::string& value = property.get(); vespalib::nbostream stream(value.data(), value.size()); try { - return EngineOrFactory::get().decode(stream); + return decode_value(stream, FastValueBuilderFactory::get()); } catch (vespalib::Exception& ex) { LOG(warning, "Query tensor '%s' could not be deserialized: %s", tensor_name.c_str(), ex.getMessage().c_str()); diff --git a/searchcore/src/vespa/searchcore/proton/server/proton.cpp b/searchcore/src/vespa/searchcore/proton/server/proton.cpp index c2b57734903..dddca6a9ddd 100644 --- a/searchcore/src/vespa/searchcore/proton/server/proton.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/proton.cpp @@ -17,8 +17,6 @@ #include <vespa/document/base/exceptions.h> #include <vespa/document/datatype/documenttype.h> #include <vespa/document/repo/documenttyperepo.h> -#include <vespa/eval/eval/engine_or_factory.h> -#include <vespa/eval/eval/fast_value.h> #include <vespa/searchcore/proton/flushengine/flush_engine_explorer.h> #include <vespa/searchcore/proton/flushengine/flushengine.h> #include <vespa/searchcore/proton/flushengine/tls_stats_factory.h> @@ -56,7 +54,6 @@ using search::transactionlog::DomainStats; using vespa::config::search::core::ProtonConfig; using vespa::config::search::core::internal::InternalProtonType; using vespalib::compression::CompressionConfig; -using vespalib::eval::EngineOrFactory; namespace proton { @@ -74,17 +71,6 @@ convert(InternalProtonType::Packetcompresstype type) } void -set_tensor_implementation(const ProtonConfig& cfg) -{ - if (cfg.tensorImplementation == ProtonConfig::TensorImplementation::TENSOR_ENGINE) { - LOG(error, "Old tensor engine implementation no longer available"); - } else if (cfg.tensorImplementation == ProtonConfig::TensorImplementation::FAST_VALUE) { - EngineOrFactory::set(vespalib::eval::FastValueBuilderFactory::get()); - } - LOG(info, "Tensor implementation used: %s", EngineOrFactory::get().to_string().c_str()); -} - -void setBucketCheckSumType(const ProtonConfig & proton) { switch (proton.bucketdb.checksumtype) { @@ -268,7 +254,6 @@ Proton::init(const BootstrapConfig::SP & configSnapshot) const ProtonConfig &protonConfig = configSnapshot->getProtonConfig(); const HwInfo & hwInfo = configSnapshot->getHwInfo(); - set_tensor_implementation(protonConfig); setBucketCheckSumType(protonConfig); setFS4Compression(protonConfig); _diskMemUsageSampler = std::make_unique<DiskMemUsageSampler>(protonConfig.basedir, diff --git a/searchlib/src/vespa/searchlib/attribute/createsinglestd.cpp b/searchlib/src/vespa/searchlib/attribute/createsinglestd.cpp index 29033944d4b..ffaec9d0779 100644 --- a/searchlib/src/vespa/searchlib/attribute/createsinglestd.cpp +++ b/searchlib/src/vespa/searchlib/attribute/createsinglestd.cpp @@ -7,7 +7,7 @@ #include "singlenumericattribute.hpp" #include "singlestringattribute.h" #include "singleboolattribute.h" -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/searchlib/tensor/dense_tensor_attribute.h> #include <vespa/searchlib/tensor/serialized_tensor_attribute.h> #include <vespa/searchlib/tensor/serialized_fast_value_attribute.h> @@ -47,10 +47,8 @@ AttributeFactory::createSingleStd(stringref name, const Config & info) case BasicType::TENSOR: if (info.tensorType().is_dense()) { return std::make_shared<tensor::DenseTensorAttribute>(name, info); - } else if (vespalib::eval::EngineOrFactory::get().is_factory()) { - return std::make_shared<tensor::SerializedFastValueAttribute>(name, info); } else { - return std::make_shared<tensor::SerializedTensorAttribute>(name, info); + return std::make_shared<tensor::SerializedFastValueAttribute>(name, info); } case BasicType::REFERENCE: return std::make_shared<attribute::ReferenceAttribute>(name, info); diff --git a/searchlib/src/vespa/searchlib/features/constant_tensor_executor.h b/searchlib/src/vespa/searchlib/features/constant_tensor_executor.h index 835cd1a8e36..f95cbfa4726 100644 --- a/searchlib/src/vespa/searchlib/features/constant_tensor_executor.h +++ b/searchlib/src/vespa/searchlib/features/constant_tensor_executor.h @@ -6,7 +6,8 @@ #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value.h> #include <vespa/eval/eval/value_type.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/vespalib/util/stash.h> namespace search::features { @@ -31,9 +32,9 @@ public: return stash.create<ConstantTensorExecutor>(std::move(tensor)); } static fef::FeatureExecutor &createEmpty(const vespalib::eval::ValueType &valueType, vespalib::Stash &stash) { - const auto engine = vespalib::eval::EngineOrFactory::get(); + const auto &factory = vespalib::eval::FastValueBuilderFactory::get(); auto spec = vespalib::eval::TensorSpec(valueType.to_spec()); - return stash.create<ConstantTensorExecutor>(engine.from_spec(spec)); + return stash.create<ConstantTensorExecutor>(vespalib::eval::value_from_spec(spec, factory)); } static fef::FeatureExecutor &createEmpty(vespalib::Stash &stash) { return createEmpty(vespalib::eval::ValueType::double_type(), stash); diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp index 83beee98634..06f0de631be 100644 --- a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp @@ -10,7 +10,8 @@ #include <vespa/searchlib/attribute/floatbase.h> #include <vespa/searchlib/attribute/multinumericattribute.h> #include <vespa/searchlib/attribute/multienumattribute.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/stash.h> @@ -19,7 +20,7 @@ LOG_SETUP(".features.dotproduct"); using namespace search::attribute; using namespace search::fef; -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::TypedCells; using vespalib::hwaccelrated::IAccelrated; @@ -500,7 +501,7 @@ template <typename T> ArrayParam<T>::ArrayParam(vespalib::nbostream & stream) { using vespalib::typify_invoke; using vespalib::eval::TypifyCellType; - auto tensor = EngineOrFactory::get().decode(stream); + auto tensor = vespalib::eval::decode_value(stream, FastValueBuilderFactory::get()); if (tensor->type().is_dense()) { TypedCells cells = tensor->cells(); typify_invoke<1,TypifyCellType,CopyCellsToVector<T>>(cells.type, cells, values); diff --git a/searchlib/src/vespa/searchlib/features/queryfeature.cpp b/searchlib/src/vespa/searchlib/features/queryfeature.cpp index 9cded69d5de..c6196fcbc7f 100644 --- a/searchlib/src/vespa/searchlib/features/queryfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/queryfeature.cpp @@ -12,6 +12,8 @@ #include <vespa/searchlib/fef/feature_type.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/eval/eval/value_type.h> +#include <vespa/eval/eval/value_codec.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/vespalib/locale/c.h> #include <cerrno> @@ -119,7 +121,7 @@ createTensorExecutor(const IQueryEnvironment &env, if (prop.found() && !prop.get().empty()) { const vespalib::string &value = prop.get(); vespalib::nbostream stream(value.data(), value.size()); - auto tensor = vespalib::eval::EngineOrFactory::get().decode(stream); + auto tensor = vespalib::eval::decode_value(stream, vespalib::eval::FastValueBuilderFactory::get()); if (!TensorDataType::isAssignableType(valueType, tensor->type())) { LOG(warning, "Query feature type is '%s' but other tensor type is '%s'", valueType.to_spec().c_str(), tensor->type().to_spec().c_str()); diff --git a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h index b0cb076f65b..72520830d06 100644 --- a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h +++ b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h @@ -4,7 +4,8 @@ #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/searchcommon/attribute/iattributecontext.h> #include <vespa/searchlib/attribute/attributevector.h> #include <vespa/searchlib/attribute/attribute_blueprint_params.h> @@ -34,7 +35,7 @@ public: } vespalib::eval::Value::UP get_query_tensor(const vespalib::string& tensor_name) const override { if (_query_tensor && (tensor_name == _query_tensor_name)) { - return vespalib::eval::EngineOrFactory::get().from_spec(*_query_tensor); + return vespalib::eval::value_from_spec(*_query_tensor, vespalib::eval::FastValueBuilderFactory::get()); } return {}; } diff --git a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp index 62beb25be22..8cda62682d0 100644 --- a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp @@ -3,7 +3,7 @@ #include "direct_tensor_attribute.h" #include "direct_tensor_saver.h" -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> #include <vespa/eval/eval/value.h> #include <vespa/fastlib/io/bufferedfile.h> #include <vespa/searchlib/attribute/readerbase.h> @@ -14,7 +14,7 @@ #include "tensor_deserialize.h" #include "tensor_attribute.hpp" -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; namespace search::tensor { @@ -73,7 +73,7 @@ DirectTensorAttribute::set_tensor(DocId lid, std::unique_ptr<vespalib::eval::Val void DirectTensorAttribute::setTensor(DocId lid, const vespalib::eval::Value &tensor) { - set_tensor(lid, EngineOrFactory::get().copy(tensor)); + set_tensor(lid, FastValueBuilderFactory::get().copy(tensor)); } std::unique_ptr<vespalib::eval::Value> @@ -86,7 +86,7 @@ DirectTensorAttribute::getTensor(DocId docId) const if (ref.valid()) { auto ptr = _direct_store.get_tensor(ref); if (ptr) { - return EngineOrFactory::get().copy(*ptr); + return FastValueBuilderFactory::get().copy(*ptr); } } std::unique_ptr<vespalib::eval::Value> empty; diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp index 96049375180..e0b21290284 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp @@ -7,13 +7,14 @@ #include <vespa/vespalib/data/slime/cursor.h> #include <vespa/vespalib/data/slime/inserter.h> #include <vespa/vespalib/util/rcuvector.hpp> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/value.h> using document::TensorDataType; using document::WrongTensorTypeException; -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::TensorSpec; using vespalib::eval::Value; using vespalib::eval::ValueType; @@ -31,9 +32,9 @@ constexpr size_t DEAD_SLACK = 0x10000u; Value::UP createEmptyTensor(const ValueType &type) { - auto engine = EngineOrFactory::get(); + const auto &factory = FastValueBuilderFactory::get(); TensorSpec empty_spec(type.to_spec()); - return engine.from_spec(empty_spec); + return vespalib::eval::value_from_spec(empty_spec, factory); } vespalib::string makeWrongTensorTypeMsg(const ValueType &fieldTensorType, const ValueType &tensorType) @@ -183,7 +184,7 @@ TensorAttribute::populate_state(vespalib::slime::Cursor& object) const vespalib::eval::Value::UP TensorAttribute::getEmptyTensor() const { - return EngineOrFactory::get().copy(*_emptyTensor); + return FastValueBuilderFactory::get().copy(*_emptyTensor); } vespalib::eval::TypedCells diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_deserialize.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_deserialize.cpp index 35be27bc03b..4fddd092451 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_deserialize.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_deserialize.cpp @@ -2,18 +2,19 @@ #include "tensor_deserialize.h" #include <vespa/document/util/serializableexceptions.h> -#include <vespa/eval/eval/engine_or_factory.h> +#include <vespa/eval/eval/fast_value.h> +#include <vespa/eval/eval/value_codec.h> #include <vespa/eval/eval/value.h> using document::DeserializeException; -using vespalib::eval::EngineOrFactory; +using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::Value; namespace search::tensor { std::unique_ptr<Value> deserialize_tensor(vespalib::nbostream &buffer) { - auto tensor = EngineOrFactory::get().decode(buffer); + auto tensor = vespalib::eval::decode_value(buffer, FastValueBuilderFactory::get()); if (buffer.size() != 0) { throw DeserializeException("Leftover bytes deserializing tensor attribute value.", VESPA_STRLOC); } |