Skip to content

Commit a1762eb

Browse files
miurshwep21
andauthored
fix(lidar_centerpoint,image_projection_based_fusion): add guard to avoid exceeding max voxel size (#1065)
fix(lidar_centerpoint,image_projection_based_fusion): add guard to avoid exceeding max voxel size (autowarefoundation#5824) Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com>
1 parent 962a81e commit a1762eb

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

perception/image_projection_based_fusion/include/image_projection_based_fusion/pointpainting_fusion/preprocess_kernel.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ cudaError_t generateVoxels_random_launch(
2727
cudaStream_t stream);
2828

2929
cudaError_t generateBaseFeatures_launch(
30-
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, unsigned int * pillar_num,
31-
float * voxel_features, float * voxel_num, int * voxel_idxs, cudaStream_t stream);
30+
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, int max_voxel_size,
31+
unsigned int * pillar_num, float * voxel_features, float * voxel_num, int * voxel_idxs,
32+
cudaStream_t stream);
3233

3334
cudaError_t generateFeatures_launch(
3435
const float * voxel_features, const float * voxel_num_points, const int * coords,

perception/image_projection_based_fusion/src/pointpainting_fusion/pointpainting_trt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ bool PointPaintingTRT::preprocess(
6969

7070
CHECK_CUDA_ERROR(image_projection_based_fusion::generateBaseFeatures_launch(
7171
mask_d_.get(), voxels_buffer_d_.get(), config_.grid_size_y_, config_.grid_size_x_,
72-
num_voxels_d_.get(), voxels_d_.get(), num_points_per_voxel_d_.get(), coordinates_d_.get(),
73-
stream_));
72+
config_.max_voxel_size_, num_voxels_d_.get(), voxels_d_.get(), num_points_per_voxel_d_.get(),
73+
coordinates_d_.get(), stream_));
7474

7575
CHECK_CUDA_ERROR(image_projection_based_fusion::generateFeatures_launch(
7676
voxels_d_.get(), num_points_per_voxel_d_.get(), coordinates_d_.get(), num_voxels_d_.get(),

perception/image_projection_based_fusion/src/pointpainting_fusion/preprocess_kernel.cu

+8-5
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ cudaError_t generateVoxels_random_launch(
105105
}
106106

107107
__global__ void generateBaseFeatures_kernel(
108-
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, unsigned int * pillar_num,
109-
float * voxel_features, float * voxel_num, int * voxel_idxs)
108+
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, int max_voxel_size,
109+
unsigned int * pillar_num, float * voxel_features, float * voxel_num, int * voxel_idxs)
110110
{
111111
unsigned int voxel_idx = blockIdx.x * blockDim.x + threadIdx.x;
112112
unsigned int voxel_idy = blockIdx.y * blockDim.y + threadIdx.y;
@@ -120,6 +120,7 @@ __global__ void generateBaseFeatures_kernel(
120120

121121
unsigned int current_pillarId = 0;
122122
current_pillarId = atomicAdd(pillar_num, 1);
123+
if (current_pillarId > max_voxel_size - 1) return;
123124

124125
voxel_num[current_pillarId] = count;
125126

@@ -140,15 +141,17 @@ __global__ void generateBaseFeatures_kernel(
140141

141142
// create 4 channels
142143
cudaError_t generateBaseFeatures_launch(
143-
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, unsigned int * pillar_num,
144-
float * voxel_features, float * voxel_num, int * voxel_idxs, cudaStream_t stream)
144+
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, int max_voxel_size,
145+
unsigned int * pillar_num, float * voxel_features, float * voxel_num, int * voxel_idxs,
146+
cudaStream_t stream)
145147
{
146148
dim3 threads = {32, 32};
147149
dim3 blocks = {
148150
(grid_x_size + threads.x - 1) / threads.x, (grid_y_size + threads.y - 1) / threads.y};
149151

150152
generateBaseFeatures_kernel<<<blocks, threads, 0, stream>>>(
151-
mask, voxels, grid_y_size, grid_x_size, pillar_num, voxel_features, voxel_num, voxel_idxs);
153+
mask, voxels, grid_y_size, grid_x_size, max_voxel_size, pillar_num, voxel_features, voxel_num,
154+
voxel_idxs);
152155
cudaError_t err = cudaGetLastError();
153156
return err;
154157
}

perception/lidar_centerpoint/include/lidar_centerpoint/preprocess/preprocess_kernel.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ cudaError_t generateVoxels_random_launch(
2727
cudaStream_t stream);
2828

2929
cudaError_t generateBaseFeatures_launch(
30-
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, unsigned int * pillar_num,
31-
float * voxel_features, float * voxel_num, int * voxel_idxs, cudaStream_t stream);
30+
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, int max_voxel_size,
31+
unsigned int * pillar_num, float * voxel_features, float * voxel_num, int * voxel_idxs,
32+
cudaStream_t stream);
3233

3334
cudaError_t generateFeatures_launch(
3435
const float * voxel_features, const float * voxel_num_points, const int * coords,

perception/lidar_centerpoint/lib/centerpoint_trt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ bool CenterPointTRT::preprocess(
156156

157157
CHECK_CUDA_ERROR(generateBaseFeatures_launch(
158158
mask_d_.get(), voxels_buffer_d_.get(), config_.grid_size_y_, config_.grid_size_x_,
159-
num_voxels_d_.get(), voxels_d_.get(), num_points_per_voxel_d_.get(), coordinates_d_.get(),
160-
stream_));
159+
config_.max_voxel_size_, num_voxels_d_.get(), voxels_d_.get(), num_points_per_voxel_d_.get(),
160+
coordinates_d_.get(), stream_));
161161

162162
CHECK_CUDA_ERROR(generateFeatures_launch(
163163
voxels_d_.get(), num_points_per_voxel_d_.get(), coordinates_d_.get(), num_voxels_d_.get(),

perception/lidar_centerpoint/lib/preprocess/preprocess_kernel.cu

+8-5
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ cudaError_t generateVoxels_random_launch(
8787
}
8888

8989
__global__ void generateBaseFeatures_kernel(
90-
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, unsigned int * pillar_num,
91-
float * voxel_features, float * voxel_num, int * voxel_idxs)
90+
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, int max_voxel_size,
91+
unsigned int * pillar_num, float * voxel_features, float * voxel_num, int * voxel_idxs)
9292
{
9393
unsigned int voxel_idx = blockIdx.x * blockDim.x + threadIdx.x;
9494
unsigned int voxel_idy = blockIdx.y * blockDim.y + threadIdx.y;
@@ -102,6 +102,7 @@ __global__ void generateBaseFeatures_kernel(
102102

103103
unsigned int current_pillarId = 0;
104104
current_pillarId = atomicAdd(pillar_num, 1);
105+
if (current_pillarId > max_voxel_size - 1) return;
105106

106107
voxel_num[current_pillarId] = count;
107108

@@ -120,15 +121,17 @@ __global__ void generateBaseFeatures_kernel(
120121

121122
// create 4 channels
122123
cudaError_t generateBaseFeatures_launch(
123-
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, unsigned int * pillar_num,
124-
float * voxel_features, float * voxel_num, int * voxel_idxs, cudaStream_t stream)
124+
unsigned int * mask, float * voxels, int grid_y_size, int grid_x_size, int max_voxel_size,
125+
unsigned int * pillar_num, float * voxel_features, float * voxel_num, int * voxel_idxs,
126+
cudaStream_t stream)
125127
{
126128
dim3 threads = {32, 32};
127129
dim3 blocks = {
128130
(grid_x_size + threads.x - 1) / threads.x, (grid_y_size + threads.y - 1) / threads.y};
129131

130132
generateBaseFeatures_kernel<<<blocks, threads, 0, stream>>>(
131-
mask, voxels, grid_y_size, grid_x_size, pillar_num, voxel_features, voxel_num, voxel_idxs);
133+
mask, voxels, grid_y_size, grid_x_size, max_voxel_size, pillar_num, voxel_features, voxel_num,
134+
voxel_idxs);
132135
cudaError_t err = cudaGetLastError();
133136
return err;
134137
}

0 commit comments

Comments
 (0)