Open3D (C++ API)  0.18.0+252c867
HashBackendBuffer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 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 
19 namespace open3d {
20 namespace core {
21 
22 void CPUResetHeap(Tensor &heap);
23 
24 #ifdef BUILD_CUDA_MODULE
25 void 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.
45 
47 public:
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 
98 protected:
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
HashBackendBuffer(int64_t capacity, int64_t key_dsize, std::vector< int64_t > value_dsizes, const Device &device)
Definition: HashBackendBuffer.cpp:15
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
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle uint32_t
Definition: K4aPlugin.cpp:548
Definition: PinholeCameraIntrinsic.cpp:16
Definition: HashBackendBuffer.h:48
std::atomic< int > cpu
Definition: HashBackendBuffer.h:50
Tensor cuda
Definition: HashBackendBuffer.h:49