Open3D (C++ API)  0.19.0
Loading...
Searching...
No Matches
DeviceHashBackend.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2024 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
12#include "open3d/core/Tensor.h"
14
15namespace open3d {
16namespace core {
17
18enum class HashBackendType;
19
21public:
22 DeviceHashBackend(int64_t init_capacity,
23 int64_t key_dsize,
24 const std::vector<int64_t>& value_dsizes,
25 const Device& device)
26 : capacity_(init_capacity),
27 key_dsize_(key_dsize),
28 value_dsizes_(value_dsizes),
29 device_(device) {}
30 virtual ~DeviceHashBackend() {}
31
38 virtual void Reserve(int64_t capacity) = 0;
39
41 virtual void Insert(const void* input_keys,
42 const std::vector<const void*>& input_values,
43 buf_index_t* output_buf_indices,
44 bool* output_masks,
45 int64_t count) = 0;
46
48 virtual void Find(const void* input_keys,
49 buf_index_t* output_buf_indices,
50 bool* output_masks,
51 int64_t count) = 0;
52
54 virtual void Erase(const void* input_keys,
55 bool* output_masks,
56 int64_t count) = 0;
57
59 virtual int64_t GetActiveIndices(buf_index_t* output_buf_indices) = 0;
60
62 virtual void Clear() = 0;
63
65 virtual int64_t Size() const = 0;
66
68 virtual int64_t GetNonEmptyCount() const { return Size(); }
69
71 virtual int64_t GetBucketCount() const = 0;
72
74 virtual float LoadFactor() const = 0;
75
77 int64_t GetCapacity() const { return capacity_; }
78
80 Device GetDevice() const { return device_; }
81
83 virtual std::vector<int64_t> BucketSizes() const = 0;
84
86 Tensor GetKeyBuffer() { return buffer_->GetKeyBuffer(); }
87
89 std::vector<Tensor> GetValueBuffers() { return buffer_->GetValueBuffers(); }
90
92 Tensor GetValueBuffer(size_t i = 0) { return buffer_->GetValueBuffer(i); }
93
94 virtual void Allocate(int64_t capacity) = 0;
95 virtual void Free() = 0;
96
97public:
98 int64_t capacity_;
99
100 int64_t key_dsize_;
101 std::vector<int64_t> value_dsizes_;
102
104
105 std::shared_ptr<HashBackendBuffer> buffer_;
106};
107
112std::shared_ptr<DeviceHashBackend> CreateDeviceHashBackend(
113 int64_t init_capacity,
114 const Dtype& key_dtype,
115 const SizeVector& key_element_shape,
116 const std::vector<Dtype>& value_dtypes,
117 const std::vector<SizeVector>& value_element_shapes,
118 const Device& device,
119 const HashBackendType& backend);
120
121std::shared_ptr<DeviceHashBackend> CreateCPUHashBackend(
122 int64_t init_capacity,
123 const Dtype& key_dtype,
124 const SizeVector& key_element_shape,
125 const std::vector<Dtype>& value_dtypes,
126 const std::vector<SizeVector>& value_element_shapes,
127 const Device& device,
128 const HashBackendType& backend);
129
130std::shared_ptr<DeviceHashBackend> CreateCUDAHashBackend(
131 int64_t init_capacity,
132 const Dtype& key_dtype,
133 const SizeVector& key_element_shape,
134 const std::vector<Dtype>& value_dtypes,
135 const std::vector<SizeVector>& value_element_shapes,
136 const Device& device,
137 const HashBackendType& backend);
138
139#if defined(BUILD_SYCL_MODULE)
141std::shared_ptr<DeviceHashBackend> CreateSYCLHashBackend(
142 int64_t init_capacity,
143 const Dtype& key_dtype,
144 const SizeVector& key_element_shape,
145 const std::vector<Dtype>& value_dtypes,
146 const std::vector<SizeVector>& value_element_shapes,
147 const Device& device,
148 const HashBackendType& backend);
149#endif
150
151} // namespace core
152} // namespace open3d
Common CUDA utilities.
Definition DeviceHashBackend.h:20
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:77
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:80
virtual int64_t GetNonEmptyCount() const
Get the number of non-empty slots (occupied + deleted/tombstones).
Definition DeviceHashBackend.h:68
std::vector< int64_t > value_dsizes_
Definition DeviceHashBackend.h:101
std::shared_ptr< HashBackendBuffer > buffer_
Definition DeviceHashBackend.h:105
Device device_
Definition DeviceHashBackend.h:103
int64_t key_dsize_
Definition DeviceHashBackend.h:100
Tensor GetValueBuffer(size_t i=0)
Get the i-th value buffer that store an actual value array.
Definition DeviceHashBackend.h:92
Tensor GetKeyBuffer()
Get the key buffer that stores actual keys.
Definition DeviceHashBackend.h:86
virtual void Reserve(int64_t capacity)=0
std::vector< Tensor > GetValueBuffers()
Get the value buffers that store actual array of values.
Definition DeviceHashBackend.h:89
int64_t capacity_
Definition DeviceHashBackend.h:98
virtual ~DeviceHashBackend()
Definition DeviceHashBackend.h:30
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:22
virtual int64_t Size() const =0
Get the size (number of valid entries) of the hash map.
Definition Device.h:18
Definition Dtype.h:20
Definition SizeVector.h:69
Definition Tensor.h:32
int count
Definition FilePCD.cpp:43
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:16
uint32_t buf_index_t
Definition HashBackendBuffer.h:49
std::shared_ptr< DeviceHashBackend > CreateSYCLHashBackend(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 CreateSYCLHashBackend.cpp:20
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:18
HashBackendType
Definition HashMap.h:20
Definition PinholeCameraIntrinsic.cpp:16