Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Hashmap.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 #pragma once
28 
29 #include "open3d/core/Dtype.h"
30 #include "open3d/core/Tensor.h"
32 
33 namespace open3d {
34 namespace core {
35 
36 class DeviceHashmap;
37 
38 enum class HashmapBackend { Slab, StdGPU, TBB, Default };
39 
40 class Hashmap {
41 public:
47  Hashmap(int64_t init_capacity,
48  const Dtype& dtype_key,
49  const Dtype& dtype_value,
50  const SizeVector& element_shape_key,
51  const SizeVector& element_shape_value,
52  const Device& device,
53  const HashmapBackend& backend = HashmapBackend::Default);
54 
55  ~Hashmap(){};
56 
62  void Rehash(int64_t buckets);
63 
69  void Insert(const Tensor& input_keys,
70  const Tensor& input_values,
71  Tensor& output_addrs,
72  Tensor& output_masks);
73 
81  void Activate(const Tensor& input_keys,
82  Tensor& output_addrs,
83  Tensor& output_masks);
84 
90  void Find(const Tensor& input_keys,
91  Tensor& output_addrs,
92  Tensor& output_masks);
93 
98  void Erase(const Tensor& input_keys, Tensor& output_masks);
99 
103  void GetActiveIndices(Tensor& output_indices) const;
104 
106  void Clear();
107 
108  Hashmap Clone() const;
109  Hashmap To(const Device& device, bool copy = false) const;
110  Hashmap CPU() const;
111  Hashmap CUDA(int device_id = 0) const;
112 
113  int64_t Size() const;
114 
115  int64_t GetCapacity() const;
116  int64_t GetBucketCount() const;
117  Device GetDevice() const;
118  int64_t GetKeyBytesize() const;
119  int64_t GetValueBytesize() const;
120 
121  Tensor& GetKeyBuffer() const;
122  Tensor& GetValueBuffer() const;
123 
124  Tensor GetKeyTensor() const;
125  Tensor GetValueTensor() const;
126 
129  std::vector<int64_t> BucketSizes() const;
130 
132  float LoadFactor() const;
133 
134  std::shared_ptr<DeviceHashmap> GetDeviceHashmap() const {
135  return device_hashmap_;
136  }
137 
138 protected:
139  void AssertKeyDtype(const Dtype& dtype_key,
140  const SizeVector& elem_shape) const;
141  void AssertValueDtype(const Dtype& dtype_val,
142  const SizeVector& elem_shape) const;
143 
144  Dtype GetKeyDtype() const { return dtype_key_; }
145  Dtype GetValueDtype() const { return dtype_value_; }
146 
147 private:
148  std::shared_ptr<DeviceHashmap> device_hashmap_;
149 
150  Dtype dtype_key_;
151  Dtype dtype_value_;
152 
153  SizeVector element_shape_key_;
154  SizeVector element_shape_value_;
155 };
156 
157 } // namespace core
158 } // namespace open3d
HashmapBackend
Definition: Hashmap.h:38
Definition: Dtype.h:39
Definition: SizeVector.h:102
Definition: Device.h:39
~Hashmap()
Definition: Hashmap.h:55
Dtype GetKeyDtype() const
Definition: Hashmap.h:144
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:50
void To(const core::Tensor &src_im, core::Tensor &dst_im, double scale, double offset)
Definition: IPPImage.cpp:46
Dtype GetValueDtype() const
Definition: Hashmap.h:145
std::shared_ptr< DeviceHashmap > GetDeviceHashmap() const
Definition: Hashmap.h:134
Definition: Hashmap.h:40