isl-org / Open3D

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

CUDA runtime error when running extract_triangle_mesh() from o3d.t.geometry.VoxelBlockGrid() #4824

Open dalnoguer opened 2 years ago

dalnoguer commented 2 years ago

Checklist

My Question

Hello,

Thanks for your great work :)

I am running into the following error when extracting a triangle mesh from a VoxelBlockGrid. Integrating each pair color/depth works fine, but when I try to extract the triangle mesh I get the following error:

    mesh = volume.extract_triangle_mesh()
RuntimeError: [Open3D Error] (void open3d::core::__OPEN3D_CUDA_CHECK(cudaError_t, const char*, int)) /root/Open3D/cpp/open3d/core/CUDAUtils.cpp:301: /root/Open3D/cpp/open3d/core/MemoryManagerCUDA.cpp:91 CUDA runtime error: an illegal memory access was encountered

Additionally, if I try to save the voxelblockgrid and load it again, I get a bunch of index out of bounds errors.

Here is the piece of code I used:

volume = o3d.t.geometry.VoxelBlockGrid(
    attr_names=("tsdf", "weight", "color"),
    attr_dtypes=(o3c.float32, o3c.float32, o3c.float32),
    attr_channels=((1), (1), (3)),
    voxel_size=3.0 / 512,
    block_resolution=16,
    block_count=50000,
    device=o3d.core.Device("CUDA:0"),
)

for i in tqdm.tqdm(range(len(rgbd_frames))):
    color = o3d.t.io.read_image(str(image_dir.joinpath(rgbd_frames[i]))).to(
        o3d.core.Device("CUDA:0")
    )
    depth = o3d.t.io.read_image(str(depth_dir.joinpath(rgbd_frames[i]))).to(
        o3d.core.Device("CUDA:0")
    )

    intrinsics = o3d.core.Tensor(
        camera_intrinsics[recording_id].intrinsic_matrix,
    )
    extrinsics = o3d.core.Tensor(
        np.linalg.inv(camera.parameters[i].extrinsic),
    )
    frustum_block_coords = volume.compute_unique_block_coordinates(
        depth, intrinsics, extrinsics, depth_max=self.depth_trunc
    )

    volume.integrate(
        frustum_block_coords,
        depth,
        color,
        intrinsics,
        extrinsics,
        depth_max=self.depth_trunc,
    )

mesh = volume.extract_triangle_mesh()

What am I missing? I checked if the gpu was full but only 8/16 GB were being used.

Thanks!

theNded commented 2 years ago

Does extract_point_cloud work? Current extract_triangle_mesh is a bit expensive and requires a lot of additional memory. I will have to rewrite it someday...

ozgucbertug commented 2 years ago

@theNded I can confirm that on my configuration extract_point_cloud works. I'm having the same problem on my RTX 3070 laptop however it seems to be ok on my desktop with RTX 2070 Super. They both have 8GB RAM and I'm running the same scene on both devices and the only difference is that my open3d version on my desktop is open3d-0.13.0+4dd197ce2 vs open3d-0.15.2+97960f23 on my laptop. I haven't had a chance to build 0.13 on my laptop yet and will make sure to update here once I test it.

small-zeng commented 3 months ago

Does extract_point_cloud work? Current extract_triangle_mesh is a bit expensive and requires a lot of additional memory. I will have to rewrite it someday...

extract_triangle_mesh

After each call to extract_triangle_mesh, the GPU memory is not released. Is there any solution to this issue?