facebookresearch / pytorch3d

PyTorch3D is FAIR's library of reusable components for deep learning with 3D data
https://pytorch3d.org/
Other
8.7k stars 1.3k forks source link

marching_cubes does not work for cuda tensors #1679

Closed nikhilmishra000 closed 10 months ago

nikhilmishra000 commented 11 months ago

🐛 Bugs / Unexpected behaviors

pytorch3d.ops.marching_cubes.marching_cubes() does not work on v0.7.5 for cuda tensors. It throws RuntimeError: expected scalar type Int but found Long.

Instructions To Reproduce the Issue:

I am using torch==2.1.0+cu121 and I installed pytorch3d via:

pip install "git+https://github.com/facebookresearch/pytorch3d.git@v0.7.5"

The following snippet raises the error:

import torch
from pytorch3d.ops.marching_cubes import marching_cubes

x_cpu = torch.rand(4, 32, 32, 32, device="cpu")
_ = marching_cubes(x_cpu, 0.7)     # works

x_cuda = x_cpu.cuda()
_ = marching_cubes(x_cuda, 0.7)    # fails

This raises RuntimeError: expected scalar type Int but found Long.

bottler commented 11 months ago

I broke the marching_cubes cuda implementation recently with my commit https://github.com/facebookresearch/pytorch3d/commit/6f2212da46f3ad1a596b3e1017be2d16eaaf95f9 which was attempting to fix windows' build problems (see #1610). Fixing the type error you are seeing (which is easy) doesn't give the right result. This needs investigating. For the moment, it would be easiest to build from a source checkout, changing marching_cubes.cu to the previous version.

nikhilmishra000 commented 11 months ago

Thanks, I'll give that a try -- are there any tests in the pytorch3d repo I can run to check correctness?

bottler commented 11 months ago

Turns out all the test_marching_cubes tests are checking cpu only (where output order is deterministic). That's how this went wrong. Ideally the same tests would check gpu too.

bottler commented 11 months ago

Turns out all the test_marching_cubes tests are checking cpu only (where output order is deterministic). That's how this went wrong. Ideally the same tests would check gpu too.

In fact, fixing the typing in the new code works.

Khoa-NT commented 8 months ago

hi @bottler, thank you for taking care of this case.

Can I ask if you have any updates on this? (I'm using v0.7.5)