summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/tensor/tensor_buffer_type_mapper.h
blob: 950076c99248c88e1b7a0feac173148f2e395bdc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <cstddef>
#include <cstdint>
#include <vector>

namespace search::tensor {

class LargeSubspacesBufferType;
class SmallSubspacesBufferType;
class TensorBufferOperations;

/*
 * This class provides mapping between type ids and array sizes needed for
 * storing a tensor.
 */
class TensorBufferTypeMapper
{
    std::vector<size_t> _array_sizes;
    TensorBufferOperations* _ops;
public:
    using SmallBufferType = SmallSubspacesBufferType;
    using LargeBufferType = LargeSubspacesBufferType;

    TensorBufferTypeMapper();
    TensorBufferTypeMapper(uint32_t max_small_subspaces_type_id, TensorBufferOperations* ops);
    ~TensorBufferTypeMapper();

    uint32_t get_type_id(size_t array_size) const;
    size_t get_array_size(uint32_t type_id) const;
    TensorBufferOperations& get_tensor_buffer_operations() const noexcept { return *_ops; }
};

}