ashawkey / cubvh

CUDA Mesh BVH tools.
MIT License
156 stars 11 forks source link

C++ standard version update #14

Open lcp29 opened 7 months ago

lcp29 commented 7 months ago

A version of PyTorch (mine is torch2.1.2+cu121) requires C++ 17 for its compliation. Directly running

pip install .

results in the errors including:

      /home/******/miniconda3/envs/******/lib/python3.10/site-packages/torch/include/c10/util/C++17.h:27:2: error: #error You need C++17 to compile PyTorch
         27 | #error You need C++17 to compile PyTorch
            |  ^~~~~
      In file included from /home/******/miniconda3/envs/******/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/torch.h:3,
                       from /home/******/Projects/cubvh/include/cubvh/api.h:5,
                       from /home/******/Projects/cubvh/src/api.cu:3:
      /home/******/miniconda3/envs/******/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/all.h:4:2: error: #error C++17 or later compatible compiler is required to use PyTorch.
          4 | #error C++17 or later compatible compiler is required to use PyTorch.
            |  ^~~~~

After the following patch applied cuBVH was installed successfully:

diff --git a/setup.py b/setup.py
index 10efae9..968d7a8 100644
--- a/setup.py
+++ b/setup.py
@@ -107,7 +107,7 @@ if os.name == "nt":
        # won't try to activate a developer command prompt a second time.
        os.environ["DISTUTILS_USE_SDK"] = "1"

-cpp_standard = 14
+cpp_standard = 17

 # Get CUDA version and make sure the targeted compute capability is compatible
 if os.system("nvcc --version") == 0:

and functioned as normal.

ashawkey commented 7 months ago

@lcp29 Thanks for reporting it! Do you mind opening a PR to fix it?

lcp29 commented 7 months ago

@ashawkey I'm sorry. It seems that nvcc is not in my path and there is already relevant code in setup.py:

cpp_standard = 14

# Get CUDA version and make sure the targeted compute capability is compatible
if os.system("nvcc --version") == 0:
    nvcc_out = subprocess.check_output(["nvcc", "--version"]).decode()
    cuda_version = re.search(r"release (\S+),", nvcc_out)

    if cuda_version:
        cuda_version = parse_version(cuda_version.group(1))
        print(f"Detected CUDA version {cuda_version}")
        if cuda_version >= parse_version("11.0"):
            cpp_standard = 17

I added a nvcc_try_paths for such case. By the way they have updated C++ standard in ATen since PyTorch 2.1.0. pytorch/pytorch@bcb4444c

ashawkey commented 7 months ago

Oh I didn't notice that too. In that case this sounds not a reasonable idea, since we assume nvcc can be found in PATH. Maybe we can delete the whole if statement and directly change cpp_standard = 17.

lcp29 commented 7 months ago

How about we use torch.__version__? Users with cuda<11 will be unable to build it in c++17.

ashawkey commented 7 months ago

It doesn't seem very different from current nvcc version... maybe like this:

from packaging import version
if version(torch.__version__) > version("2.1.0"):
    cpp_standard = 17
elif os.system("nvcc --version") == 0:
    ....