isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.41k stars 2.3k forks source link

Use voxel_down_sampel on GPU? #5519

Open tanzeyy opened 2 years ago

tanzeyy commented 2 years ago

Checklist

My Question

Seems like voxel_down_sample pybind implementation sets the backend to Default, is it possible to use StdGPU?

https://github.com/isl-org/Open3D/blob/6805e7413df0588c9bbcfaad67e18ad2603dca45/cpp/pybind/t/geometry/pointcloud.cpp#L198

yuecideng commented 2 years ago

Hi, the stdgpu is the default backend on CUDA. please see the code for reference.

soccercoder-21 commented 2 years ago

@yuecideng How can I ensure that the GPU is actually performing the voxel down sample? I am running this and my GPU is not being utilized at all.

@tanzeyy Were you able to resolve this?

yuecideng commented 2 years ago

You should create your point cloud on CUDA device, then the voxel down sample will be performed on GPU automatically. @mslopezg

soccercoder-21 commented 2 years ago

@yuecideng I currently I load it in like this: open3d.io.read_point_cloud(filename)

Do I need to be using a special flag to ensure that it is created on the CUDA device, or a particular build? I am on the 0.15.1 release, working on Python 3.8.10

yuecideng commented 2 years ago

First, you should make sure you have open3d with CUDA enabled:

import open3d as o3d
print(o3d.core.cuda.is_available())

Then you should use open3d.t.io.read_point_cloud to read point cloud, since only the tensor based PointCloud can support CUDA backend. Finally you should copy your point cloud on GPU, because the point cloud read from io is always on CPU:

pcd_cu = pcd.cuda()
soccercoder-21 commented 2 years ago

@yuecideng [Open3D DEBUG] Format auto File assets/pointcloud/pointcloud.ply [Open3D DEBUG] Read t::geometry::PointCloud with following attributes: [Open3D DEBUG] confidence [shape: {112140632, 1}, stride: {1, 1}, Float32] [Open3D DEBUG] reflectance [shape: {112140632, 1}, stride: {1, 1}, UInt8] [Open3D DEBUG] distance [shape: {112140632, 1}, stride: {1, 1}, Float32] [Open3D DEBUG] timestamp [shape: {112140632, 1}, stride: {1, 1}, Float64] [Open3D DEBUG] hitCount [shape: {112140632, 1}, stride: {1, 1}, Int32] [Open3D DEBUG] colors [shape: {112140632, 3}, stride: {3, 1}, UInt8] [Open3D DEBUG] normals [shape: {112140632, 3}, stride: {3, 1}, Float32] [Open3D DEBUG] positions [shape: {112140632, 3}, stride: {3, 1}, Float32] [2022-10-05 18:21:33,412] [INFO] {RasterizationEngine.py:43} - Cleaning PointCloud... [2022-10-05 18:21:33,412] [INFO] {PointCloud.py:64} - Cleaning: Down Sampling Pointcloud... Traceback (most recent call last): File "/home/ubuntu/data/wu-cv-toolkit/adhoc/test_ec2.py", line 51, in <module> config = EC2Engine.run() File "/home/ubuntu/data/wu-cv-toolkit/src/pipelines/EC2Pipeline.py", line 115, in run rasterEngine.rasterize() File "/home/ubuntu/data/wu-cv-toolkit/src/engines/RasterizationEngine.py", line 44, in rasterize self.pointcloud.clean() File "/home/ubuntu/data/wu-cv-toolkit/src/classes/PointCloud.py", line 65, in clean voxel_down_pcd = pcd.voxel_down_sample(voxel_size) RuntimeError: [Open3D Error] (void open3d::core::__OPEN3D_CUDA_CHECK(cudaError_t, const char*, int)) /root/Open3D/cpp/open3d/core/CUDAUtils.cpp:309: /root/Open3D/cpp/open3d/core/MemoryManagerCUDA.cpp:45 CUDA runtime error: out of memory

This is my GPU. image

I finally have the GPU working but it is unable to downsample this point cloud due to a memory error. Is it a requirement for the pointcloud to be entirely on the GPU for it to proceed?

If not, how can I progressively compute downsampling with my GPU.

yuecideng commented 2 years ago

I notice that your point cloud is very large... There are two possible workarounds:

  1. Before voxel dowm sample, use uniform down sample first to reduce the size of the point cloud if your point cloud is dense (a voxel may contain more than 1000 point).
  2. Partition your point cloud into several fragments and process these fragments one by one then stack them finally.
tanzeyy commented 2 years ago

@yuecideng How can I ensure that the GPU is actually performing the voxel down sample? I am running this and my GPU is not being utilized at all.

@tanzeyy Were you able to resolve this?

No, I didn't find a way to use voxel down sampling on GPU. Actually, I inspect the source code and rewrite the algorithm, the idea is using int32 instead of float64, therefore I can do fast hashing with integer division. The final Python program (implemented with Pandas) is twice as fast as the Open3d implementation.