17 std::vector<int64_t> value_dsizes,
20 const std::vector<int64_t> kDivisors = {16, 12, 8, 4, 2, 1};
22 for (
const auto &divisor : kDivisors) {
25 for (
size_t i = 0; i < value_dsizes.size(); ++i) {
26 int64_t bytesize = value_dsizes[i];
27 valid = valid && (bytesize % divisor == 0);
43 for (
size_t i = 0; i < value_dsizes.size(); ++i) {
44 int64_t dsize_value = value_dsizes[i];
45 Tensor value_buffer_i({capacity},
67 }
else if (device.
IsCUDA()) {
82 std::vector<int64_t> value_dsizes;
84 value_dsizes.push_back(value_buffer.GetDtype().ByteSize());
#define CUDA_CALL(cuda_function,...)
bool IsCUDA() const
Returns true iff device type is CUDA.
bool IsCPU() const
Returns true iff device type is CPU.
int64_t GetKeyDsize() const
Return key's data size in bytes.
std::vector< Tensor > value_buffers_
Tensor GetKeyBuffer() const
Return the key buffer tensor.
HashBackendBuffer(int64_t capacity, int64_t key_dsize, std::vector< int64_t > value_dsizes, const Device &device)
Device GetDevice() const
Return device of the buffer.
int GetHeapTopIndex() const
Return the current heap top.
std::vector< int64_t > GetValueDsizes() const
Return value's data sizes in bytes.
std::vector< int64_t > GetValueBlocksPerElement() const
Return value's data sizes in the unit of common block size divisor.
Tensor GetValueBuffer(size_t i=0) const
Return the selected value buffer tensor at index i.
int64_t GetCommonBlockSize() const
Get the common block size divisor of all values types.
int64_t common_block_size_
std::vector< Tensor > GetValueBuffers() const
Return the value buffer tensors.
std::vector< int64_t > blocks_per_element_
int64_t GetCapacity() const
Return capacity of the buffer.
void ResetHeap()
Reset the heap and heap top.
Tensor GetIndexHeap() const
Return the index heap tensor.
int64_t GetLength() const
Device GetDevice() const override
void Fill(S v)
Fill the whole Tensor with a scalar value, the scalar will be casted to the Tensor's Dtype.
void CPUResetHeap(Tensor &heap)
Generic file read and write utility for python interface.
std::string to_string(const T &n)