[Potential Performance Improvement] Hard voxelization could have a much faster implementation (at the cost of determinism).

Author: zhanggefanCreated Aug 30, 2021Updated Aug 22, 2026
Labelsenhancementcommunity discussion

Hi,

I noticed that the Cuda code of hard voxelization wraps some kernel code that is computationally inefficient.

  1. single-thread kernel launch https://github.com/open-mmlab/mmdetection3d/blob/d1123084973dd3a910760e77c499afad76d16cea/mmdet3d/ops/voxel/src/voxelization_cuda.cu#L276

  2. O(n^2) part -- loop in kernel. https://github.com/open-mmlab/mmdetection3d/blob/d1123084973dd3a910760e77c499afad76d16cea/mmdet3d/ops/voxel/src/voxelization_cuda.cu#L156

From my experience (By pr #318), voxelization can be viewed as a sparse hashing problem. Getting the sparse index can be solved by torch.unique at the complexity of O(nlogn), while the hash-reduce part can be implemented by atomicMax at the complexity of O(n). Just like the implementation in Apollo: https://github.com/ApolloAuto/apollo/blob/master/modules/perception/lidar/lib/detector/point_pillars_detection/preprocess_points_cuda.cu

From my observation, this part is the performance bottleneck for many lightweight detectors on many datasets. For example the CenterPoint with pillar encoder on NuScenes dataset: https://github.com/open-mmlab/mmdetection3d/blob/d1123084973dd3a910760e77c499afad76d16cea/configs/centerpoint/centerpoint_02pillar_second_secfpn_4x8_cyclic_20e_nus.py I managed to reimplement this part and it can reduce the training iteration time by more than a half, a huge improvement.

I also understand that your implementation is designed for determinism. Because hard voxelization involves points/voxels discarding, the ordering between points matters so that we could guarantee that always to discard the same portion of input points. In your implementation, the former points/voxels take precedence over the latter ones when discard points, thus your implementation is deterministic.

My reimplementation is non-deterministic because the hash-reduce kernel may be executed in any order, with no ordering between input points at runtime. Different runs for the same data can result in different portions of points being discarded.

If you think the performance gain is worth more than keeping the determinism, then my reimplementation is ready for PR.

Looking forward to your reply!

Source: open-mmlab/mmdetection3d