Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HashBackendBuffer.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <assert.h>
30 
31 #include <atomic>
32 #include <memory>
33 #include <vector>
34 
36 #include "open3d/core/Tensor.h"
37 
38 namespace open3d {
39 namespace core {
40 
41 void CPUResetHeap(Tensor &heap);
42 
43 #ifdef BUILD_CUDA_MODULE
44 void CUDAResetHeap(Tensor &heap);
45 #endif
46 
47 // The heap array stores the indices of the key/values buffers. It is not
48 // injective.
49 // During Allocate, an buffer index (buf_index) is extracted from the
50 // heap; During Free, a buf_index is put back to the top of the heap.
51 // ---------------------------------------------------------------------
52 // heap ---Malloc--> heap ---Malloc--> heap ---Free(0)--> heap
53 // N-1 N-1 N-1 N-1 |
54 // . . . . |
55 // . . . . |
56 // . . . . |
57 // 3 3 3 3 |
58 // 2 2 2 <- 2 |
59 // 1 1 <- 1 0 <- |
60 // 0 <- heap_top 0 0 0
61 
62 // Buffer index type for the internal heap.
64 
66 public:
67  struct HeapTop {
69  std::atomic<int> cpu = {0};
70  };
71 
72  HashBackendBuffer(int64_t capacity,
73  int64_t key_dsize,
74  std::vector<int64_t> value_dsizes,
75  const Device &device);
76 
78  void ResetHeap();
79 
81  Device GetDevice() const;
82 
84  int64_t GetCapacity() const;
85 
87  int64_t GetKeyDsize() const;
88 
90  std::vector<int64_t> GetValueDsizes() const;
91 
93  int64_t GetCommonBlockSize() const;
94 
96  std::vector<int64_t> GetValueBlocksPerElement() const;
97 
99  Tensor GetIndexHeap() const;
100 
103  HeapTop &GetHeapTop();
104 
106  int GetHeapTopIndex() const;
107 
109  Tensor GetKeyBuffer() const;
110 
112  std::vector<Tensor> GetValueBuffers() const;
113 
115  Tensor GetValueBuffer(size_t i = 0) const;
116 
117 protected:
120 
122  std::vector<Tensor> value_buffers_;
123 
125  std::vector<int64_t> blocks_per_element_;
126 };
127 } // namespace core
128 } // namespace open3d
Tensor GetIndexHeap() const
Return the index heap tensor.
Definition: HashBackendBuffer.cpp:115
int64_t GetCommonBlockSize() const
Get the common block size divisor of all values types.
Definition: HashBackendBuffer.cpp:107
int64_t GetKeyDsize() const
Return key&#39;s data size in bytes.
Definition: HashBackendBuffer.cpp:95
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:557
HashBackendBuffer(int64_t capacity, int64_t key_dsize, std::vector< int64_t > value_dsizes, const Device &device)
Definition: HashBackendBuffer.cpp:33
Device GetDevice() const
Return device of the buffer.
Definition: HashBackendBuffer.cpp:91
std::vector< int64_t > GetValueDsizes() const
Return value&#39;s data sizes in bytes.
Definition: HashBackendBuffer.cpp:99
std::vector< int64_t > blocks_per_element_
Definition: HashBackendBuffer.h:125
std::vector< Tensor > value_buffers_
Definition: HashBackendBuffer.h:122
uint32_t buf_index_t
Definition: HashBackendBuffer.h:63
int GetHeapTopIndex() const
Return the current heap top.
Definition: HashBackendBuffer.cpp:121
Tensor cuda
Definition: HashBackendBuffer.h:68
Definition: Device.h:39
int64_t common_block_size_
Definition: HashBackendBuffer.h:124
std::vector< Tensor > GetValueBuffers() const
Return the value buffer tensors.
Definition: HashBackendBuffer.cpp:130
Definition: HashBackendBuffer.h:67
Tensor heap_
Definition: HashBackendBuffer.h:118
void CPUResetHeap(Tensor &heap)
Definition: CPUHashBackendBuffer.cpp:32
HeapTop & GetHeapTop()
Definition: HashBackendBuffer.cpp:117
Definition: PinholeCameraIntrinsic.cpp:35
void ResetHeap()
Reset the heap and heap top.
Definition: HashBackendBuffer.cpp:78
Definition: Tensor.h:50
HeapTop heap_top_
Definition: HashBackendBuffer.h:119
Definition: HashBackendBuffer.h:65
std::atomic< int > cpu
Definition: HashBackendBuffer.h:69
Tensor key_buffer_
Definition: HashBackendBuffer.h:121
int64_t GetCapacity() const
Return capacity of the buffer.
Definition: HashBackendBuffer.cpp:93
Tensor GetValueBuffer(size_t i=0) const
Return the selected value buffer tensor at index i.
Definition: HashBackendBuffer.cpp:134
std::vector< int64_t > GetValueBlocksPerElement() const
Return value&#39;s data sizes in the unit of common block size divisor.
Definition: HashBackendBuffer.cpp:111
Tensor GetKeyBuffer() const
Return the key buffer tensor.
Definition: HashBackendBuffer.cpp:128