diff options
21 files changed, 46 insertions, 86 deletions
diff --git a/eval/src/vespa/eval/eval/typed_cells.h b/eval/src/vespa/eval/eval/typed_cells.h index a478a419f95..b65fa2b40e4 100644 --- a/eval/src/vespa/eval/eval/typed_cells.h +++ b/eval/src/vespa/eval/eval/typed_cells.h @@ -4,7 +4,7 @@ #include <assert.h> #include <vespa/vespalib/util/arrayref.h> -#include <vespa/eval/eval/value_type.h> +#include <vespa/eval/eval/cell_type.h> namespace vespalib::eval { diff --git a/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.cpp b/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.cpp index ae3e8ad9023..913a386418b 100644 --- a/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.cpp +++ b/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.cpp @@ -2,14 +2,13 @@ #include "mutable_dense_tensor_view.h" -using vespalib::eval::ValueType; +namespace vespalib::eval { -namespace vespalib::tensor { - -MutableDenseTensorView::MutableDenseTensorView(ValueType type_in) - : DenseTensorView(_type), - _type(type_in) +MutableDenseTensorView::MutableDenseTensorView(const ValueType &type_in) + : _type(type_in), + _cells() { + assert(_type.is_dense()); } } diff --git a/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.h b/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.h index 5e4a48462d7..6b1011033a0 100644 --- a/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.h +++ b/eval/src/vespa/eval/tensor/dense/mutable_dense_tensor_view.h @@ -2,25 +2,28 @@ #pragma once -#include "dense_tensor_view.h" +#include <vespa/eval/eval/value.h> #include <cassert> -namespace vespalib::tensor { +namespace vespalib::eval { /** - * A mutable view to a dense tensor where all dimensions are indexed. + * A dense tensor with a cells reference that can be modified. */ -class MutableDenseTensorView : public DenseTensorView -{ +class MutableDenseTensorView : public Value { private: - eval::ValueType _type; - + const ValueType _type; + TypedCells _cells; public: - MutableDenseTensorView(eval::ValueType type_in); - MutableDenseTensorView(MutableDenseTensorView &&) = default; + MutableDenseTensorView(const ValueType &type_in); void setCells(TypedCells cells_in) { - initCellsRef(cells_in); + assert(cells_in.type == _type.cell_type()); + _cells = cells_in; } + const ValueType &type() const final override { return _type; } + TypedCells cells() const final override { return _cells; } + const Index &index() const final override { return TrivialIndex::get(); } + MemoryUsage get_memory_usage() const final override { return self_memory_usage<MutableDenseTensorView>(); } }; } diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreattribute.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreattribute.cpp index 7fab995dfb9..fa8097419a5 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreattribute.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreattribute.cpp @@ -17,15 +17,6 @@ DocumentMetaStoreAttribute::getFixedName() return _G_documentMetaStoreName; } - -void -DocumentMetaStoreAttribute::notImplemented() const -{ - throw vespalib::IllegalStateException( - "The function is not implemented for DocumentMetaStoreAttribute"); -} - - DocumentMetaStoreAttribute::DocumentMetaStoreAttribute(const vespalib::string &name) : NotImplementedAttribute(name, Config(BasicType::NONE)) { } diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreattribute.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreattribute.h index 721aa8fe126..f4e936e663a 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreattribute.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreattribute.h @@ -13,9 +13,6 @@ namespace proton { **/ class DocumentMetaStoreAttribute : public search::NotImplementedAttribute { -protected: - void notImplemented() const override __attribute__((noinline)); - public: DocumentMetaStoreAttribute(const vespalib::string &name=getFixedName()); ~DocumentMetaStoreAttribute() override; diff --git a/searchlib/src/tests/tensor/dense_tensor_store/dense_tensor_store_test.cpp b/searchlib/src/tests/tensor/dense_tensor_store/dense_tensor_store_test.cpp index a3b59909ac8..3385ac5a6bc 100644 --- a/searchlib/src/tests/tensor/dense_tensor_store/dense_tensor_store_test.cpp +++ b/searchlib/src/tests/tensor/dense_tensor_store/dense_tensor_store_test.cpp @@ -15,7 +15,6 @@ using vespalib::eval::SimpleValue; using vespalib::eval::TensorSpec; using vespalib::eval::Value; using vespalib::eval::ValueType; -using vespalib::tensor::MutableDenseTensorView; using EntryRef = DenseTensorStore::EntryRef; @@ -46,8 +45,8 @@ struct Fixture assertTensorView(ref, *expTensor); } void assertTensorView(EntryRef ref, const Value &expTensor) { - MutableDenseTensorView actTensor(store.type()); - store.getTensor(ref, actTensor); + auto cells = store.get_typed_cells(ref); + vespalib::eval::DenseValueView actTensor(store.type(), cells); EXPECT_EQUAL(expTensor, actTensor); } }; diff --git a/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.h b/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.h index a5b570a4864..f311907bd91 100644 --- a/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.h +++ b/searchlib/src/vespa/searchlib/attribute/not_implemented_attribute.h @@ -9,7 +9,7 @@ namespace search { struct NotImplementedAttribute : AttributeVector { using AttributeVector::AttributeVector; - [[noreturn]] virtual void notImplemented() const ; + void notImplemented [[noreturn]] () const; uint32_t getValueCount(DocId) const override; largeint_t getInt(DocId) const override; diff --git a/searchlib/src/vespa/searchlib/features/attributefeature.cpp b/searchlib/src/vespa/searchlib/features/attributefeature.cpp index eac69f87587..80d9a305ef4 100644 --- a/searchlib/src/vespa/searchlib/features/attributefeature.cpp +++ b/searchlib/src/vespa/searchlib/features/attributefeature.cpp @@ -469,7 +469,7 @@ createTensorAttributeExecutor(const IAttributeVector *attribute, const vespalib: tensorType.to_spec().c_str()); return ConstantTensorExecutor::createEmpty(tensorType, stash); } - if (tensorAttribute->supports_extract_dense_view()) { + if (tensorAttribute->supports_extract_cells_ref()) { return stash.create<DenseTensorAttributeExecutor>(*tensorAttribute); } if (tensorAttribute->supports_get_tensor_ref()) { diff --git a/searchlib/src/vespa/searchlib/features/dense_tensor_attribute_executor.cpp b/searchlib/src/vespa/searchlib/features/dense_tensor_attribute_executor.cpp index 8f7d82adadd..0de375b7acb 100644 --- a/searchlib/src/vespa/searchlib/features/dense_tensor_attribute_executor.cpp +++ b/searchlib/src/vespa/searchlib/features/dense_tensor_attribute_executor.cpp @@ -4,7 +4,6 @@ #include <vespa/searchlib/tensor/i_tensor_attribute.h> using search::tensor::ITensorAttribute; -using vespalib::tensor::MutableDenseTensorView; namespace search::features { @@ -18,7 +17,7 @@ DenseTensorAttributeExecutor(const ITensorAttribute& attribute) void DenseTensorAttributeExecutor::execute(uint32_t docId) { - _attribute.extract_dense_view(docId, _tensorView); + _tensorView.setCells(_attribute.extract_cells_ref(docId)); outputs().set_object(0, _tensorView); } diff --git a/searchlib/src/vespa/searchlib/features/dense_tensor_attribute_executor.h b/searchlib/src/vespa/searchlib/features/dense_tensor_attribute_executor.h index a8a84447c88..d6e92a89619 100644 --- a/searchlib/src/vespa/searchlib/features/dense_tensor_attribute_executor.h +++ b/searchlib/src/vespa/searchlib/features/dense_tensor_attribute_executor.h @@ -17,7 +17,7 @@ class DenseTensorAttributeExecutor : public fef::FeatureExecutor { private: const search::tensor::ITensorAttribute& _attribute; - vespalib::tensor::MutableDenseTensorView _tensorView; + vespalib::eval::MutableDenseTensorView _tensorView; public: DenseTensorAttributeExecutor(const search::tensor::ITensorAttribute& attribute); diff --git a/searchlib/src/vespa/searchlib/features/onnx_feature.cpp b/searchlib/src/vespa/searchlib/features/onnx_feature.cpp index f05ee60076f..d207e34e991 100644 --- a/searchlib/src/vespa/searchlib/features/onnx_feature.cpp +++ b/searchlib/src/vespa/searchlib/features/onnx_feature.cpp @@ -21,7 +21,6 @@ using search::fef::ParameterList; using vespalib::Stash; using vespalib::eval::ValueType; using vespalib::make_string_short::fmt; -using vespalib::tensor::MutableDenseTensorView; using vespalib::tensor::Onnx; namespace search::features { diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp index 85b7e8f89e8..52814bb2631 100644 --- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.cpp @@ -5,7 +5,6 @@ using search::tensor::DenseTensorAttribute; using vespalib::ConstArrayRef; -using vespalib::tensor::MutableDenseTensorView; using vespalib::eval::TypedCells; using vespalib::eval::CellType; @@ -36,10 +35,10 @@ public: NearestNeighborImpl(Params params_in) : NearestNeighborIterator(params_in), _lhs(params().queryTensor.cells()), - _fieldTensor(params().tensorAttribute.getTensorType()), _lastScore(0.0) { - assert(is_compatible(_fieldTensor.fast_type(), params().queryTensor.type())); + assert(is_compatible(params().tensorAttribute.getTensorType(), + params().queryTensor.type())); } ~NearestNeighborImpl(); @@ -74,13 +73,11 @@ public: private: double computeDistance(uint32_t docId, double limit) { - params().tensorAttribute.extract_dense_view(docId, _fieldTensor); - auto rhs = _fieldTensor.cells(); + auto rhs = params().tensorAttribute.extract_cells_ref(docId); return params().distanceFunction->calc_with_limit(_lhs, rhs, limit); } TypedCells _lhs; - MutableDenseTensorView _fieldTensor; double _lastScore; }; diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp index 8b27dcc1cd4..434df7549f3 100644 --- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp @@ -19,7 +19,6 @@ using search::attribute::LoadUtils; using vespalib::eval::Value; using vespalib::eval::ValueType; using vespalib::slime::ObjectInserter; -using vespalib::tensor::MutableDenseTensorView; namespace search::tensor { @@ -173,14 +172,14 @@ DenseTensorAttribute::getTensor(DocId docId) const return _denseTensorStore.getTensor(ref); } -void -DenseTensorAttribute::extract_dense_view(DocId docId, MutableDenseTensorView &tensor) const +vespalib::eval::TypedCells +DenseTensorAttribute::extract_cells_ref(DocId docId) const { EntryRef ref; if (docId < getCommittedDocIdLimit()) { ref = _refVector[docId]; } - _denseTensorStore.getTensor(ref, tensor); + return _denseTensorStore.get_typed_cells(ref); } bool diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.h index e06bbf331ac..55e7b8cb464 100644 --- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.h +++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.h @@ -8,8 +8,6 @@ #include "tensor_attribute.h" #include <memory> -namespace vespalib::tensor { class MutableDenseTensorView; } - namespace search::tensor { class NearestNeighborIndex; @@ -37,8 +35,8 @@ public: std::unique_ptr<PrepareResult> prepare_set_tensor(DocId docid, const vespalib::eval::Value& tensor) const override; void complete_set_tensor(DocId docid, const vespalib::eval::Value& tensor, std::unique_ptr<PrepareResult> prepare_result) override; std::unique_ptr<vespalib::eval::Value> getTensor(DocId docId) const override; - void extract_dense_view(DocId docId, vespalib::tensor::MutableDenseTensorView &tensor) const override; - bool supports_extract_dense_view() const override { return true; } + vespalib::eval::TypedCells extract_cells_ref(DocId docId) const override; + bool supports_extract_cells_ref() const override { return true; } bool onLoad() override; std::unique_ptr<AttributeSaver> onInitSave(vespalib::stringref fileName) override; void compactWorst() override; diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp index ddbb956838b..aa81f3836a6 100644 --- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp +++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.cpp @@ -6,7 +6,6 @@ #include <vespa/vespalib/datastore/datastore.hpp> using vespalib::datastore::Handle; -using vespalib::tensor::MutableDenseTensorView; using vespalib::eval::Value; using vespalib::eval::ValueType; using CellType = vespalib::eval::CellType; @@ -137,18 +136,6 @@ DenseTensorStore::getTensor(EntryRef ref) const return std::make_unique<vespalib::tensor::DenseTensorView>(_type, cells_ref); } -void -DenseTensorStore::getTensor(EntryRef ref, MutableDenseTensorView &tensor) const -{ - if (!ref.valid()) { - vespalib::eval::TypedCells cells_ref(&_emptySpace[0], _type.cell_type(), getNumCells()); - tensor.setCells(cells_ref); - } else { - vespalib::eval::TypedCells cells_ref(getRawBuffer(ref), _type.cell_type(), getNumCells()); - tensor.setCells(cells_ref); - } -} - vespalib::eval::TypedCells DenseTensorStore::get_typed_cells(EntryRef ref) const { diff --git a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h index 696a325f813..49e8a585fec 100644 --- a/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h +++ b/searchlib/src/vespa/searchlib/tensor/dense_tensor_store.h @@ -6,7 +6,6 @@ #include <vespa/eval/eval/value_type.h> #include <vespa/eval/eval/typed_cells.h> -namespace vespalib { namespace tensor { class MutableDenseTensorView; }} namespace vespalib::eval { struct Value; } namespace search::tensor { @@ -66,7 +65,6 @@ public: void holdTensor(EntryRef ref) override; EntryRef move(EntryRef ref) override; std::unique_ptr<vespalib::eval::Value> getTensor(EntryRef ref) const; - void getTensor(EntryRef ref, vespalib::tensor::MutableDenseTensorView &tensor) const; vespalib::eval::TypedCells get_typed_cells(EntryRef ref) const; EntryRef setTensor(const vespalib::eval::Value &tensor); // The following method is meant to be used only for unit tests. diff --git a/searchlib/src/vespa/searchlib/tensor/i_tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/i_tensor_attribute.h index c962e919d95..360250c869e 100644 --- a/searchlib/src/vespa/searchlib/tensor/i_tensor_attribute.h +++ b/searchlib/src/vespa/searchlib/tensor/i_tensor_attribute.h @@ -3,10 +3,8 @@ #pragma once #include <memory> +#include <vespa/eval/eval/typed_cells.h> -namespace vespalib::tensor { -class MutableDenseTensorView; -} namespace vespalib::eval { class ValueType; struct Value; } namespace vespalib::slime { struct Inserter; } @@ -21,9 +19,9 @@ public: virtual ~ITensorAttribute() {} virtual std::unique_ptr<vespalib::eval::Value> getTensor(uint32_t docId) const = 0; virtual std::unique_ptr<vespalib::eval::Value> getEmptyTensor() const = 0; - virtual void extract_dense_view(uint32_t docid, vespalib::tensor::MutableDenseTensorView& tensor) const = 0; + virtual vespalib::eval::TypedCells extract_cells_ref(uint32_t docid) const = 0; virtual const vespalib::eval::Value& get_tensor_ref(uint32_t docid) const = 0; - virtual bool supports_extract_dense_view() const = 0; + virtual bool supports_extract_cells_ref() const = 0; virtual bool supports_get_tensor_ref() const = 0; virtual const vespalib::eval::ValueType & getTensorType() const = 0; diff --git a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.cpp b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.cpp index 6a0dbfb9f48..79c8e5a663e 100644 --- a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.cpp +++ b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.cpp @@ -48,10 +48,10 @@ ImportedTensorAttributeVectorReadGuard::getEmptyTensor() const return _target_tensor_attribute.getEmptyTensor(); } -void -ImportedTensorAttributeVectorReadGuard::extract_dense_view(uint32_t docid, vespalib::tensor::MutableDenseTensorView& tensor) const +vespalib::eval::TypedCells +ImportedTensorAttributeVectorReadGuard::extract_cells_ref(uint32_t docid) const { - _target_tensor_attribute.extract_dense_view(getTargetLid(docid), tensor); + return _target_tensor_attribute.extract_cells_ref(getTargetLid(docid)); } const vespalib::eval::Value& diff --git a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h index a3ffc27b153..c55a922487f 100644 --- a/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h +++ b/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h @@ -32,9 +32,9 @@ public: std::unique_ptr<vespalib::eval::Value> getTensor(uint32_t docId) const override; std::unique_ptr<vespalib::eval::Value> getEmptyTensor() const override; - void extract_dense_view(uint32_t docid, vespalib::tensor::MutableDenseTensorView& tensor) const override; + vespalib::eval::TypedCells extract_cells_ref(uint32_t docid) const override; const vespalib::eval::Value& get_tensor_ref(uint32_t docid) const override; - bool supports_extract_dense_view() const override { return _target_tensor_attribute.supports_extract_dense_view(); } + bool supports_extract_cells_ref() const override { return _target_tensor_attribute.supports_extract_cells_ref(); } bool supports_get_tensor_ref() const override { return _target_tensor_attribute.supports_get_tensor_ref(); } const vespalib::eval::ValueType &getTensorType() const override; void get_state(const vespalib::slime::Inserter& inserter) const override; diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp index 0748329694c..96049375180 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp @@ -186,20 +186,16 @@ TensorAttribute::getEmptyTensor() const return EngineOrFactory::get().copy(*_emptyTensor); } -void -TensorAttribute::extract_dense_view(uint32_t docid, vespalib::tensor::MutableDenseTensorView& tensor) const +vespalib::eval::TypedCells +TensorAttribute::extract_cells_ref(uint32_t /*docid*/) const { - (void) docid; - (void) tensor; notImplemented(); } const vespalib::eval::Value& -TensorAttribute::get_tensor_ref(uint32_t docid) const +TensorAttribute::get_tensor_ref(uint32_t /*docid*/) const { - (void) docid; notImplemented(); - abort(); // Needed to avoid compile error } const vespalib::eval::ValueType & diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h index b88ffcf0f2c..7abfe66a2e4 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h @@ -47,9 +47,9 @@ public: void onGenerationChange(generation_t generation) override; bool addDoc(DocId &docId) override; std::unique_ptr<vespalib::eval::Value> getEmptyTensor() const override; - void extract_dense_view(uint32_t docid, vespalib::tensor::MutableDenseTensorView& tensor) const override; + vespalib::eval::TypedCells extract_cells_ref(uint32_t docid) const override; const vespalib::eval::Value& get_tensor_ref(uint32_t docid) const override; - bool supports_extract_dense_view() const override { return false; } + bool supports_extract_cells_ref() const override { return false; } bool supports_get_tensor_ref() const override { return false; } const vespalib::eval::ValueType & getTensorType() const override; void get_state(const vespalib::slime::Inserter& inserter) const override; |