Skip to content

Commit

Permalink
Update backend.py
Browse files Browse the repository at this point in the history
Add condition to search in the C:\Program Files folder.
  • Loading branch information
pergyz authored Aug 7, 2024
1 parent 5ee29af commit 4b814f0
Showing 1 changed file with 53 additions and 18 deletions.
71 changes: 53 additions & 18 deletions ernerf/raymarching/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,72 @@
_src_path = os.path.dirname(os.path.abspath(__file__))

nvcc_flags = [
'-O3', '-std=c++14',
'-U__CUDA_NO_HALF_OPERATORS__', '-U__CUDA_NO_HALF_CONVERSIONS__', '-U__CUDA_NO_HALF2_OPERATORS__',
"-O3",
"-std=c++14",
"-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']
c_flags = ["-O3", "-std=c++14"]
elif os.name == "nt":
c_flags = ['/O2', '/std:c++17']
c_flags = ["/O2", "/std:c++17"]

# find cl.exe
def find_cl_path():
import glob
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)
if paths:
return paths[0]

# Directories to search
search_paths = [r"C:\Program Files", r"C:\Program Files (x86)"]

# Editions to check
editions = ["Enterprise", "Professional", "BuildTools", "Community"]

for base_path in search_paths:
for edition in editions:
# Construct the search pattern for the current edition
pattern = os.path.join(
base_path,
"Microsoft Visual Studio",
"*",
edition,
"VC",
"Tools",
"MSVC",
"*",
"bin",
"Hostx64",
"x64",
)
# Perform the search
paths = sorted(glob.glob(pattern), reverse=True)
if paths:
return paths[0]

# If no path is found, return None or raise an error
return None

# If cl.exe is not on path, try to find it.
if os.system("where cl.exe >nul 2>nul") != 0:
cl_path = find_cl_path()
if cl_path is None:
raise RuntimeError("Could not locate a supported Microsoft Visual C++ installation")
raise RuntimeError(
"Could not locate a supported Microsoft Visual C++ installation"
)
os.environ["PATH"] += ";" + cl_path

_backend = load(name='_raymarching_face',
extra_cflags=c_flags,
extra_cuda_cflags=nvcc_flags,
sources=[os.path.join(_src_path, 'src', f) for f in [
'raymarching.cu',
'bindings.cpp',
]],
)
_backend = load(
name="_raymarching_face",
extra_cflags=c_flags,
extra_cuda_cflags=nvcc_flags,
sources=[
os.path.join(_src_path, "src", f)
for f in [
"raymarching.cu",
"bindings.cpp",
]
],
)

__all__ = ['_backend']
__all__ = ["_backend"]

0 comments on commit 4b814f0

Please sign in to comment.