point_cloud_fusion v1.6.0
Loading...
Searching...
No Matches
point_cloud_fusion_cuda.hpp
Go to the documentation of this file.
1// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#ifdef ENABLE_CUDA
7
8#include <cstddef>
9#include <cstdint>
10#include <vector>
11
13
14namespace point_cloud_fusion {
15namespace cuda {
16
17constexpr int kMaxCalibrationKnots = 65;
18
19struct CudaFieldCopy {
20 int src_offset;
21 int dst_offset;
22 int size;
23};
24
25// Metadata struct for device consumption
26struct CloudMetadata {
27 int num_points; // Actual number of points in this cloud
28 int num_samples; // Number of samples to take (for strided sampling)
29 float stride; // Stride for uniform sampling (>= 1.0)
30 int apply_transform; // bool as int for alignment
31 float rotation[9];
32 float translation[3];
33 int motion_compensation;
34 int time_offset;
35 unsigned int max_time_offset;
36 int64_t time_rebase_units;
37 float start_translation[3];
38 float end_translation[3];
39 float start_quaternion[4];
40 float end_quaternion[4];
41 ObjectMotion object_motion;
42 int calibration_source_offset;
43 int calibration_destination_offset;
44 int calibration_source_datatype;
45 int calibration_destination_datatype;
46 int calibration_knot_count;
47 float calibration_source[kMaxCalibrationKnots];
48 float calibration_target[kMaxCalibrationKnots];
49};
50
57class CudaTransformContext {
58 public:
59 CudaTransformContext();
60 ~CudaTransformContext();
61
62 // Disable copy/move
63 CudaTransformContext(const CudaTransformContext&) = delete;
64 CudaTransformContext& operator=(const CudaTransformContext&) = delete;
65
83 bool resetBatch(size_t total_max_points,
84 size_t max_single_cloud_points,
85 size_t input_point_step,
86 size_t output_point_step,
87 int src_x_offset,
88 int src_y_offset,
89 int src_z_offset,
90 int dst_x_offset,
91 int dst_y_offset,
92 int dst_z_offset,
93 int dst_time_offset,
94 const std::vector<CudaFieldCopy>& copy_plan,
95 float x_min,
96 float x_max,
97 float y_min,
98 float y_max,
99 float z_min,
100 float z_max,
101 bool range_enable);
102
116 bool addCloud(const uint8_t* input_data,
117 size_t num_points,
118 const float* rotation_matrix_host,
119 const float* translation_host,
120 bool apply_transform,
121 size_t slot_index,
122 int desired_points = 0,
123 bool motion_compensation = false,
124 int time_offset = -1,
125 unsigned int max_time_offset = 0,
126 int64_t time_rebase_units = 0,
127 const float* start_translation = nullptr,
128 const float* end_translation = nullptr,
129 const float* start_quaternion = nullptr,
130 const float* end_quaternion = nullptr,
131 int calibration_source_offset = -1,
132 int calibration_destination_offset = -1,
133 int calibration_source_datatype = 0,
134 int calibration_destination_datatype = 0,
135 int calibration_knot_count = 0,
136 const float* calibration_source = nullptr,
137 const float* calibration_target = nullptr,
138 const ObjectMotion& object_motion = ObjectMotion{});
139
147 bool getBatchOutput(std::vector<uint8_t>& output_data, size_t& valid_count);
148
149 private:
150 bool ensureInputCapacity(size_t num_points);
151 bool ensureOutputCapacity(size_t total_max_points, size_t point_step);
152 void cleanup();
153
154 // Device memory
155 uint8_t* d_input_points_;
156 uint8_t* d_accumulated_buffer_;
157 unsigned int* d_global_count_; // Atomic counter for total output
158 void* d_cloud_metadata_; // Device buffer for CloudMetadata
159 void* d_copy_plan_; // Device buffer for CudaFieldCopy
160
161 // Host pinned memory
162 unsigned int* h_global_count_pinned_;
163 void* h_cloud_metadata_pinned_; // Host pinned buffer for CloudMetadata
164
165 // CUDA resources
166 void* stream_; // cudaStream_t
167
168 size_t input_capacity_;
169 size_t output_capacity_;
170 size_t current_input_point_step_;
171 size_t current_output_point_step_;
172 size_t slot_size_points_; // fixed slot size in points (padding per cloud)
173 size_t num_slots_; // number of slots (usually number of input clouds)
174 size_t metadata_capacity_; // number of slots we can store metadata for
175 size_t copy_plan_capacity_;
176
177 int current_src_x_offset_;
178 int current_src_y_offset_;
179 int current_src_z_offset_;
180 int current_dst_x_offset_;
181 int current_dst_y_offset_;
182 int current_dst_z_offset_;
183 int current_dst_time_offset_;
184 float current_x_min_;
185 float current_x_max_;
186 float current_y_min_;
187 float current_y_max_;
188 float current_z_min_;
189 float current_z_max_;
190 bool current_range_enable_;
191 int num_copy_ops_;
192
193 // We keep a host vector of metadata to fill before upload
194 std::vector<CloudMetadata> host_metadata_;
195
196 // Stored input pointers for batch upload
197 struct InputCloudInfo {
198 const uint8_t* data;
199 size_t size_bytes;
200 size_t slot_index;
201 };
202 std::vector<InputCloudInfo> pending_inputs_;
203};
204
205} // namespace cuda
206} // namespace point_cloud_fusion
207
208#endif // ENABLE_CUDA
std::size_t point_step