summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/tensor/tensor_buffer_type_mapper/tensor_buffer_type_mapper_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchlib/src/tests/tensor/tensor_buffer_type_mapper/tensor_buffer_type_mapper_test.cpp')
-rw-r--r--searchlib/src/tests/tensor/tensor_buffer_type_mapper/tensor_buffer_type_mapper_test.cpp49
1 files changed, 36 insertions, 13 deletions
diff --git a/searchlib/src/tests/tensor/tensor_buffer_type_mapper/tensor_buffer_type_mapper_test.cpp b/searchlib/src/tests/tensor/tensor_buffer_type_mapper/tensor_buffer_type_mapper_test.cpp
index fc574ba9b2c..6f25b9e07c5 100644
--- a/searchlib/src/tests/tensor/tensor_buffer_type_mapper/tensor_buffer_type_mapper_test.cpp
+++ b/searchlib/src/tests/tensor/tensor_buffer_type_mapper/tensor_buffer_type_mapper_test.cpp
@@ -3,10 +3,13 @@
#include <vespa/searchlib/tensor/tensor_buffer_type_mapper.h>
#include <vespa/searchlib/tensor/tensor_buffer_operations.h>
#include <vespa/eval/eval/value_type.h>
+#include <vespa/vespalib/datastore/array_store_config.h>
#include <vespa/vespalib/gtest/gtest.h>
+#include <limits>
using search::tensor::TensorBufferOperations;
using search::tensor::TensorBufferTypeMapper;
+using vespalib::datastore::ArrayStoreConfig;
using vespalib::eval::ValueType;
const vespalib::string tensor_type_sparse_spec("tensor(x{})");
@@ -15,18 +18,26 @@ const vespalib::string tensor_type_2d_mixed_spec("tensor(x{},y[2])");
const vespalib::string float_tensor_type_spec("tensor<float>(y{})");
const vespalib::string tensor_type_dense_spec("tensor(x[2])");
-constexpr double grow_factor = 1.03;
+namespace {
+
+constexpr double default_grow_factor = 1.03;
+constexpr size_t default_max_buffer_size = ArrayStoreConfig::default_max_buffer_size;
+constexpr size_t max_max_buffer_size = std::numeric_limits<uint32_t>::max();
+
+}
struct TestParam
{
vespalib::string _name;
std::vector<size_t> _array_sizes;
std::vector<size_t> _large_array_sizes;
+ std::vector<uint32_t> _type_id_caps;
vespalib::string _tensor_type_spec;
- TestParam(vespalib::string name, std::vector<size_t> array_sizes, std::vector<size_t> large_array_sizes, const vespalib::string& tensor_type_spec)
+ TestParam(vespalib::string name, std::vector<size_t> array_sizes, std::vector<size_t> large_array_sizes, std::vector<uint32_t> type_id_caps, const vespalib::string& tensor_type_spec)
: _name(std::move(name)),
_array_sizes(std::move(array_sizes)),
_large_array_sizes(std::move(large_array_sizes)),
+ _type_id_caps(type_id_caps),
_tensor_type_spec(tensor_type_spec)
{
}
@@ -61,7 +72,7 @@ TensorBufferTypeMapperTest::TensorBufferTypeMapperTest()
: testing::TestWithParam<TestParam>(),
_tensor_type(ValueType::from_spec(GetParam()._tensor_type_spec)),
_ops(_tensor_type),
- _mapper(GetParam()._array_sizes.size(), grow_factor, &_ops)
+ _mapper(GetParam()._array_sizes.size(), default_grow_factor, default_max_buffer_size, &_ops)
{
}
@@ -73,7 +84,7 @@ TensorBufferTypeMapperTest::get_array_sizes()
uint32_t max_small_subspaces_type_id = GetParam()._array_sizes.size();
std::vector<size_t> array_sizes;
for (uint32_t type_id = 1; type_id <= max_small_subspaces_type_id; ++type_id) {
- auto num_subspaces = type_id - 1;
+ auto num_subspaces = _tensor_type.is_dense() ? 1 : (type_id - 1);
array_sizes.emplace_back(_mapper.get_array_size(type_id));
EXPECT_EQ(_ops.get_buffer_size(num_subspaces), array_sizes.back());
}
@@ -85,10 +96,13 @@ TensorBufferTypeMapperTest::get_large_array_sizes()
{
auto& large_array_sizes = GetParam()._large_array_sizes;
uint32_t max_large = large_array_sizes.size();
- TensorBufferTypeMapper mapper(max_large * 100, grow_factor, &_ops);
+ TensorBufferTypeMapper mapper(max_large * 100, default_grow_factor, default_max_buffer_size, &_ops);
std::vector<size_t> result;
for (uint32_t i = 0; i < max_large; ++i) {
uint32_t type_id = (i + 1) * 100;
+ if (type_id > mapper.get_max_type_id(max_large * 100)) {
+ break;
+ }
auto array_size = mapper.get_array_size(type_id);
result.emplace_back(array_size);
EXPECT_EQ(type_id, mapper.get_type_id(array_size));
@@ -128,11 +142,11 @@ TensorBufferTypeMapperTest::select_type_ids()
INSTANTIATE_TEST_SUITE_P(TensorBufferTypeMapperMultiTest,
TensorBufferTypeMapperTest,
- testing::Values(TestParam("1d", {8, 16, 32, 40, 64}, {2768, 49712, 950768, 18268976, 351101184}, tensor_type_sparse_spec),
- TestParam("1dfloat", {4, 12, 20, 28, 36}, {2688, 48896, 937248, 18009808, 346121248}, float_tensor_type_spec),
- TestParam("2d", {8, 24, 40, 56, 80}, {2416, 41392, 790112, 15179616, 291726288}, tensor_type_2d_spec),
- TestParam("2dmixed", {8, 24, 48, 64, 96}, {3008, 51728, 987632, 18974512, 364657856}, tensor_type_2d_mixed_spec),
- TestParam("dense", {8, 24}, {}, tensor_type_dense_spec)),
+ testing::Values(TestParam("1d", {8, 16, 32, 40, 64}, {2768, 49712, 950768, 18268976, 351101184}, {27, 30, 514, 584}, tensor_type_sparse_spec),
+ TestParam("1dfloat", {4, 12, 20, 28, 36}, {2688, 48896, 937248, 18009808, 346121248}, {27, 30, 514, 585}, float_tensor_type_spec),
+ TestParam("2d", {8, 24, 40, 56, 80}, {2416, 41392, 790112, 15179616, 291726288}, {26, 29, 520, 590}, tensor_type_2d_spec),
+ TestParam("2dmixed", {8, 24, 48, 64, 96}, {3008, 51728, 987632, 18974512, 364657856}, {26, 29, 513, 583}, tensor_type_2d_mixed_spec),
+ TestParam("dense", {24}, {}, {1, 1, 1, 1}, tensor_type_dense_spec)),
testing::PrintToStringParamName());
TEST_P(TensorBufferTypeMapperTest, array_sizes_are_calculated)
@@ -150,10 +164,19 @@ TEST_P(TensorBufferTypeMapperTest, large_arrays_grows_exponentially)
EXPECT_EQ(GetParam()._large_array_sizes, get_large_array_sizes());
}
-TEST_P(TensorBufferTypeMapperTest, avoid_array_size_overflow)
+TEST_P(TensorBufferTypeMapperTest, type_id_is_capped)
{
- TensorBufferTypeMapper mapper(300, 2.0, &_ops);
- EXPECT_GE(30, mapper.get_max_type_id(1000));
+ auto& exp_type_id_caps = GetParam()._type_id_caps;
+ std::vector<uint32_t> act_type_id_caps;
+ std::vector<double> grow_factors = { 2.0, default_grow_factor };
+ std::vector<size_t> max_buffer_sizes = { default_max_buffer_size, max_max_buffer_size };
+ for (auto& grow_factor : grow_factors) {
+ for (auto max_buffer_size : max_buffer_sizes) {
+ TensorBufferTypeMapper mapper(1000, grow_factor, max_buffer_size, &_ops);
+ act_type_id_caps.emplace_back(mapper.get_max_type_id(1000));
+ }
+ }
+ EXPECT_EQ(exp_type_id_caps, act_type_id_caps);
}
GTEST_MAIN_RUN_ALL_TESTS()