Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
BlockCopyDispatch.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2026 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
14
15#pragma once
16
17#include <cstdint>
18
19#ifdef SYCL_LANGUAGE_VERSION
20#include <sycl/sycl.hpp>
21#endif
22
23namespace open3d {
24namespace core {
25
26// Vectorized trivial-object copy block sizes (bytes). Used for: HashMap SoA
27// value buffers (VoxelBlockGrid blocks, etc.), Dtype::Object advanced index
28// get/set, and non-contiguous SYCL tensor copy of object dtypes.
29inline constexpr int64_t kBlockCopyDivisors[] = {64, 16, 12, 4, 1};
30
32inline int64_t GetLargestAlignedObjectBlockSize(int64_t object_byte_size) {
33 for (int64_t divisor : kBlockCopyDivisors) {
34 if (object_byte_size % divisor == 0) {
35 return divisor;
36 }
37 }
38 return 1;
39}
40
41} // namespace core
42} // namespace open3d
43
44#ifdef __CUDACC__
45#include <cuda_runtime.h>
46
47// Reinterpret hash maps' void* value arrays as CUDA primitive type arrays to
48// avoid slow memcpy or byte-by-byte copy in kernels. Not used on CPU (memcpy is
49// fast enough). BlockCopy64 is at namespace scope because nvcc disallows
50// types with no linkage as template arguments for __global__ instantiations.
51struct BlockCopy64 {
52 int4 v[4];
53};
54
56#define DISPATCH_DIVISOR_SIZE_TO_BLOCK_T(DIVISOR, ...) \
57 [&] { \
58 if (DIVISOR == 64) { \
59 using block_t = BlockCopy64; \
60 static_assert(sizeof(block_t) == 64, "block_t size mismatch"); \
61 return __VA_ARGS__(); \
62 } else if (DIVISOR == 16) { \
63 using block_t = int4; \
64 static_assert(sizeof(block_t) == 16, "block_t size mismatch"); \
65 return __VA_ARGS__(); \
66 } else if (DIVISOR == 12) { \
67 using block_t = int3; \
68 static_assert(sizeof(block_t) == 12, "block_t size mismatch"); \
69 return __VA_ARGS__(); \
70 } else if (DIVISOR == 4) { \
71 using block_t = int; \
72 static_assert(sizeof(block_t) == 4, "block_t size mismatch"); \
73 return __VA_ARGS__(); \
74 } else { \
75 using block_t = uint8_t; \
76 static_assert(sizeof(block_t) == 1, "block_t size mismatch"); \
77 return __VA_ARGS__(); \
78 } \
79 }()
80#endif // __CUDACC__
81
82#ifdef SYCL_LANGUAGE_VERSION
83
84// sycl::vec<uint32_t, 3> is NOT 12 bytes: the SYCL spec requires 3-element
85// vectors to have the same size/alignment as the 4-element vector (16 bytes,
86// 16-byte aligned), so it cannot be used for the 12-byte divisor. Use a
87// plain POD struct instead, which packs to exactly 12 bytes.
88struct BlockCopy12 {
89 uint32_t v[3];
90};
91
97#define DISPATCH_DIVISOR_SIZE_TO_BLOCK_T_SYCL(DIVISOR, ...) \
98 [&] { \
99 if (DIVISOR == 64) { \
100 using block_t = sycl::vec<uint32_t, 16>; \
101 static_assert(sizeof(block_t) == 64, "block_t size mismatch"); \
102 return __VA_ARGS__(); \
103 } else if (DIVISOR == 16) { \
104 using block_t = sycl::vec<uint32_t, 4>; \
105 static_assert(sizeof(block_t) == 16, "block_t size mismatch"); \
106 return __VA_ARGS__(); \
107 } else if (DIVISOR == 12) { \
108 using block_t = BlockCopy12; \
109 static_assert(sizeof(block_t) == 12, "block_t size mismatch"); \
110 return __VA_ARGS__(); \
111 } else if (DIVISOR == 4) { \
112 using block_t = uint32_t; \
113 static_assert(sizeof(block_t) == 4, "block_t size mismatch"); \
114 return __VA_ARGS__(); \
115 } else { \
116 using block_t = uint8_t; \
117 static_assert(sizeof(block_t) == 1, "block_t size mismatch"); \
118 return __VA_ARGS__(); \
119 } \
120 }()
121
122#endif // SYCL_LANGUAGE_VERSION
constexpr int64_t kBlockCopyDivisors[]
Definition BlockCopyDispatch.h:29
int64_t GetLargestAlignedObjectBlockSize(int64_t object_byte_size)
Largest entry in kBlockCopyDivisors that divides object_byte_size.
Definition BlockCopyDispatch.h:32
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle uint32_t
Definition K4aPlugin.cpp:548
Definition PinholeCameraIntrinsic.cpp:16