Utility function to get CUDA version Parameters ---------- cuda_path : Optional[str] Path to CUDA root. If None is passed, will use `find_cuda_path()` as default. Returns ------- version : float The CUDA version
(cuda_path=None)
| 721 | |
| 722 | |
| 723 | def get_cuda_version(cuda_path=None): |
| 724 | """Utility function to get CUDA version |
| 725 | |
| 726 | Parameters |
| 727 | ---------- |
| 728 | cuda_path : Optional[str] |
| 729 | |
| 730 | Path to CUDA root. If None is passed, will use |
| 731 | `find_cuda_path()` as default. |
| 732 | |
| 733 | Returns |
| 734 | ------- |
| 735 | version : float |
| 736 | The CUDA version |
| 737 | |
| 738 | """ |
| 739 | if cuda_path is None: |
| 740 | cuda_path = find_cuda_path() |
| 741 | |
| 742 | version_file_path = os.path.join(cuda_path, "version.txt") |
| 743 | if not os.path.exists(version_file_path): |
| 744 | # Debian/Ubuntu repackaged CUDA path |
| 745 | version_file_path = os.path.join(cuda_path, "lib", "cuda", "version.txt") |
| 746 | try: |
| 747 | with open(version_file_path) as f: |
| 748 | version_str = f.read().strip().split()[-1] |
| 749 | return tuple(int(field) for field in version_str.split(".")) |
| 750 | except FileNotFoundError: |
| 751 | pass |
| 752 | |
| 753 | cmd = [os.path.join(cuda_path, "bin", "nvcc"), "--version"] |
| 754 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 755 | (out, _) = proc.communicate() |
| 756 | out = out.decode("utf-8", errors="replace") |
| 757 | if proc.returncode == 0: |
| 758 | release_line = next(line for line in out.split("\n") if "release" in line) |
| 759 | release_fields = [s.strip() for s in release_line.split(",")] |
| 760 | version_str = next(f[1:] for f in release_fields if f.startswith("V")) |
| 761 | return tuple(int(field) for field in version_str.split(".")) |
| 762 | raise RuntimeError("Cannot read CUDA version file") |
| 763 | |
| 764 | |
| 765 | def find_nvshmem_paths() -> tuple[str, str]: |
no test coverage detected
searching dependent graphs…