Spaces:
Sleeping
Sleeping
Preload libcudart.so.13 via ctypes.CDLL before nvdiffrast import
Browse files
app.py
CHANGED
|
@@ -25,14 +25,29 @@ import sys
|
|
| 25 |
import time
|
| 26 |
from pathlib import Path
|
| 27 |
|
| 28 |
-
# nvdiffrast is compiled against
|
| 29 |
-
#
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
import gradio as gr
|
| 38 |
import spaces # HF ZeroGPU
|
|
|
|
| 25 |
import time
|
| 26 |
from pathlib import Path
|
| 27 |
|
| 28 |
+
# nvdiffrast is compiled against CUDA 13.0 and its .so links to libcudart.so.13.
|
| 29 |
+
# os.environ["LD_LIBRARY_PATH"] only affects child processes, not the running
|
| 30 |
+
# Python interpreter. Use ctypes.CDLL with RTLD_GLOBAL to load libcudart.so.13
|
| 31 |
+
# into the current process before nvdiffrast is imported.
|
| 32 |
+
import ctypes, glob as _glob
|
| 33 |
+
|
| 34 |
+
def _preload_cudart() -> None:
|
| 35 |
+
cuda_lib_dir = "/cuda-image/usr/local/cuda-13.0/lib64"
|
| 36 |
+
# Try versioned name first, then unversioned fallback.
|
| 37 |
+
for pattern in (
|
| 38 |
+
f"{cuda_lib_dir}/libcudart.so.13*",
|
| 39 |
+
f"{cuda_lib_dir}/libcudart.so",
|
| 40 |
+
):
|
| 41 |
+
matches = _glob.glob(pattern)
|
| 42 |
+
if matches:
|
| 43 |
+
try:
|
| 44 |
+
ctypes.CDLL(matches[0], mode=ctypes.RTLD_GLOBAL)
|
| 45 |
+
print(f"Preloaded {matches[0]}", flush=True)
|
| 46 |
+
except OSError as e:
|
| 47 |
+
print(f"Preload failed for {matches[0]}: {e}", flush=True)
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
+
_preload_cudart()
|
| 51 |
|
| 52 |
import gradio as gr
|
| 53 |
import spaces # HF ZeroGPU
|