Skip to content

marching_cubes does not work for cuda tensors #1679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nikhilmishra000 opened this issue Nov 2, 2023 · 5 comments
Closed

marching_cubes does not work for cuda tensors #1679

nikhilmishra000 opened this issue Nov 2, 2023 · 5 comments

Comments

@nikhilmishra000
Copy link

nikhilmishra000 commented Nov 2, 2023

🐛 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/[email protected]"

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
Copy link
Contributor

bottler commented Nov 2, 2023

I broke the marching_cubes cuda implementation recently with my commit 6f2212d 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
Copy link
Author

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

@bottler
Copy link
Contributor

bottler commented Nov 2, 2023

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
Copy link
Contributor

bottler commented Nov 2, 2023

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.

facebook-github-bot pushed a commit that referenced this issue Dec 5, 2023
Summary:
Change the data type usage in the code to ensure cross-platform compatibility
long -> int64_t

<img width="628" alt="image" src="https://github.com/facebookresearch/pytorch3d/assets/6214316/40041f7f-3c09-4571-b9ff-676c625802e9">

Tested under
Win 11 and Ubuntu 22.04
with
CUDA 12.1.1 torch 2.1.1

Related issues & PR

#9

#1679

Pull Request resolved: #1689

Reviewed By: MichaelRamamonjisoa

Differential Revision: D51521562

Pulled By: bottler

fbshipit-source-id: d8ea81e223c642e0e9fb283f5d7efc9d6ac00d93
@Khoa-NT
Copy link

Khoa-NT commented Jan 27, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants