From 4f1a4523aa844d68c4a0dfa40d9325aaf8ac1a3a Mon Sep 17 00:00:00 2001 From: WaefreBeorn <32711803+emangamer@users.noreply.github.com> Date: Sun, 28 Apr 2024 18:48:49 -0400 Subject: [PATCH 1/2] Update ops.py changes ops.py to work with Visual Studio 2019 and properly compile on windows, used as main call for windows_run_bat of InstantMesh forked by me --- nvdiffrast/torch/ops.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/nvdiffrast/torch/ops.py b/nvdiffrast/torch/ops.py index ebe770b..ca7edfd 100644 --- a/nvdiffrast/torch/ops.py +++ b/nvdiffrast/torch/ops.py @@ -29,12 +29,15 @@ def _get_plugin(gl=False): lib_dir = os.path.dirname(__file__) + r"\..\lib" def find_cl_path(): import glob - for edition in ['Enterprise', 'Professional', 'BuildTools', 'Community']: - vs_relative_path = r"\Microsoft Visual Studio\*\%s\VC\Tools\MSVC\*\bin\Hostx64\x64" % edition - paths = sorted(glob.glob(r"C:\Program Files" + vs_relative_path), reverse=True) - paths += sorted(glob.glob(r"C:\Program Files (x86)" + vs_relative_path), reverse=True) - if paths: - return paths[0] + def get_sort_key(x): + x = x.split('\\')[3:] + x[1] = {'BuildTools': '~0', 'Community': '~1', 'Pro': '~2', 'Professional': '~3', 'Enterprise': '~4'}.get(x[1], x[1]) + return x + vs_relative_path = r"\Microsoft Visual Studio\*\*\VC\Tools\MSVC\*\bin\Hostx64\x64" + paths = glob.glob(r"C:\Program Files" + vs_relative_path) + paths += glob.glob(r"C:\Program Files (x86)" + vs_relative_path) + if paths: + return sorted(paths, key=get_sort_key)[-1] # If cl.exe is not on path, try to find it. if os.system("where cl.exe >nul 2>nul") != 0: @@ -112,10 +115,20 @@ def find_cl_path(): distutils._msvccompiler._get_vc_env = functools.lru_cache()(distutils._msvccompiler._get_vc_env) except: pass + # Detect Visual Studio include and library paths + vspath = os.environ.get('VSPATH') + if vspath is not None: + vs_include_path = os.path.join(vspath, 'VC', 'Tools', 'MSVC', '*', 'include') + vs_lib_path = os.path.join(vspath, 'VC', 'Tools', 'MSVC', '*', 'lib', 'x64') + opts += [f'-I{vs_include_path}'] + ldflags += [f'-LIBPATH:{vs_lib_path}'] # Compile and load. source_paths = [os.path.join(os.path.dirname(__file__), fn) for fn in source_files] - torch.utils.cpp_extension.load(name=plugin_name, sources=source_paths, extra_cflags=opts, extra_cuda_cflags=opts+['-lineinfo'], extra_ldflags=ldflags, with_cuda=True, verbose=False) + import sysconfig + python_include_path = sysconfig.get_path('include') + + torch.utils.cpp_extension.load(name=plugin_name, sources=source_paths, extra_cflags=opts + [f'-I{python_include_path}'], extra_cuda_cflags=opts+['-lineinfo', f'-I{python_include_path}'], extra_ldflags=ldflags, with_cuda=True, verbose=True) # Import, cache, and return the compiled module. _cached_plugin[gl] = importlib.import_module(plugin_name) From 51b8bccda85ffdc83f6f1a2e46894f6af4618994 Mon Sep 17 00:00:00 2001 From: WaefreBeorn <32711803+emangamer@users.noreply.github.com> Date: Tue, 30 Apr 2024 21:39:44 -0400 Subject: [PATCH 2/2] Update ops.py fixing --- nvdiffrast/torch/ops.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/nvdiffrast/torch/ops.py b/nvdiffrast/torch/ops.py index ca7edfd..90bb41f 100644 --- a/nvdiffrast/torch/ops.py +++ b/nvdiffrast/torch/ops.py @@ -115,13 +115,19 @@ def get_sort_key(x): distutils._msvccompiler._get_vc_env = functools.lru_cache()(distutils._msvccompiler._get_vc_env) except: pass - # Detect Visual Studio include and library paths - vspath = os.environ.get('VSPATH') - if vspath is not None: - vs_include_path = os.path.join(vspath, 'VC', 'Tools', 'MSVC', '*', 'include') - vs_lib_path = os.path.join(vspath, 'VC', 'Tools', 'MSVC', '*', 'lib', 'x64') - opts += [f'-I{vs_include_path}'] - ldflags += [f'-LIBPATH:{vs_lib_path}'] + + # Detect Visual Studio include and library paths + vspath = os.environ.get('VSPATH') + vs_include_path = None + vs_lib_path = None + if vspath is not None: + vs_include_path = os.path.join(vspath, 'VC', 'Tools', 'MSVC', '*', 'include') + vs_lib_path = os.path.join(vspath, 'VC', 'Tools', 'MSVC', '*', 'lib', 'x64') + + if vs_include_path is not None: + opts += [f'-I{vs_include_path}'] + if vs_lib_path is not None: + ldflags += [f'-LIBPATH:{vs_lib_path}'] # Compile and load. source_paths = [os.path.join(os.path.dirname(__file__), fn) for fn in source_files]