summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2022-10-10 14:14:18 +0200
committerGitHub <noreply@github.com>2022-10-10 14:14:18 +0200
commit8be08877e45a714263e7e1a48d56a41ebc5bfb9b (patch)
tree005d02c4a0036265d35781fa3f67f7d56798acda
parent57b587d07c464a407745b4557b28b912571e7dfe (diff)
parenta66ec8fb6dd466fdc6f23017cab340ab356e12f2 (diff)
Merge pull request #24373 from vespa-engine/tegge/use-paged-setting-for-serialized-fast-value-tensor-attribute
Use paged setting for SerializedFastValueAttribute.
-rw-r--r--searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp96
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.cpp2
3 files changed, 65 insertions, 35 deletions
diff --git a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp
index 3dda2eb6d95..222a3341ef9 100644
--- a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp
+++ b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp
@@ -350,28 +350,11 @@ struct Fixture {
vespalib::ThreadStackExecutor _executor;
bool _denseTensors;
FixtureTraits _traits;
+ vespalib::string _mmap_allocator_base_dir;
- Fixture(const vespalib::string &typeSpec,
- FixtureTraits traits = FixtureTraits())
- : _dir_handler(test_dir),
- _cfg(BasicType::TENSOR, CollectionType::SINGLE),
- _name(attr_name),
- _typeSpec(typeSpec),
- _index_factory(),
- _tensorAttr(),
- _attr(),
- _executor(1, 0x10000),
- _denseTensors(false),
- _traits(traits)
- {
- if (traits.enable_hnsw_index) {
- _cfg.set_distance_metric(DistanceMetric::Euclidean);
- _cfg.set_hnsw_index_params(HnswIndexParams(4, 20, DistanceMetric::Euclidean));
- }
- setup();
- }
+ Fixture(const vespalib::string &typeSpec, FixtureTraits traits = FixtureTraits());
- ~Fixture() {}
+ ~Fixture();
void setup() {
_cfg.setTensorType(ValueType::from_spec(_typeSpec));
@@ -545,8 +528,35 @@ struct Fixture {
void testEmptyTensor();
void testOnHoldAccounting();
void test_populate_address_space_usage();
+ void test_mmap_file_allocator();
};
+Fixture::Fixture(const vespalib::string &typeSpec, FixtureTraits traits)
+ : _dir_handler(test_dir),
+ _cfg(BasicType::TENSOR, CollectionType::SINGLE),
+ _name(attr_name),
+ _typeSpec(typeSpec),
+ _index_factory(),
+ _tensorAttr(),
+ _attr(),
+ _executor(1, 0x10000),
+ _denseTensors(false),
+ _traits(traits),
+ _mmap_allocator_base_dir("mmap-file-allocator-factory-dir")
+{
+ if (traits.enable_hnsw_index) {
+ _cfg.set_distance_metric(DistanceMetric::Euclidean);
+ _cfg.set_hnsw_index_params(HnswIndexParams(4, 20, DistanceMetric::Euclidean));
+ }
+ vespalib::alloc::MmapFileAllocatorFactory::instance().setup(_mmap_allocator_base_dir);
+ setup();
+}
+
+Fixture::~Fixture()
+{
+ vespalib::alloc::MmapFileAllocatorFactory::instance().setup("");
+ std::filesystem::remove_all(std::filesystem::path(_mmap_allocator_base_dir));
+}
void
Fixture::set_example_tensors()
@@ -750,6 +760,23 @@ Fixture::test_populate_address_space_usage()
}
}
+void
+Fixture::test_mmap_file_allocator()
+{
+ std::filesystem::path allocator_dir(_mmap_allocator_base_dir + "/0.my_attr");
+ if (!_traits.use_mmap_file_allocator) {
+ EXPECT_FALSE(std::filesystem::is_directory(allocator_dir));
+ } else {
+ EXPECT_TRUE(std::filesystem::is_directory(allocator_dir));
+ int entry_cnt = 0;
+ for (auto& entry : std::filesystem::directory_iterator(allocator_dir)) {
+ EXPECT_LESS(0u, entry.file_size());
+ ++entry_cnt;
+ }
+ EXPECT_LESS(0, entry_cnt);
+ }
+}
+
template <class MakeFixture>
void testAll(MakeFixture &&f)
{
@@ -761,6 +788,7 @@ void testAll(MakeFixture &&f)
TEST_DO(f()->testEmptyTensor());
TEST_DO(f()->testOnHoldAccounting());
TEST_DO(f()->test_populate_address_space_usage());
+ TEST_DO(f()->test_mmap_file_allocator());
}
TEST("Test sparse tensors with generic tensor attribute")
@@ -768,6 +796,11 @@ TEST("Test sparse tensors with generic tensor attribute")
testAll([]() { return std::make_shared<Fixture>(sparseSpec); });
}
+TEST("Test sparse tensors with generic tensor attribute, paged")
+{
+ testAll([]() { return std::make_shared<Fixture>(sparseSpec, FixtureTraits().mmap_file_allocator()); });
+}
+
TEST("Test sparse tensors with direct tensor attribute")
{
testAll([]() { return std::make_shared<Fixture>(sparseSpec, FixtureTraits().direct()); });
@@ -778,11 +811,21 @@ TEST("Test dense tensors with generic tensor attribute")
testAll([]() { return std::make_shared<Fixture>(denseSpec); });
}
+TEST("Test dense tensors with generic tensor attribute, paged")
+{
+ testAll([]() { return std::make_shared<Fixture>(denseSpec, FixtureTraits().mmap_file_allocator()); });
+}
+
TEST("Test dense tensors with dense tensor attribute")
{
testAll([]() { return std::make_shared<Fixture>(denseSpec, FixtureTraits().dense()); });
}
+TEST("Test dense tensors with dense tensor attribute, paged")
+{
+ testAll([]() { return std::make_shared<Fixture>(denseSpec, FixtureTraits().dense().mmap_file_allocator()); });
+}
+
TEST_F("Hnsw index is NOT instantiated in dense tensor attribute by default",
Fixture(vec_2d_spec, FixtureTraits().dense()))
{
@@ -1176,17 +1219,4 @@ TEST_F("NN blueprint do NOT want global filter when NOT having index (implicit b
EXPECT_FALSE(bp->getState().want_global_filter());
}
-TEST("Dense tensor attribute with paged flag uses mmap file allocator")
-{
- vespalib::string basedir("mmap-file-allocator-factory-dir");
- vespalib::alloc::MmapFileAllocatorFactory::instance().setup(basedir);
- {
- Fixture f(vec_2d_spec, FixtureTraits().dense().mmap_file_allocator());
- vespalib::string allocator_dir(basedir + "/0.my_attr");
- EXPECT_TRUE(std::filesystem::is_directory(std::filesystem::path(allocator_dir)));
- }
- vespalib::alloc::MmapFileAllocatorFactory::instance().setup("");
- std::filesystem::remove_all(std::filesystem::path(basedir));
-}
-
TEST_MAIN() { TEST_RUN_ALL(); }
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
index dd7af1e8c4b..963285d760d 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp
@@ -64,7 +64,7 @@ allow_paged(const search::attribute::Config& config)
return false;
}
if (config.basicType() == Type::TENSOR) {
- return (!config.tensorType().is_error() && config.tensorType().is_dense());
+ return (!config.tensorType().is_error() && (config.tensorType().is_dense() || !config.fastSearch()));
}
return true;
}
diff --git a/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.cpp
index a24059b3f7c..52ccb4c91b1 100644
--- a/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.cpp
+++ b/searchlib/src/vespa/searchlib/tensor/serialized_fast_value_attribute.cpp
@@ -16,7 +16,7 @@ namespace search::tensor {
SerializedFastValueAttribute::SerializedFastValueAttribute(stringref name, const Config &cfg)
: TensorAttribute(name, cfg, _tensorBufferStore),
_tensor_type(cfg.tensorType()),
- _tensorBufferStore(_tensor_type, {}, 1000u)
+ _tensorBufferStore(_tensor_type, get_memory_allocator(), 1000u)
{
}