From 7dc4ed00c0a23248e2c5e48333786b0c2341d0fa Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Fri, 30 Sep 2022 12:01:36 +0200 Subject: Extend class comment with short description of memory layout for stored tensor. --- .../src/vespa/searchlib/tensor/tensor_buffer_operations.cpp | 10 +++++----- .../src/vespa/searchlib/tensor/tensor_buffer_operations.h | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.cpp index ba8b550a779..807975c392a 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.cpp @@ -35,23 +35,23 @@ adjust_min_alignment(size_t min_alignment) return std::max(std::max(sizeof(uint32_t), sizeof(string_id)), min_alignment); } -struct MyFastValueView final : Value { +struct FastValueView final : Value { const ValueType& _type; StringIdVector _labels; FastValueIndex _index; TypedCells _cells; - MyFastValueView(const ValueType& type, ConstArrayRef labels, TypedCells cells, size_t num_mapped_dimensions, size_t num_subspaces); + FastValueView(const ValueType& type, ConstArrayRef labels, TypedCells cells, size_t num_mapped_dimensions, size_t num_subspaces); const ValueType& type() const override { return _type; } const Value::Index& index() const override { return _index; } TypedCells cells() const override { return _cells; } MemoryUsage get_memory_usage() const override { - MemoryUsage usage = self_memory_usage(); + MemoryUsage usage = self_memory_usage(); usage.merge(_index.map.estimate_extra_memory_usage()); return usage; } }; -MyFastValueView::MyFastValueView(const ValueType& type, ConstArrayRef labels, TypedCells cells, size_t num_mapped_dimensions, size_t num_subspaces) +FastValueView::FastValueView(const ValueType& type, ConstArrayRef labels, TypedCells cells, size_t num_mapped_dimensions, size_t num_subspaces) : Value(), _type(type), _labels(labels.begin(), labels.end()), @@ -144,7 +144,7 @@ TensorBufferOperations::make_fast_view(ConstArrayRef buf, const vespalib:: auto cells_start_offset = get_cells_offset(num_subspaces, alignment); TypedCells cells(buf.data() + cells_start_offset, _cell_type, cells_size); assert(cells_start_offset + cells_mem_size <= buf.size()); - return std::make_unique(tensor_type, labels, cells, _num_mapped_dimensions, num_subspaces); + return std::make_unique(tensor_type, labels, cells, _num_mapped_dimensions, num_subspaces); } void diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.h b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.h index 72b00e79426..ab3777d7526 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.h +++ b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.h @@ -23,6 +23,17 @@ namespace search::tensor { /* * Class used to store a tensor in a buffer and make tensor views based on * buffer content. + * + * Layout of buffer is: + * + * num_subspaces - number of subspaces + * labels[num_subspaces * _num_mapped_dimensions] - array of labels for sparse dimensions + * padding - to align start of cells + * cells[num_subspaces * _dense_subspaces_size] - array of tensor cell values + * padding - to align start of next buffer + * + * Alignment is dynamic, based on cell type, memory used by tensor cell values and + * alignment required for reading num_subspaces and labels array. */ class TensorBufferOperations { -- cgit v1.2.3