[Fix] Fix bugs in Voxelization op (#1746)

* Fix bugs in  Voxelization op

* fix comments

* fix lint

* add comments
pull/1790/head
Wenhao Wu 2022-03-07 21:08:36 +08:00 committed by GitHub
parent 09b64a60b0
commit 76e870f17c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 7 deletions

View File

@ -26,13 +26,22 @@ void dynamic_voxelize_forward_cpu_kernel(
coor[ndim_minus_1 - j] = c;
}
if (failed)
memset(&coors[i][0], -1, NDim * sizeof(T_int));
else
memcpy(&coors[i][0], &coor[0], NDim * sizeof(T_int));
// memcpy and memset will cause problem because of the memory distribution
// discontinuity of TensorAccessor, so here using loops to replace memcpy
// or memset
if (failed) {
for (int k = 0; k < NDim; ++k) {
coors[i][k] = -1;
}
} else {
for (int k = 0; k < NDim; ++k) {
coors[i][k] = coor[k];
}
}
}
delete[] coor;
return;
}
template <typename T, typename T_int>
@ -72,14 +81,21 @@ void hard_voxelize_forward_cpu_kernel(
voxel_num += 1;
coor_to_voxelidx[coor[i][0]][coor[i][1]][coor[i][2]] = voxelidx;
memcpy(&coors[voxelidx][0], &coor[i][0], NDim * sizeof(T_int));
// memcpy will cause problem because of the memory distribution
// discontinuity of TensorAccessor, so here using loops to replace memcpy
for (int k = 0; k < NDim; ++k) {
coors[voxelidx][k] = coor[i][k];
}
}
// put points into voxel
num = num_points_per_voxel[voxelidx];
if (max_points == -1 || num < max_points) {
memcpy(&voxels[voxelidx][num][0], &points[i][0],
num_features * sizeof(T));
// memcpy will cause problem because of the memory distribution
// discontinuity of TensorAccessor, so here using loops to replace memcpy
for (int k = 0; k < num_features; ++k) {
voxels[voxelidx][num][k] = points[i][k];
}
num_points_per_voxel[voxelidx] += 1;
}
}