MCPcopy Create free account
hub / github.com/pytorch/executorch / _get_cuda_version

Function _get_cuda_version

install_utils.py:60–103  ·  view source on GitHub ↗

Get the CUDA version installed on the system using nvcc command. Returns a tuple (major, minor). Raises: RuntimeError: if nvcc is not found or version cannot be parsed

()

Source from the content-addressed store, hash-verified

58
59@functools.lru_cache(maxsize=1)
60def _get_cuda_version():
61 """
62 Get the CUDA version installed on the system using nvcc command.
63 Returns a tuple (major, minor).
64
65 Raises:
66 RuntimeError: if nvcc is not found or version cannot be parsed
67 """
68 try:
69 # Get CUDA version from nvcc (CUDA compiler)
70 nvcc_result = subprocess.run(
71 ["nvcc", "--version"], capture_output=True, text=True, check=True
72 )
73 # Parse nvcc output for CUDA version
74 # Output contains line like "Cuda compilation tools, release 12.6, V12.6.68"
75 match = re.search(r"release (\d+)\.(\d+)", nvcc_result.stdout)
76 if match:
77 major, minor = int(match.group(1)), int(match.group(2))
78
79 # Check if the detected version is supported
80 if (major, minor) not in SUPPORTED_CUDA_VERSIONS:
81 available_versions = ", ".join(
82 [f"{maj}.{min}" for maj, min in SUPPORTED_CUDA_VERSIONS]
83 )
84 raise RuntimeError(
85 f"Detected CUDA version {major}.{minor} is not supported. "
86 f"Supported versions: {available_versions}."
87 )
88
89 return (major, minor)
90 else:
91 raise RuntimeError(
92 "Failed to parse CUDA version from nvcc output. "
93 "Ensure CUDA is properly installed."
94 )
95 except FileNotFoundError:
96 raise RuntimeError(
97 "nvcc (CUDA compiler) is not found in PATH. Install the CUDA toolkit."
98 )
99 except subprocess.CalledProcessError as e:
100 raise RuntimeError(
101 f"nvcc command failed with error: {e}. "
102 "Ensure CUDA is properly installed."
103 )
104
105
106def _extract_cmake_define(args: List[str], name: str) -> Optional[str]:

Callers 2

is_cuda_availableFunction · 0.85
determine_torch_urlFunction · 0.85

Calls 1

runMethod · 0.45

Tested by

no test coverage detected