Leszek Bukowski commited on
Commit ·
dbd6b58
1
Parent(s): 8867c65
Support recorded Python 3.13 runtime and preflight CUDA linking
Browse files12 unmodified lines1314151617181945 unmodified lines65666767686969707170717273747579 unmodified lines15515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818912 unmodified linesimport shutilimport subprocessimport sysimport tempfileimport threadingimport time
45 unmodified lines
def check_preflight(): print("Python:", platform.python_version(), flush=True) if sys.version_info[:2] != (3, 12): if sys.version_info[:2] not in ((3, 12), (3, 13)): raise RuntimeError( "Python 3.12 is required. In Colab, select Runtime → Change runtime type → " "Runtime version 2026.07, reconnect, then rerun Prepare runtime. " "For a local kernel, create a Python 3.12 environment. No packages were installed." "Use Python 3.12 or 3.13. In Colab, select Runtime → Change runtime type → " "the latest runtime version, reconnect, then rerun Prepare runtime. " "The recorded GPU runs used Python 3.13. No packages were installed." ) if platform.system() != "Linux" or not shutil.which("nvidia-smi"): raise RuntimeError("Use a Linux NVIDIA GPU runtime. This is not a Mac/CPU demo.")79 unmodified lines os.environ["CUDA_HOME"] = str(nvcc.parent.parent) os.environ["PATH"] = str(nvcc.parent) + os.pathsep + os.environ.get("PATH", "") print(f"CUDA compiler verified: 13.0 ({nvcc}). Host driver unchanged.", flush=True) check_cuda_linker(nvcc, log_path)
def check_cuda_linker(nvcc, log_path): """Catch a missing CUDA runtime link before the lengthy extension build.""" root = nvcc.parent.parent runtime = next((p for folder in ("lib64", "lib") for p in (root / folder / "libcudart.so", root / folder / "libcudart.so.13") if p.is_file()), None) if runtime is None: raise RuntimeError(f"CUDA runtime library is missing under {root}; no extension build started.") # NVIDIA's pip wheel provides the versioned library but may omit the linker alias. # Keep our alias outside installed packages and the system CUDA installation. links = Path.cwd() / ".thesystem-runtime" / "cuda-link" links.mkdir(parents=True, exist_ok=True) alias = links / "libcudart.so" if alias.is_symlink(): alias.unlink() elif alias.exists(): raise RuntimeError(f"Unexpected file at {alias}; refusing to replace it.") alias.symlink_to(runtime.resolve()) existing = [p for p in os.environ.get("LIBRARY_PATH", "").split(os.pathsep) if p and p != str(links)] os.environ["LIBRARY_PATH"] = os.pathsep.join([str(links), *existing]) with tempfile.TemporaryDirectory(prefix="thesystem-cuda-check-") as tmp: source = Path(tmp) / "link_check.cu" source.write_text('#include <cuda_runtime_api.h>\nextern "C" int check() { int n; return cudaGetDeviceCount(&n); }\n') run_command([str(nvcc), "--shared", "-Xcompiler", "-fPIC", "--cudart=shared", str(source), f"-L{links}", "-o", str(Path(tmp) / "link_check.so")], log_path) print("CUDA compiler and runtime-library link check passed.", flush=True)
def check_loaded_versions():prepare_runtime.py+34-4