Open3D (C++ API)  0.11.0
TemplateHashmap.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 // Low level hashmap interface for advanced usages who wish to modify hash
30 // function and/or equal function.
31 // Users must create a .cu file and compile with
32 // nvcc to use customized GPU hashmap.
33 //
34 // APIs are available in HashmapBase.h.
35 // Include path: TemplatedHashmap.h -> HashmapCPU.hpp -> HashmapBase.h
36 // | ^
37 // |--> HashmapCUDA.cuh --|
38 // (CUDA code)
39 //
40 // .cpp targets only include CPU part that can be compiled by non-nvcc
41 // compilers even if BUILD_CUDA_MODULE is enabled.
42 // .cu targets include both.
43 
45 
46 #if defined(BUILD_CUDA_MODULE) && defined(__CUDACC__)
48 #endif
49 
50 #include <unordered_map>
51 
52 namespace open3d {
53 namespace core {
54 
55 template <typename Hash, typename KeyEq>
56 std::shared_ptr<DeviceHashmap<Hash, KeyEq>> CreateTemplateDeviceHashmap(
57  size_t init_buckets,
58  size_t init_capacity,
59  size_t dsize_key,
60  size_t dsize_value,
61  const Device &device) {
62  if (device.GetType() == Device::DeviceType::CPU) {
63  return CreateTemplateCPUHashmap<Hash, KeyEq>(
64  init_buckets, init_capacity, dsize_key, dsize_value, device);
65  }
66 #if defined(BUILD_CUDA_MODULE) && defined(__CUDACC__)
67  else if (device.GetType() == Device::DeviceType::CUDA) {
68  return CreateTemplateCUDAHashmap<Hash, KeyEq>(
69  init_buckets, init_capacity, dsize_key, dsize_value, device);
70  }
71 #endif
72  else {
73  utility::LogError("[CreateTemplateHashmap]: Unimplemented device");
74  }
75 }
76 } // namespace core
77 } // namespace open3d
void LogError(const char *format, const Args &... args)
Definition: Console.h:176
std::shared_ptr< DeviceHashmap< Hash, KeyEq > > CreateTemplateDeviceHashmap(size_t init_buckets, size_t init_capacity, size_t dsize_key, size_t dsize_value, const Device &device)
Definition: TemplateHashmap.h:56
DeviceType GetType() const
Definition: Device.h:89
Definition: Device.h:39
Definition: PinholeCameraIntrinsic.cpp:35