Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DeviceHashmap.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/CUDAUtils.h"
31 #include "open3d/core/Tensor.h"
33 
34 namespace open3d {
35 namespace core {
36 
37 enum class HashmapBackend;
38 
40 public:
42  DeviceHashmap(int64_t init_capacity,
43  int64_t dsize_key,
44  int64_t dsize_value,
45  const Device& device)
46  : capacity_(init_capacity),
47  dsize_key_(dsize_key),
48  dsize_value_(dsize_value),
49  device_(device) {}
50  virtual ~DeviceHashmap() {}
51 
58  virtual void Rehash(int64_t buckets) = 0;
59 
61  virtual void Insert(const void* input_keys,
62  const void* input_values,
63  addr_t* output_iterators,
64  bool* output_masks,
65  int64_t count) = 0;
66 
70  virtual void Activate(const void* input_keys,
71  addr_t* output_iterators,
72  bool* output_masks,
73  int64_t count) = 0;
74 
76  virtual void Find(const void* input_keys,
77  addr_t* output_iterators,
78  bool* output_masks,
79  int64_t count) = 0;
80 
82  virtual void Erase(const void* input_keys,
83  bool* output_masks,
84  int64_t count) = 0;
85 
87  virtual int64_t GetActiveIndices(addr_t* output_indices) = 0;
88 
90  virtual void Clear() = 0;
91 
92  virtual int64_t Size() const = 0;
93  virtual int64_t GetBucketCount() const = 0;
94  virtual float LoadFactor() const = 0;
95 
96  int64_t GetCapacity() const { return capacity_; }
97  int64_t GetKeyBytesize() const { return dsize_key_; }
98  int64_t GetValueBytesize() const { return dsize_value_; }
99  Device GetDevice() const { return device_; }
100 
101  Tensor& GetKeyBuffer() { return buffer_->GetKeyBuffer(); }
102  Tensor& GetValueBuffer() { return buffer_->GetValueBuffer(); }
103 
106  virtual std::vector<int64_t> BucketSizes() const = 0;
107 
108 public:
109  int64_t capacity_;
110  int64_t dsize_key_;
111  int64_t dsize_value_;
112 
114 
115  std::shared_ptr<HashmapBuffer> buffer_;
116 };
117 
122 std::shared_ptr<DeviceHashmap> CreateDeviceHashmap(
123  int64_t init_capacity,
124  const Dtype& dtype_key,
125  const Dtype& dtype_value,
126  const SizeVector& element_shape_key,
127  const SizeVector& element_shape_value,
128  const Device& device,
129  const HashmapBackend& backend);
130 
131 std::shared_ptr<DeviceHashmap> CreateCPUHashmap(
132  int64_t init_capacity,
133  const Dtype& dtype_key,
134  const Dtype& dtype_value,
135  const SizeVector& element_shape_key,
136  const SizeVector& element_shape_value,
137  const Device& device,
138  const HashmapBackend& backend);
139 
140 std::shared_ptr<DeviceHashmap> CreateCUDAHashmap(
141  int64_t init_capacity,
142  const Dtype& dtype_key,
143  const Dtype& dtype_value,
144  const SizeVector& element_shape_key,
145  const SizeVector& element_shape_value,
146  const Device& device,
147  const HashmapBackend& backend);
148 
149 } // namespace core
150 } // namespace open3d
virtual float LoadFactor() const =0
HashmapBackend
Definition: Hashmap.h:38
Definition: Dtype.h:39
virtual int64_t GetBucketCount() const =0
Definition: SizeVector.h:102
std::shared_ptr< DeviceHashmap > CreateDeviceHashmap(int64_t init_capacity, const Dtype &dtype_key, const Dtype &dtype_value, const SizeVector &element_shape_key, const SizeVector &element_shape_value, const Device &device, const HashmapBackend &backend)
Definition: DeviceHashmap.cpp:36
Definition: DeviceHashmap.h:39
Device GetDevice() const
Definition: DeviceHashmap.h:99
virtual int64_t GetActiveIndices(addr_t *output_indices)=0
Parallel collect all iterators in the hash table.
virtual ~DeviceHashmap()
Definition: DeviceHashmap.h:50
DeviceHashmap(int64_t init_capacity, int64_t dsize_key, int64_t dsize_value, const Device &device)
Comprehensive constructor for the developer.
Definition: DeviceHashmap.h:42
int64_t GetValueBytesize() const
Definition: DeviceHashmap.h:98
std::shared_ptr< DeviceHashmap > CreateCPUHashmap(int64_t init_capacity, const Dtype &dtype_key, const Dtype &dtype_value, const SizeVector &element_shape_key, const SizeVector &element_shape_value, const Device &device, const HashmapBackend &backend)
Non-templated factory.
Definition: CreateCPUHashmap.cpp:35
Device device_
Definition: DeviceHashmap.h:113
Definition: Device.h:39
std::shared_ptr< DeviceHashmap > CreateCUDAHashmap(int64_t init_capacity, const Dtype &dtype_key, const Dtype &dtype_value, const SizeVector &element_shape_key, const SizeVector &element_shape_value, const Device &device, const HashmapBackend &backend)
virtual void Insert(const void *input_keys, const void *input_values, addr_t *output_iterators, bool *output_masks, int64_t count)=0
Parallel insert contiguous arrays of keys and values.
int64_t GetKeyBytesize() const
Definition: DeviceHashmap.h:97
int count
Definition: FilePCD.cpp:61
virtual void Find(const void *input_keys, addr_t *output_iterators, bool *output_masks, int64_t count)=0
Parallel find a contiguous array of keys.
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:50
virtual int64_t Size() const =0
int64_t capacity_
Definition: DeviceHashmap.h:109
virtual void Erase(const void *input_keys, bool *output_masks, int64_t count)=0
Parallel erase a contiguous array of keys.
Tensor & GetKeyBuffer()
Definition: DeviceHashmap.h:101
virtual void Activate(const void *input_keys, addr_t *output_iterators, bool *output_masks, int64_t count)=0
virtual void Rehash(int64_t buckets)=0
uint32_t addr_t
Definition: HashmapBuffer.h:58
int64_t dsize_key_
Definition: DeviceHashmap.h:110
int64_t dsize_value_
Definition: DeviceHashmap.h:111
Common CUDA utilities.
virtual std::vector< int64_t > BucketSizes() const =0
int64_t GetCapacity() const
Definition: DeviceHashmap.h:96
Tensor & GetValueBuffer()
Definition: DeviceHashmap.h:102
virtual void Clear()=0
Clear stored map without reallocating memory.
std::shared_ptr< HashmapBuffer > buffer_
Definition: DeviceHashmap.h:115