Open3D (C++ API)  0.12.0
HashmapBuffer.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 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 // The value_ array's size is FIXED.
28 // The heap_ array stores the addresses of the values.
29 // Only the unallocated part is maintained.
30 // (ONLY care about the heap above the heap counter. Below is
31 // meaningless.)
32 // During Allocate, ptr is extracted from the heap;
33 // During Free, ptr is put back to the top of the heap.
34 // ---------------------------------------------------------------------
35 // heap ---Malloc--> heap ---Malloc--> heap ---Free(0)--> heap
36 // N-1 N-1 N-1 N-1 |
37 // . . . . |
38 // . . . . |
39 // . . . . |
40 // 3 3 3 3 |
41 // 2 2 2 <- 2 |
42 // 1 1 <- 1 0 <- |
43 // 0 <- heap_counter 0 0 0
44 #pragma once
45 
46 #include <assert.h>
47 
48 #include <memory>
49 #include <vector>
50 
52 #include "open3d/core/Tensor.h"
53 
54 namespace open3d {
55 namespace core {
56 
57 // Type for the internal heap. Dtype::Int32 is used to store it in Tensors.
58 typedef uint32_t addr_t;
59 
61 public:
62  HashmapBuffer(int64_t capacity,
63  int64_t dsize_key,
64  int64_t dsize_value,
65  const Device &device)
66  : capacity_(capacity),
67  dsize_key_(dsize_key),
68  dsize_value_(dsize_value),
69  device_(device) {
70  key_buffer_ =
71  Tensor({capacity_},
73  device_);
75  Tensor({capacity_},
77  device_);
79  }
80 
83  Tensor &GetHeap() { return heap_; }
84 
85 protected:
86  int64_t capacity_;
87  int64_t dsize_key_;
88  int64_t dsize_value_;
89 
93 
95 };
96 } // namespace core
97 } // namespace open3d
HashmapBuffer(int64_t capacity, int64_t dsize_key, int64_t dsize_value, const Device &device)
Definition: HashmapBuffer.h:62
Device device_
Definition: HashmapBuffer.h:94
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
Tensor key_buffer_
Definition: HashmapBuffer.h:90
Definition: Dtype.h:39
Tensor & GetKeyBuffer()
Definition: HashmapBuffer.h:81
int64_t dsize_key_
Definition: HashmapBuffer.h:87
int64_t dsize_value_
Definition: HashmapBuffer.h:88
static const Dtype Int32
Definition: Dtype.h:44
Definition: Device.h:39
int64_t capacity_
Definition: HashmapBuffer.h:86
Definition: HashmapBuffer.h:60
Tensor & GetHeap()
Definition: HashmapBuffer.h:83
Tensor value_buffer_
Definition: HashmapBuffer.h:91
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:48
uint32_t addr_t
Definition: HashmapBuffer.h:58
Tensor & GetValueBuffer()
Definition: HashmapBuffer.h:82
Tensor heap_
Definition: HashmapBuffer.h:92