ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
CreateCPUHashBackend.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
11 
12 namespace cloudViewer {
13 namespace core {
14 
16 std::shared_ptr<DeviceHashBackend> CreateCPUHashBackend(
17  int64_t init_capacity,
18  const Dtype& key_dtype,
19  const SizeVector& key_element_shape,
20  const std::vector<Dtype>& value_dtypes,
21  const std::vector<SizeVector>& value_element_shapes,
22  const Device& device,
23  const HashBackendType& backend) {
24  if (backend != HashBackendType::Default &&
25  backend != HashBackendType::TBB) {
26  utility::LogError("Unsupported backend for CPU hashmap.");
27  }
28 
29  int64_t dim = key_element_shape.NumElements();
30 
31  int64_t key_dsize = dim * key_dtype.ByteSize();
32 
33  // TODO: size check
34  std::vector<int64_t> value_dsizes;
35  for (size_t i = 0; i < value_dtypes.size(); ++i) {
36  int64_t dsize_value = value_element_shapes[i].NumElements() *
37  value_dtypes[i].ByteSize();
38  value_dsizes.push_back(dsize_value);
39  }
40 
41  std::shared_ptr<DeviceHashBackend> device_hashmap_ptr;
42  DISPATCH_DTYPE_AND_DIM_TO_TEMPLATE(key_dtype, dim, [&] {
43  device_hashmap_ptr =
44  std::make_shared<TBBHashBackend<key_t, hash_t, eq_t>>(
45  init_capacity, key_dsize, value_dsizes, device);
46  });
47  return device_hashmap_ptr;
48 }
49 
50 } // namespace core
51 } // namespace cloudViewer
int64_t ByteSize() const
Definition: Dtype.h:59
#define LogError(...)
Definition: Logging.h:60
#define DISPATCH_DTYPE_AND_DIM_TO_TEMPLATE(DTYPE, DIM,...)
Definition: Dispatch.h:47
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.
Generic file read and write utility for python interface.