point_cloud_fusion v1.4.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
12namespace point_cloud_fusion {
13namespace cuda {
14
15struct CudaFieldCopy {
16 int src_offset;
17 int dst_offset;
18 int size;
19};
20
21// Metadata struct for device consumption
22struct CloudMetadata {
23 int num_points; // Actual number of points in this cloud
24 int num_samples; // Number of samples to take (for strided sampling)
25 float stride; // Stride for uniform sampling (>= 1.0)
26 int apply_transform; // bool as int for alignment
27 float rotation[9];
28 float translation[3];
29 int pad; // alignment padding
30};
31
38class CudaTransformContext {
39 public:
40 CudaTransformContext();
41 ~CudaTransformContext();
42
43 // Disable copy/move
44 CudaTransformContext(const CudaTransformContext&) = delete;
45 CudaTransformContext& operator=(const CudaTransformContext&) = delete;
46
64 bool resetBatch(size_t total_max_points,
65 size_t max_single_cloud_points,
66 size_t input_point_step,
67 size_t output_point_step,
68 int src_x_offset,
69 int src_y_offset,
70 int src_z_offset,
71 int dst_x_offset,
72 int dst_y_offset,
73 int dst_z_offset,
74 const std::vector<CudaFieldCopy>& copy_plan,
75 float x_min,
76 float x_max,
77 float y_min,
78 float y_max,
79 float z_min,
80 float z_max,
81 bool range_enable);
82
96 bool addCloud(const uint8_t* input_data,
97 size_t num_points,
98 const float* rotation_matrix_host,
99 const float* translation_host,
100 bool apply_transform,
101 size_t slot_index,
102 int desired_points = 0);
103
111 bool getBatchOutput(std::vector<uint8_t>& output_data, size_t& valid_count);
112
113 private:
114 bool ensureInputCapacity(size_t num_points);
115 bool ensureOutputCapacity(size_t total_max_points, size_t point_step);
116 void cleanup();
117
118 // Device memory
119 uint8_t* d_input_points_;
120 uint8_t* d_accumulated_buffer_;
121 unsigned int* d_global_count_; // Atomic counter for total output
122 void* d_cloud_metadata_; // Device buffer for CloudMetadata
123 void* d_copy_plan_; // Device buffer for CudaFieldCopy
124
125 // Host pinned memory
126 unsigned int* h_global_count_pinned_;
127 void* h_cloud_metadata_pinned_; // Host pinned buffer for CloudMetadata
128
129 // CUDA resources
130 void* stream_; // cudaStream_t
131
132 size_t input_capacity_;
133 size_t output_capacity_;
134 size_t current_input_point_step_;
135 size_t current_output_point_step_;
136 size_t slot_size_points_; // fixed slot size in points (padding per cloud)
137 size_t num_slots_; // number of slots (usually number of input clouds)
138 size_t metadata_capacity_; // number of slots we can store metadata for
139 size_t copy_plan_capacity_;
140
141 int current_src_x_offset_;
142 int current_src_y_offset_;
143 int current_src_z_offset_;
144 int current_dst_x_offset_;
145 int current_dst_y_offset_;
146 int current_dst_z_offset_;
147 float current_x_min_;
148 float current_x_max_;
149 float current_y_min_;
150 float current_y_max_;
151 float current_z_min_;
152 float current_z_max_;
153 bool current_range_enable_;
154 int num_copy_ops_;
155
156 // We keep a host vector of metadata to fill before upload
157 std::vector<CloudMetadata> host_metadata_;
158
159 // Stored input pointers for batch upload
160 struct InputCloudInfo {
161 const uint8_t* data;
162 size_t size_bytes;
163 size_t slot_index;
164 };
165 std::vector<InputCloudInfo> pending_inputs_;
166};
167
168} // namespace cuda
169} // namespace point_cloud_fusion
170
171#endif // ENABLE_CUDA