Commit 7d436274 authored by ashawkey's avatar ashawkey
Browse files

fix building for torch 2

parent d3e923c9
import os
import re
import subprocess
from pkg_resources import parse_version
from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
......@@ -20,7 +23,7 @@ def find_eigen(min_ver=(3, 3, 0)):
MINOR_VER_STR = "#define EIGEN_MINOR_VERSION"
EIGEN_WEB_URL = 'https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.bz2'
TMP_EIGEN_FILE = 'tmp_eigen.tar.bz2'
TMP_EIGEN_DIR = 'eigen-3.3.7'
TMP_EIGEN_DIR = './eigen-3.3.7'
min_ver_str = '.'.join(map(str, min_ver))
eigen_path = None
......@@ -80,23 +83,15 @@ def find_eigen(min_ver=(3, 3, 0)):
return eigen_path
nvcc_flags = [
'-O3', '-std=c++14',
"--expt-extended-lambda",
"--expt-relaxed-constexpr",
'-U__CUDA_NO_HALF_OPERATORS__', '-U__CUDA_NO_HALF_CONVERSIONS__', '-U__CUDA_NO_HALF2_OPERATORS__',
]
if os.name == "posix":
c_flags = ['-O3', '-std=c++14']
elif os.name == "nt":
c_flags = ['/O2', '/std:c++17']
if os.name == "nt":
# find cl.exe
def find_cl_path():
import glob
for executable in ["Program Files (x86)", "Program Files"]:
for edition in ["Enterprise", "Professional", "BuildTools", "Community"]:
paths = sorted(glob.glob(r"C:\\Program Files (x86)\\Microsoft Visual Studio\\*\\%s\\VC\\Tools\\MSVC\\*\\bin\\Hostx64\\x64" % edition), reverse=True)
paths = sorted(glob.glob(f"C:\\{executable}\\Microsoft Visual Studio\\*\\{edition}\\VC\\Tools\\MSVC\\*\\bin\\Hostx64\\x64"), reverse=True)
if paths:
return paths[0]
......@@ -106,6 +101,47 @@ elif os.name == "nt":
if cl_path is None:
raise RuntimeError("Could not locate a supported Microsoft Visual C++ installation")
os.environ["PATH"] += ";" + cl_path
else:
# cl.exe was found in PATH, so we can assume that the user is already in a developer command prompt
# In this case, BuildExtensions requires the following environment variable to be set such that it
# won't try to activate a developer command prompt a second time.
os.environ["DISTUTILS_USE_SDK"] = "1"
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
print(f"Targeting C++ standard {cpp_standard}")
base_nvcc_flags = [
f"-std=c++{cpp_standard}",
"--extended-lambda",
"--expt-relaxed-constexpr",
# The following definitions must be undefined
# since TCNN requires half-precision operation.
"-U__CUDA_NO_HALF_OPERATORS__",
"-U__CUDA_NO_HALF_CONVERSIONS__",
"-U__CUDA_NO_HALF2_OPERATORS__",
]
if os.name == "posix":
base_cflags = [f"-std=c++{cpp_standard}"]
base_nvcc_flags += [
"-Xcompiler=-Wno-float-conversion",
"-Xcompiler=-fno-strict-aliasing",
]
elif os.name == "nt":
base_cflags = [f"/std:c++{cpp_standard}"]
'''
Usage:
......@@ -136,8 +172,8 @@ setup(
find_eigen(),
],
extra_compile_args={
'cxx': c_flags,
'nvcc': nvcc_flags,
'cxx': base_cflags,
'nvcc': base_nvcc_flags,
}
),
],
......@@ -146,6 +182,7 @@ setup(
},
install_requires=[
'ninja',
'pybind11',
'trimesh',
'opencv-python',
'torch',
......
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/eigen.h>
// #include <pybind11/pybind11.h>
// #include <pybind11/numpy.h>
// #include <pybind11/eigen.h>
#include <torch/extension.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment