Commit ·
cda3e6f
1
Parent(s): d95ff3d
Include PyTorch CUDA headers for nvdiffrast JIT
Browse files
app.py
CHANGED
|
@@ -75,6 +75,29 @@ def _find_site_package_dir(relative_path: str) -> Optional[Path]:
|
|
| 75 |
return None
|
| 76 |
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def _symlink_children(src_dir: Optional[Path], dst_dir: Path) -> None:
|
| 79 |
if src_dir is None or not src_dir.exists():
|
| 80 |
return
|
|
@@ -97,6 +120,18 @@ def _configure_cuda_extension_runtime() -> None:
|
|
| 97 |
runtime_include = cuda_runtime_root / 'include' if cuda_runtime_root else None
|
| 98 |
nvcc_include = cuda_nvcc_root / 'include' if cuda_nvcc_root else None
|
| 99 |
nvcc_bin = cuda_nvcc_root / 'bin' if cuda_nvcc_root else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
if not runtime_lib or not (runtime_lib / 'libcudart.so.12').exists():
|
| 102 |
print('[app_hf] CUDA 12 runtime package not found; using system CUDA_HOME.', flush=True)
|
|
@@ -125,16 +160,20 @@ def _configure_cuda_extension_runtime() -> None:
|
|
| 125 |
|
| 126 |
_symlink_children(runtime_include, compat_include)
|
| 127 |
_symlink_children(nvcc_include, compat_include)
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
| 129 |
libcudart_link = compat_lib / 'libcudart.so'
|
| 130 |
if not libcudart_link.exists() and not libcudart_link.is_symlink():
|
| 131 |
libcudart_link.symlink_to(runtime_lib / 'libcudart.so.12')
|
| 132 |
|
| 133 |
os.environ['CUDA_HOME'] = str(compat_root)
|
| 134 |
os.environ['CUDA_PATH'] = str(compat_root)
|
|
|
|
| 135 |
_prepend_env_path('PATH', [compat_bin, nvcc_bin])
|
| 136 |
-
_prepend_env_path('LIBRARY_PATH', [compat_lib
|
| 137 |
-
_prepend_env_path('LD_LIBRARY_PATH', [compat_lib
|
| 138 |
|
| 139 |
try:
|
| 140 |
import ctypes
|
|
|
|
| 75 |
return None
|
| 76 |
|
| 77 |
|
| 78 |
+
def _find_site_package_dirs(relative_path: str) -> List[Path]:
|
| 79 |
+
import site
|
| 80 |
+
|
| 81 |
+
roots = []
|
| 82 |
+
for getter in (site.getsitepackages, lambda: [site.getusersitepackages()]):
|
| 83 |
+
try:
|
| 84 |
+
roots.extend(getter())
|
| 85 |
+
except Exception:
|
| 86 |
+
pass
|
| 87 |
+
try:
|
| 88 |
+
roots.append(str(Path(torch.__file__).resolve().parents[1]))
|
| 89 |
+
except Exception:
|
| 90 |
+
pass
|
| 91 |
+
|
| 92 |
+
found = []
|
| 93 |
+
for root in dict.fromkeys(roots):
|
| 94 |
+
parent = Path(root) / relative_path
|
| 95 |
+
if not parent.exists():
|
| 96 |
+
continue
|
| 97 |
+
found.extend(sorted(parent.iterdir()))
|
| 98 |
+
return [path for path in found if path.is_dir()]
|
| 99 |
+
|
| 100 |
+
|
| 101 |
def _symlink_children(src_dir: Optional[Path], dst_dir: Path) -> None:
|
| 102 |
if src_dir is None or not src_dir.exists():
|
| 103 |
return
|
|
|
|
| 120 |
runtime_include = cuda_runtime_root / 'include' if cuda_runtime_root else None
|
| 121 |
nvcc_include = cuda_nvcc_root / 'include' if cuda_nvcc_root else None
|
| 122 |
nvcc_bin = cuda_nvcc_root / 'bin' if cuda_nvcc_root else None
|
| 123 |
+
nvidia_package_dirs = _find_site_package_dirs('nvidia')
|
| 124 |
+
nvidia_include_dirs = [
|
| 125 |
+
path / 'include'
|
| 126 |
+
for path in nvidia_package_dirs
|
| 127 |
+
if (path / 'include').exists()
|
| 128 |
+
]
|
| 129 |
+
nvidia_lib_dirs = [
|
| 130 |
+
lib_dir
|
| 131 |
+
for path in nvidia_package_dirs
|
| 132 |
+
for lib_dir in (path / 'lib', path / 'lib64')
|
| 133 |
+
if lib_dir.exists()
|
| 134 |
+
]
|
| 135 |
|
| 136 |
if not runtime_lib or not (runtime_lib / 'libcudart.so.12').exists():
|
| 137 |
print('[app_hf] CUDA 12 runtime package not found; using system CUDA_HOME.', flush=True)
|
|
|
|
| 160 |
|
| 161 |
_symlink_children(runtime_include, compat_include)
|
| 162 |
_symlink_children(nvcc_include, compat_include)
|
| 163 |
+
for include_dir in nvidia_include_dirs:
|
| 164 |
+
_symlink_children(include_dir, compat_include)
|
| 165 |
+
for lib_dir in nvidia_lib_dirs:
|
| 166 |
+
_symlink_children(lib_dir, compat_lib)
|
| 167 |
libcudart_link = compat_lib / 'libcudart.so'
|
| 168 |
if not libcudart_link.exists() and not libcudart_link.is_symlink():
|
| 169 |
libcudart_link.symlink_to(runtime_lib / 'libcudart.so.12')
|
| 170 |
|
| 171 |
os.environ['CUDA_HOME'] = str(compat_root)
|
| 172 |
os.environ['CUDA_PATH'] = str(compat_root)
|
| 173 |
+
os.environ.setdefault('TORCH_EXTENSIONS_DIR', '/tmp/anigen_torch_extensions_cuda12')
|
| 174 |
_prepend_env_path('PATH', [compat_bin, nvcc_bin])
|
| 175 |
+
_prepend_env_path('LIBRARY_PATH', [compat_lib] + nvidia_lib_dirs)
|
| 176 |
+
_prepend_env_path('LD_LIBRARY_PATH', [compat_lib] + nvidia_lib_dirs)
|
| 177 |
|
| 178 |
try:
|
| 179 |
import ctypes
|