Open3D (C++ API)  0.19.0
Loading...
Searching...
No Matches
Dispatch.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/Dtype.h"
15
16#define INSTANTIATE_TYPES(DTYPE, DIM) \
17 using key_t = utility::MiniVec<DTYPE, DIM>; \
18 using hash_t = utility::MiniVecHash<DTYPE, DIM>; \
19 using eq_t = utility::MiniVecEq<DTYPE, DIM>;
20
21#define DIM_SWITCHER(DTYPE, DIM, ...) \
22 if (DIM == 1) { \
23 INSTANTIATE_TYPES(DTYPE, 1) \
24 return __VA_ARGS__(); \
25 } else if (DIM == 2) { \
26 INSTANTIATE_TYPES(DTYPE, 2) \
27 return __VA_ARGS__(); \
28 } else if (DIM == 3) { \
29 INSTANTIATE_TYPES(DTYPE, 3) \
30 return __VA_ARGS__(); \
31 } else if (DIM == 4) { \
32 INSTANTIATE_TYPES(DTYPE, 4) \
33 return __VA_ARGS__(); \
34 } else if (DIM == 5) { \
35 INSTANTIATE_TYPES(DTYPE, 5) \
36 return __VA_ARGS__(); \
37 } else if (DIM == 6) { \
38 INSTANTIATE_TYPES(DTYPE, 6) \
39 return __VA_ARGS__(); \
40 } else { \
41 utility::LogError( \
42 "Unsupported dim {}, please modify {} and compile from " \
43 "source", \
44 DIM, __FILE__); \
45 }
46
47// TODO: dispatch more combinations.
48#define DISPATCH_DTYPE_AND_DIM_TO_TEMPLATE(DTYPE, DIM, ...) \
49 [&] { \
50 if (DTYPE == open3d::core::Int64) { \
51 DIM_SWITCHER(int64_t, DIM, __VA_ARGS__) \
52 } else if (DTYPE == open3d::core::Int32) { \
53 DIM_SWITCHER(int, DIM, __VA_ARGS__) \
54 } else if (DTYPE == open3d::core::Int16) { \
55 DIM_SWITCHER(short, DIM, __VA_ARGS__) \
56 } else { \
57 utility::LogError( \
58 "Unsupported dtype {}, please use integer types (Int64, " \
59 "Int32, Int16).", \
60 DTYPE.ToString()); \
61 } \
62 }()
63
64namespace open3d {
65namespace utility {
66
67template <typename T, int N>
69public:
70 OPEN3D_HOST_DEVICE uint64_t operator()(const MiniVec<T, N>& key) const {
71 uint64_t hash = UINT64_C(14695981039346656037);
72#if defined(__CUDA_ARCH__)
73#pragma unroll
74#endif
75 for (int i = 0; i < N; ++i) {
76 hash ^= static_cast<uint64_t>(key[i]);
77 hash *= UINT64_C(1099511628211);
78 }
79 return hash;
80 }
81};
82
83template <typename T, int N>
84struct MiniVecEq {
85public:
87 const MiniVec<T, N>& rhs) const {
88 bool is_equal = true;
89#if defined(__CUDA_ARCH__)
90#pragma unroll
91#endif
92 for (int i = 0; i < N; ++i) {
93 is_equal = is_equal && (lhs[i] == rhs[i]);
94 }
95 return is_equal;
96 }
97};
98
99} // namespace utility
100} // namespace open3d
Vectorized trivial-object copy block sizes (CUDA and SYCL).
Common CUDA utilities.
#define OPEN3D_HOST_DEVICE
Definition CUDAUtils.h:43
Definition PinholeCameraIntrinsic.cpp:16
Definition Dispatch.h:84
OPEN3D_HOST_DEVICE bool operator()(const MiniVec< T, N > &lhs, const MiniVec< T, N > &rhs) const
Definition Dispatch.h:86
Definition Dispatch.h:68
OPEN3D_HOST_DEVICE uint64_t operator()(const MiniVec< T, N > &key) const
Definition Dispatch.h:70
Definition MiniVec.h:24