summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-02-23 11:33:31 +0100
committerTor Egge <Tor.Egge@online.no>2023-02-23 11:33:31 +0100
commit7734ba98906e0c956d2e3f09bd358886d79a5f14 (patch)
treebb9cbf847362688809a50165e110cbc82b93636e
parentf66f816102ce0a7c3aaba72d1db61a83157259ed (diff)
Move FastValueView to separate files.
-rw-r--r--eval/src/vespa/eval/eval/fast_value.hpp12
-rw-r--r--eval/src/vespa/eval/eval/fast_value_index.h24
-rw-r--r--searchlib/src/vespa/searchlib/tensor/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/tensor/fast_value_view.cpp39
-rw-r--r--searchlib/src/vespa/searchlib/tensor/fast_value_view.h24
-rw-r--r--searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.cpp33
6 files changed, 90 insertions, 43 deletions
diff --git a/eval/src/vespa/eval/eval/fast_value.hpp b/eval/src/vespa/eval/eval/fast_value.hpp
index 2eaefa3670c..47f99d19055 100644
--- a/eval/src/vespa/eval/eval/fast_value.hpp
+++ b/eval/src/vespa/eval/eval/fast_value.hpp
@@ -1,7 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "value_builder_factory.h"
-#include "fast_addr_map.h"
+#include "fast_value_index.h"
#include "inline_operation.h"
#include <vespa/eval/instruction/generic_join.h>
#include <vespa/vespalib/stllike/hashtable.hpp>
@@ -12,16 +12,6 @@ namespace vespalib::eval {
//-----------------------------------------------------------------------------
-// This is the class instructions will look for when optimizing sparse
-// operations by calling inline functions directly.
-struct FastValueIndex final : Value::Index {
- FastAddrMap map;
- FastValueIndex(size_t num_mapped_dims_in, const StringIdVector &labels, size_t expected_subspaces_in)
- : map(num_mapped_dims_in, labels, expected_subspaces_in) {}
- size_t size() const override { return map.size(); }
- std::unique_ptr<View> create_view(ConstArrayRef<size_t> dims) const override;
-};
-
inline bool is_fast(const Value::Index &index) {
return (std::type_index(typeid(index)) == std::type_index(typeid(FastValueIndex)));
}
diff --git a/eval/src/vespa/eval/eval/fast_value_index.h b/eval/src/vespa/eval/eval/fast_value_index.h
new file mode 100644
index 00000000000..edf96490db6
--- /dev/null
+++ b/eval/src/vespa/eval/eval/fast_value_index.h
@@ -0,0 +1,24 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "value.h"
+#include "fast_addr_map.h"
+
+namespace vespalib::eval {
+
+/*
+ * Tensor value index, used to map labels to dense subspace indexes.
+ *
+ * This is the class instructions will look for when optimizing sparse
+ * operations by calling inline functions directly.
+ */
+struct FastValueIndex final : Value::Index {
+ FastAddrMap map;
+ FastValueIndex(size_t num_mapped_dims_in, const StringIdVector &labels, size_t expected_subspaces_in)
+ : map(num_mapped_dims_in, labels, expected_subspaces_in) {}
+ size_t size() const override { return map.size(); }
+ std::unique_ptr<View> create_view(ConstArrayRef<size_t> dims) const override;
+};
+
+}
diff --git a/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt b/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt
index 9f96bce90c9..a64bd6af4a9 100644
--- a/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/tensor/CMakeLists.txt
@@ -13,6 +13,7 @@ vespa_add_library(searchlib_tensor OBJECT
distance_function_factory.cpp
empty_subspace.cpp
euclidean_distance.cpp
+ fast_value_view.cpp
geo_degrees_distance.cpp
hamming_distance.cpp
hash_set_visited_tracker.cpp
diff --git a/searchlib/src/vespa/searchlib/tensor/fast_value_view.cpp b/searchlib/src/vespa/searchlib/tensor/fast_value_view.cpp
new file mode 100644
index 00000000000..29cc47cb543
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/tensor/fast_value_view.cpp
@@ -0,0 +1,39 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "fast_value_view.h"
+#include <vespa/vespalib/stllike/hash_map.hpp>
+
+using vespalib::ConstArrayRef;
+using vespalib::MemoryUsage;
+using vespalib::string_id;
+using vespalib::eval::FastAddrMap;
+using vespalib::eval::TypedCells;
+using vespalib::eval::Value;
+using vespalib::eval::ValueType;
+using vespalib::eval::self_memory_usage;
+
+namespace search::tensor {
+
+FastValueView::FastValueView(const ValueType& type, ConstArrayRef<string_id> labels, TypedCells cells, size_t num_mapped_dimensions, size_t num_subspaces)
+ : Value(),
+ _type(type),
+ _labels(labels.begin(), labels.end()),
+ _index(num_mapped_dimensions, _labels, num_subspaces),
+ _cells(cells)
+{
+ for (size_t i = 0; i < num_subspaces; ++i) {
+ ConstArrayRef<string_id> addr(_labels.data() + (i * num_mapped_dimensions), num_mapped_dimensions);
+ _index.map.add_mapping(FastAddrMap::hash_labels(addr));
+ }
+ assert(_index.map.size() == num_subspaces);
+}
+
+MemoryUsage
+FastValueView::get_memory_usage() const
+{
+ MemoryUsage usage = self_memory_usage<FastValueView>();
+ usage.merge(_index.map.estimate_extra_memory_usage());
+ return usage;
+}
+
+}
diff --git a/searchlib/src/vespa/searchlib/tensor/fast_value_view.h b/searchlib/src/vespa/searchlib/tensor/fast_value_view.h
new file mode 100644
index 00000000000..c3f13ac5856
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/tensor/fast_value_view.h
@@ -0,0 +1,24 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/eval/eval/fast_value_index.h>
+
+namespace search::tensor {
+
+/*
+ * Tensor view that is not self-contained. It references external cell values.
+ */
+struct FastValueView final : vespalib::eval::Value {
+ const vespalib::eval::ValueType& _type;
+ vespalib::StringIdVector _labels;
+ vespalib::eval::FastValueIndex _index;
+ vespalib::eval::TypedCells _cells;
+ FastValueView(const vespalib::eval::ValueType& type, vespalib::ConstArrayRef<vespalib::string_id> labels, vespalib::eval::TypedCells cells, size_t num_mapped_dimensions, size_t num_subspaces);
+ const vespalib::eval::ValueType& type() const override { return _type; }
+ const vespalib::eval::Value::Index& index() const override { return _index; }
+ vespalib::eval::TypedCells cells() const override { return _cells; }
+ vespalib::MemoryUsage get_memory_usage() const override;
+};
+
+}
diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.cpp
index fcdb9311ec6..135c62b3cfa 100644
--- a/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/tensor_buffer_operations.cpp
@@ -1,8 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "tensor_buffer_operations.h"
-#include <vespa/eval/eval/fast_value.hpp>
-#include <vespa/eval/eval/value.h>
+#include "fast_value_view.h"
#include <vespa/eval/eval/value_codec.h>
#include <vespa/eval/eval/value_type.h>
#include <vespa/eval/streamed/streamed_value_view.h>
@@ -35,36 +34,6 @@ adjust_min_alignment(size_t min_alignment)
return std::max(std::max(sizeof(uint32_t), sizeof(string_id)), min_alignment);
}
-struct FastValueView final : Value {
- const ValueType& _type;
- StringIdVector _labels;
- FastValueIndex _index;
- TypedCells _cells;
- FastValueView(const ValueType& type, ConstArrayRef<string_id> 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<FastValueView>();
- usage.merge(_index.map.estimate_extra_memory_usage());
- return usage;
- }
-};
-
-FastValueView::FastValueView(const ValueType& type, ConstArrayRef<string_id> labels, TypedCells cells, size_t num_mapped_dimensions, size_t num_subspaces)
- : Value(),
- _type(type),
- _labels(labels.begin(), labels.end()),
- _index(num_mapped_dimensions, _labels, num_subspaces),
- _cells(cells)
-{
- for (size_t i = 0; i < num_subspaces; ++i) {
- ConstArrayRef<string_id> addr(_labels.data() + (i * num_mapped_dimensions), num_mapped_dimensions);
- _index.map.add_mapping(FastAddrMap::hash_labels(addr));
- }
- assert(_index.map.size() == num_subspaces);
-}
-
}
TensorBufferOperations::TensorBufferOperations(const vespalib::eval::ValueType& tensor_type)