Open3D (C++ API)  0.19.0
Loading...
Searching...
No Matches
HashBackendBuffer.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2024 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10#include <assert.h>
11
12#include <atomic>
13#include <memory>
14#include <vector>
15
17#include "open3d/core/Tensor.h"
18
19namespace open3d {
20namespace core {
21
22void CPUResetHeap(Tensor &heap);
23
24#ifdef BUILD_CUDA_MODULE
25void CUDAResetHeap(Tensor &heap);
26#endif
27
28// The heap array stores the indices of the key/values buffers. It is not
29// injective.
30// During Allocate, an buffer index (buf_index) is extracted from the
31// heap; During Free, a buf_index is put back to the top of the heap.
32// ---------------------------------------------------------------------
33// heap ---Malloc--> heap ---Malloc--> heap ---Free(0)--> heap
34// N-1 N-1 N-1 N-1 |
35// . . . . |
36// . . . . |
37// . . . . |
38// 3 3 3 3 |
39// 2 2 2 <- 2 |
40// 1 1 <- 1 0 <- |
41// 0 <- heap_top 0 0 0
42
43// Buffer index type for the internal heap.
44using buf_index_t = uint32_t;
45
47public:
48 struct HeapTop {
50 std::atomic<int> cpu = {0};
51 };
52
53 HashBackendBuffer(int64_t capacity,
54 int64_t key_dsize,
55 std::vector<int64_t> value_dsizes,
56 const Device &device);
57
59 void ResetHeap();
60
62 Device GetDevice() const;
63
65 int64_t GetCapacity() const;
66
68 int64_t GetKeyDsize() const;
69
71 std::vector<int64_t> GetValueDsizes() const;
72
74 int64_t GetCommonBlockSize() const;
75
77 std::vector<int64_t> GetValueBlocksPerElement() const;
78
80 Tensor GetIndexHeap() const;
81
84 HeapTop &GetHeapTop();
85
87 int GetHeapTopIndex() const;
88
90 Tensor GetKeyBuffer() const;
91
93 std::vector<Tensor> GetValueBuffers() const;
94
96 Tensor GetValueBuffer(size_t i = 0) const;
97
98protected:
101
103 std::vector<Tensor> value_buffers_;
104
106 std::vector<int64_t> blocks_per_element_;
107};
108} // namespace core
109} // namespace open3d
Definition Device.h:18
Definition HashBackendBuffer.h:46
int64_t GetKeyDsize() const
Return key's data size in bytes.
Definition HashBackendBuffer.cpp:77
Tensor key_buffer_
Definition HashBackendBuffer.h:102
void ResetHeap()
Reset the heap and heap top.
Definition HashBackendBuffer.cpp:60
std::vector< Tensor > value_buffers_
Definition HashBackendBuffer.h:103
Tensor heap_
Definition HashBackendBuffer.h:99
Device GetDevice() const
Return device of the buffer.
Definition HashBackendBuffer.cpp:73
Tensor GetIndexHeap() const
Return the index heap tensor.
Definition HashBackendBuffer.cpp:97
int64_t GetCapacity() const
Return capacity of the buffer.
Definition HashBackendBuffer.cpp:75
HeapTop heap_top_
Definition HashBackendBuffer.h:100
int GetHeapTopIndex() const
Return the current heap top.
Definition HashBackendBuffer.cpp:103
int64_t common_block_size_
Definition HashBackendBuffer.h:105
HeapTop & GetHeapTop()
Definition HashBackendBuffer.cpp:99
std::vector< int64_t > blocks_per_element_
Definition HashBackendBuffer.h:106
Tensor GetKeyBuffer() const
Return the key buffer tensor.
Definition HashBackendBuffer.cpp:110
std::vector< int64_t > GetValueDsizes() const
Return value's data sizes in bytes.
Definition HashBackendBuffer.cpp:81
Tensor GetValueBuffer(size_t i=0) const
Return the selected value buffer tensor at index i.
Definition HashBackendBuffer.cpp:116
int64_t GetCommonBlockSize() const
Get the common block size divisor of all values types.
Definition HashBackendBuffer.cpp:89
std::vector< Tensor > GetValueBuffers() const
Return the value buffer tensors.
Definition HashBackendBuffer.cpp:112
std::vector< int64_t > GetValueBlocksPerElement() const
Return value's data sizes in the unit of common block size divisor.
Definition HashBackendBuffer.cpp:93
Definition Tensor.h:32
void CPUResetHeap(Tensor &heap)
Definition CPUHashBackendBuffer.cpp:13
uint32_t buf_index_t
Definition HashBackendBuffer.h:44
Definition PinholeCameraIntrinsic.cpp:16
Definition HashBackendBuffer.h:48
std::atomic< int > cpu
Definition HashBackendBuffer.h:50
Tensor cuda
Definition HashBackendBuffer.h:49