Open3D (C++ API)  0.16.1
DeviceHashBackend.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
31#include "open3d/core/Tensor.h"
33
34namespace open3d {
35namespace core {
36
37enum class HashBackendType;
38
40public:
41 DeviceHashBackend(int64_t init_capacity,
42 int64_t key_dsize,
43 const std::vector<int64_t>& value_dsizes,
44 const Device& device)
45 : capacity_(init_capacity),
46 key_dsize_(key_dsize),
47 value_dsizes_(value_dsizes),
48 device_(device) {}
49 virtual ~DeviceHashBackend() {}
50
57 virtual void Reserve(int64_t capacity) = 0;
58
60 virtual void Insert(const void* input_keys,
61 const std::vector<const void*>& input_values,
62 buf_index_t* output_buf_indices,
63 bool* output_masks,
64 int64_t count) = 0;
65
67 virtual void Find(const void* input_keys,
68 buf_index_t* output_buf_indices,
69 bool* output_masks,
70 int64_t count) = 0;
71
73 virtual void Erase(const void* input_keys,
74 bool* output_masks,
75 int64_t count) = 0;
76
78 virtual int64_t GetActiveIndices(buf_index_t* output_buf_indices) = 0;
79
81 virtual void Clear() = 0;
82
84 virtual int64_t Size() const = 0;
85
87 virtual int64_t GetBucketCount() const = 0;
88
90 virtual float LoadFactor() const = 0;
91
93 int64_t GetCapacity() const { return capacity_; }
94
96 Device GetDevice() const { return device_; }
97
99 virtual std::vector<int64_t> BucketSizes() const = 0;
100
102 Tensor GetKeyBuffer() { return buffer_->GetKeyBuffer(); }
103
105 std::vector<Tensor> GetValueBuffers() { return buffer_->GetValueBuffers(); }
106
108 Tensor GetValueBuffer(size_t i = 0) { return buffer_->GetValueBuffer(i); }
109
110 virtual void Allocate(int64_t capacity) = 0;
111 virtual void Free() = 0;
112
113public:
114 int64_t capacity_;
115
116 int64_t key_dsize_;
117 std::vector<int64_t> value_dsizes_;
118
120
121 std::shared_ptr<HashBackendBuffer> buffer_;
122};
123
128std::shared_ptr<DeviceHashBackend> CreateDeviceHashBackend(
129 int64_t init_capacity,
130 const Dtype& key_dtype,
131 const SizeVector& key_element_shape,
132 const std::vector<Dtype>& value_dtypes,
133 const std::vector<SizeVector>& value_element_shapes,
134 const Device& device,
135 const HashBackendType& backend);
136
137std::shared_ptr<DeviceHashBackend> CreateCPUHashBackend(
138 int64_t init_capacity,
139 const Dtype& key_dtype,
140 const SizeVector& key_element_shape,
141 const std::vector<Dtype>& value_dtypes,
142 const std::vector<SizeVector>& value_element_shapes,
143 const Device& device,
144 const HashBackendType& backend);
145
146std::shared_ptr<DeviceHashBackend> CreateCUDAHashBackend(
147 int64_t init_capacity,
148 const Dtype& key_dtype,
149 const SizeVector& key_element_shape,
150 const std::vector<Dtype>& value_dtypes,
151 const std::vector<SizeVector>& value_element_shapes,
152 const Device& device,
153 const HashBackendType& backend);
154
155} // namespace core
156} // namespace open3d
Common CUDA utilities.
Definition: DeviceHashBackend.h:39
virtual void Insert(const void *input_keys, const std::vector< const void * > &input_values, buf_index_t *output_buf_indices, bool *output_masks, int64_t count)=0
Parallel insert contiguous arrays of keys and values.
int64_t GetCapacity() const
Get the maximum capacity of the hash map.
Definition: DeviceHashBackend.h:93
virtual void Erase(const void *input_keys, bool *output_masks, int64_t count)=0
Parallel erase a contiguous array of keys.
virtual void Allocate(int64_t capacity)=0
virtual void Clear()=0
Clear stored map without reallocating memory.
Device GetDevice() const
Get the current device.
Definition: DeviceHashBackend.h:96
std::vector< int64_t > value_dsizes_
Definition: DeviceHashBackend.h:117
std::shared_ptr< HashBackendBuffer > buffer_
Definition: DeviceHashBackend.h:121
Device device_
Definition: DeviceHashBackend.h:119
int64_t key_dsize_
Definition: DeviceHashBackend.h:116
Tensor GetValueBuffer(size_t i=0)
Get the i-th value buffer that store an actual value array.
Definition: DeviceHashBackend.h:108
Tensor GetKeyBuffer()
Get the key buffer that stores actual keys.
Definition: DeviceHashBackend.h:102
virtual void Reserve(int64_t capacity)=0
std::vector< Tensor > GetValueBuffers()
Get the value buffers that store actual array of values.
Definition: DeviceHashBackend.h:105
int64_t capacity_
Definition: DeviceHashBackend.h:114
virtual ~DeviceHashBackend()
Definition: DeviceHashBackend.h:49
virtual std::vector< int64_t > BucketSizes() const =0
Get the number of entries per bucket.
virtual int64_t GetBucketCount() const =0
Get the number of buckets of the hash map.
virtual int64_t GetActiveIndices(buf_index_t *output_buf_indices)=0
Parallel collect all iterators in the hash table.
virtual float LoadFactor() const =0
Get the current load factor, defined as size / bucket count.
virtual void Find(const void *input_keys, buf_index_t *output_buf_indices, bool *output_masks, int64_t count)=0
Parallel find a contiguous array of keys.
DeviceHashBackend(int64_t init_capacity, int64_t key_dsize, const std::vector< int64_t > &value_dsizes, const Device &device)
Definition: DeviceHashBackend.h:41
virtual int64_t Size() const =0
Get the size (number of valid entries) of the hash map.
Definition: Device.h:37
Definition: Dtype.h:39
Definition: SizeVector.h:88
Definition: Tensor.h:51
int count
Definition: FilePCD.cpp:61
std::shared_ptr< DeviceHashBackend > CreateCUDAHashBackend(int64_t init_capacity, const Dtype &key_dtype, const SizeVector &key_element_shape, const std::vector< Dtype > &value_dtypes, const std::vector< SizeVector > &value_element_shapes, const Device &device, const HashBackendType &backend)
std::shared_ptr< DeviceHashBackend > CreateCPUHashBackend(int64_t init_capacity, const Dtype &key_dtype, const SizeVector &key_element_shape, const std::vector< Dtype > &value_dtypes, const std::vector< SizeVector > &value_element_shapes, const Device &device, const HashBackendType &backend)
Non-templated factory.
Definition: CreateCPUHashBackend.cpp:35
uint32_t buf_index_t
Definition: HashBackendBuffer.h:63
std::shared_ptr< DeviceHashBackend > CreateDeviceHashBackend(int64_t init_capacity, const Dtype &key_dtype, const SizeVector &key_element_shape, const std::vector< Dtype > &value_dtypes, const std::vector< SizeVector > &value_element_shapes, const Device &device, const HashBackendType &backend)
Definition: DeviceHashBackend.cpp:36
HashBackendType
Definition: HashMap.h:39
Definition: PinholeCameraIntrinsic.cpp:35