diff options
author | Geir Storli <geirst@verizonmedia.com> | 2021-03-26 14:59:54 +0000 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2021-03-26 14:59:54 +0000 |
commit | 47dae5a7ccb78282e9db7e6b305562a9e0c195f4 (patch) | |
tree | 98aa99c3af20e13ec2984b098825a8718fba8e68 /searchlib | |
parent | cfc7927446dcea526fbdce38b8578c14671e1d6c (diff) |
Remove SerializedTensorAttribute that is replaced by SerializedFastValueAttribute.
Diffstat (limited to 'searchlib')
8 files changed, 4 insertions, 365 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/createsinglestd.cpp b/searchlib/src/vespa/searchlib/attribute/createsinglestd.cpp index bfd03200c0c..291215b886a 100644 --- a/searchlib/src/vespa/searchlib/attribute/createsinglestd.cpp +++ b/searchlib/src/vespa/searchlib/attribute/createsinglestd.cpp @@ -9,7 +9,6 @@ #include "singlenumericattribute.hpp" #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> namespace search { diff --git a/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt b/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt index 79b18a57a34..8af77a57a44 100644 --- a/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt @@ -6,8 +6,8 @@ vespa_add_library(searchlib_tensor OBJECT dense_tensor_attribute_saver.cpp dense_tensor_store.cpp direct_tensor_attribute.cpp - direct_tensor_store.cpp direct_tensor_saver.cpp + direct_tensor_store.cpp distance_function_factory.cpp distance_functions.cpp hnsw_graph.cpp @@ -19,14 +19,11 @@ vespa_add_library(searchlib_tensor OBJECT inv_log_level_generator.cpp nearest_neighbor_index.cpp nearest_neighbor_index_saver.cpp - serialized_tensor_attribute.cpp - serialized_tensor_attribute_saver.cpp - serialized_tensor_store.cpp - tensor_attribute.cpp - tensor_deserialize.cpp - tensor_store.cpp serialized_fast_value_attribute.cpp streamed_value_saver.cpp streamed_value_store.cpp + tensor_attribute.cpp + tensor_deserialize.cpp + tensor_store.cpp DEPENDS ) diff --git a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute.cpp deleted file mode 100644 index de6feb80958..00000000000 --- a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "blob_sequence_reader.h" -#include "serialized_tensor_attribute.h" -#include "serialized_tensor_attribute_saver.h" -#include "tensor_attribute.hpp" -#include <vespa/eval/eval/value.h> -#include <vespa/fastlib/io/bufferedfile.h> -#include <vespa/searchlib/attribute/readerbase.h> -#include <vespa/searchlib/util/fileutil.h> -#include <vespa/vespalib/util/rcuvector.hpp> - -using vespalib::eval::Value; -using vespalib::eval::ValueType; - -namespace search::tensor { - -namespace { - -constexpr uint32_t TENSOR_ATTRIBUTE_VERSION = 0; - -} - -SerializedTensorAttribute::SerializedTensorAttribute(stringref name, const Config &cfg) - : TensorAttribute(name, cfg, _serializedTensorStore) -{ -} - - -SerializedTensorAttribute::~SerializedTensorAttribute() -{ - getGenerationHolder().clearHoldLists(); - _tensorStore.clearHoldLists(); -} - -void -SerializedTensorAttribute::setTensor(DocId docId, const vespalib::eval::Value &tensor) -{ - checkTensorType(tensor); - EntryRef ref = _serializedTensorStore.setTensor(tensor); - setTensorRef(docId, ref); -} - - -std::unique_ptr<Value> -SerializedTensorAttribute::getTensor(DocId docId) const -{ - EntryRef ref; - if (docId < getCommittedDocIdLimit()) { - ref = _refVector[docId]; - } - if (!ref.valid()) { - return {}; - } - return _serializedTensorStore.getTensor(ref); -} - -bool -SerializedTensorAttribute::onLoad() -{ - BlobSequenceReader tensorReader(*this); - if (!tensorReader.hasData()) { - return false; - } - setCreateSerialNum(tensorReader.getCreateSerialNum()); - assert(tensorReader.getVersion() == TENSOR_ATTRIBUTE_VERSION); - uint32_t numDocs(tensorReader.getDocIdLimit()); - _refVector.reset(); - _refVector.unsafe_reserve(numDocs); - for (uint32_t lid = 0; lid < numDocs; ++lid) { - uint32_t tensorSize = tensorReader.getNextSize(); - auto raw = _serializedTensorStore.allocRawBuffer(tensorSize); - if (tensorSize != 0) { - tensorReader.readBlob(raw.data, tensorSize); - } - _refVector.push_back(raw.ref); - } - setNumDocs(numDocs); - setCommittedDocIdLimit(numDocs); - return true; -} - - -std::unique_ptr<AttributeSaver> -SerializedTensorAttribute::onInitSave(vespalib::stringref fileName) -{ - vespalib::GenerationHandler::Guard guard(getGenerationHandler(). - takeGuard()); - return std::make_unique<SerializedTensorAttributeSaver> - (std::move(guard), - this->createAttributeHeader(fileName), - getRefCopy(), - _serializedTensorStore); -} - -void -SerializedTensorAttribute::compactWorst() -{ - doCompactWorst<SerializedTensorStore::RefType>(); -} - -} diff --git a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute.h deleted file mode 100644 index fea11e3b0c4..00000000000 --- a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute.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 "serialized_tensor_store.h" -#include "tensor_attribute.h" - -namespace search::tensor { - -/** - * Attribute vector class used to store tensors for all documents in memory. - */ -class SerializedTensorAttribute : public TensorAttribute { - SerializedTensorStore _serializedTensorStore; // data store for serialized tensors -public: - SerializedTensorAttribute(vespalib::stringref baseFileName, const Config &cfg); - virtual ~SerializedTensorAttribute(); - virtual void setTensor(DocId docId, const vespalib::eval::Value &tensor) override; - virtual std::unique_ptr<vespalib::eval::Value> getTensor(DocId docId) const override; - virtual bool onLoad() override; - virtual std::unique_ptr<AttributeSaver> onInitSave(vespalib::stringref fileName) override; - virtual void compactWorst() override; -}; - -} diff --git a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute_saver.cpp b/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute_saver.cpp deleted file mode 100644 index 4c41c3a449e..00000000000 --- a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute_saver.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "serialized_tensor_attribute_saver.h" -#include "serialized_tensor_store.h" -#include <vespa/searchlib/util/bufferwriter.h> -#include <vespa/searchlib/attribute/iattributesavetarget.h> - -using vespalib::GenerationHandler; - -namespace search::tensor { - -SerializedTensorAttributeSaver:: -SerializedTensorAttributeSaver(GenerationHandler::Guard &&guard, - const attribute::AttributeHeader &header, - RefCopyVector &&refs, - const SerializedTensorStore &tensorStore) - : AttributeSaver(std::move(guard), header), - _refs(std::move(refs)), - _tensorStore(tensorStore) -{ -} - - -SerializedTensorAttributeSaver::~SerializedTensorAttributeSaver() -{ -} - - -bool -SerializedTensorAttributeSaver::onSave(IAttributeSaveTarget &saveTarget) -{ - std::unique_ptr<BufferWriter> - datWriter(saveTarget.datWriter().allocBufferWriter()); - const uint32_t docIdLimit(_refs.size()); - for (uint32_t lid = 0; lid < docIdLimit; ++lid) { - auto raw = _tensorStore.getRawBuffer(_refs[lid]); - datWriter->write(&raw.second, sizeof(raw.second)); - if (raw.second != 0) { - datWriter->write(raw.first, raw.second); - } - } - datWriter->flush(); - return true; -} - -} diff --git a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute_saver.h b/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute_saver.h deleted file mode 100644 index 1ae2279b893..00000000000 --- a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_attribute_saver.h +++ /dev/null @@ -1,33 +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/searchlib/attribute/attributesaver.h> -#include "tensor_attribute.h" - -namespace search::tensor { - -class SerializedTensorStore; - -/* - * Class for saving a tensor attribute. - */ -class SerializedTensorAttributeSaver : public AttributeSaver { -public: - using RefCopyVector = TensorAttribute::RefCopyVector; -private: - RefCopyVector _refs; - const SerializedTensorStore &_tensorStore; - using GenerationHandler = vespalib::GenerationHandler; - - virtual bool onSave(IAttributeSaveTarget &saveTarget) override; -public: - SerializedTensorAttributeSaver(GenerationHandler::Guard &&guard, - const attribute::AttributeHeader &header, - RefCopyVector &&refs, - const SerializedTensorStore &tensorStore); - - virtual ~SerializedTensorAttributeSaver(); -}; - -} diff --git a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_store.cpp b/searchlib/src/vespa/searchlib/tensor/serialized_tensor_store.cpp deleted file mode 100644 index f55b51875b2..00000000000 --- a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_store.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "serialized_tensor_store.h" -#include "tensor_deserialize.h" -#include <vespa/eval/eval/value.h> -#include <vespa/eval/eval/value_codec.h> -#include <vespa/vespalib/datastore/datastore.hpp> -#include <vespa/vespalib/objects/nbostream.h> -#include <vespa/vespalib/util/stringfmt.h> - -using vespalib::datastore::Handle; -using vespalib::eval::Value; - -namespace search::tensor { - -constexpr size_t MIN_BUFFER_ARRAYS = 1024; - -SerializedTensorStore::SerializedTensorStore() - : TensorStore(_concreteStore), - _concreteStore(), - _bufferType(RefType::align(1), - MIN_BUFFER_ARRAYS, - RefType::offsetSize() / RefType::align(1)) -{ - _store.addType(&_bufferType); - _store.init_primary_buffers(); -} - -SerializedTensorStore::~SerializedTensorStore() -{ - _store.dropBuffers(); -} - -std::pair<const void *, uint32_t> -SerializedTensorStore::getRawBuffer(RefType ref) const -{ - if (!ref.valid()) { - return std::make_pair(nullptr, 0u); - } - const char *buf = _store.getEntry<char>(ref); - uint32_t len = *reinterpret_cast<const uint32_t *>(buf); - return std::make_pair(buf + sizeof(uint32_t), len); -} - -Handle<char> -SerializedTensorStore::allocRawBuffer(uint32_t size) -{ - if (size == 0) { - return Handle<char>(); - } - size_t extSize = size + sizeof(uint32_t); - size_t bufSize = RefType::align(extSize); - auto result = _concreteStore.rawAllocator<char>(_typeId).alloc(bufSize); - *reinterpret_cast<uint32_t *>(result.data) = size; - char *padWritePtr = result.data + extSize; - for (size_t i = extSize; i < bufSize; ++i) { - *padWritePtr++ = 0; - } - // Hide length of buffer (first 4 bytes) from users of the buffer. - return Handle<char>(result.ref, result.data + sizeof(uint32_t)); -} - -void -SerializedTensorStore::holdTensor(EntryRef ref) -{ - if (!ref.valid()) { - return; - } - RefType iRef(ref); - const char *buf = _store.getEntry<char>(iRef); - uint32_t len = *reinterpret_cast<const uint32_t *>(buf); - _concreteStore.holdElem(ref, len + sizeof(uint32_t)); -} - -TensorStore::EntryRef -SerializedTensorStore::move(EntryRef ref) -{ - if (!ref.valid()) { - return RefType(); - } - auto oldraw = getRawBuffer(ref); - auto newraw = allocRawBuffer(oldraw.second); - memcpy(newraw.data, oldraw.first, oldraw.second); - _concreteStore.holdElem(ref, oldraw.second + sizeof(uint32_t)); - return newraw.ref; -} - -std::unique_ptr<Value> -SerializedTensorStore::getTensor(EntryRef ref) const -{ - auto raw = getRawBuffer(ref); - if (raw.second == 0u) { - return {}; - } - return deserialize_tensor(raw.first, raw.second); -} - -TensorStore::EntryRef -SerializedTensorStore::setTensor(const vespalib::eval::Value &tensor) -{ - vespalib::nbostream stream; - encode_value(tensor, stream); - auto raw = allocRawBuffer(stream.size()); - memcpy(raw.data, stream.peek(), stream.size()); - return raw.ref; -} - -} diff --git a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_store.h b/searchlib/src/vespa/searchlib/tensor/serialized_tensor_store.h deleted file mode 100644 index 0f1b0129ecb..00000000000 --- a/searchlib/src/vespa/searchlib/tensor/serialized_tensor_store.h +++ /dev/null @@ -1,43 +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 "tensor_store.h" - -namespace vespalib::eval { struct Value; } - -namespace search::tensor { - -/** - * Class for storing serialized tensors in memory, used by TensorAttribute. - * - * Serialization format is subject to change. Changes to serialization format - * might also require corresponding changes to implemented optimized tensor - * operations that use the serialized tensor as argument. - */ -class SerializedTensorStore : public TensorStore { -public: - using RefType = vespalib::datastore::AlignedEntryRefT<22, 2>; - using DataStoreType = vespalib::datastore::DataStoreT<RefType>; -private: - DataStoreType _concreteStore; - vespalib::datastore::BufferType<char> _bufferType; -public: - SerializedTensorStore(); - - virtual ~SerializedTensorStore(); - - std::pair<const void *, uint32_t> getRawBuffer(RefType ref) const; - - vespalib::datastore::Handle<char> allocRawBuffer(uint32_t size); - - virtual void holdTensor(EntryRef ref) override; - - virtual EntryRef move(EntryRef ref) override; - - std::unique_ptr<vespalib::eval::Value> getTensor(EntryRef ref) const; - - EntryRef setTensor(const vespalib::eval::Value &tensor); -}; - -} |