Python get cuda version
7 Python code examples are found related to "
get cuda version".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: nvcc.py From training_results_v0.6 with Apache License 2.0 | 6 votes |
def get_cuda_version(cuda_path): """Utility function to get cuda version Parameters ---------- cuda_path : str Path to cuda root. Returns ------- version : float The cuda version """ version_file_path = os.path.join(cuda_path, "version.txt") try: with open(version_file_path) as f: version_str = f.readline().replace('\n', '').replace('\r', '') return float(version_str.split(" ")[2][:2]) except: raise RuntimeError("Cannot read cuda version file")
Example 2
Source File: gpu_utils.py From azure-python-labs with MIT License | 6 votes |
def get_cuda_version(unix_path=DEFAULT_CUDA_PATH_LINUX): """Get CUDA version Args: unix_path (str): Path to CUDA version file in Linux/Mac. Returns: str: Version of the library. """ if sys.platform == "win32": raise NotImplementedError("Implement this!") elif sys.platform in ["linux", "darwin"]: if os.path.isfile(unix_path): with open(unix_path, "r") as f: data = f.read().replace("\n", "") return data else: return "No CUDA in this machine" else: raise ValueError("Not in Windows, Linux or Mac")
Example 3
Source File: cuda_toolkit.py From PerfKitBenchmarker with Apache License 2.0 | 6 votes |
def GetCudaToolkitVersion(vm): """Get the CUDA toolkit version on the vm, based on nvcc. Args: vm: the virtual machine to query Returns: A string containing the active CUDA toolkit version, None if nvcc could not be found Raises: NvccParseOutputError: On can not parse nvcc output """ stdout, _ = vm.RemoteCommand( posixpath.join(CUDA_HOME, 'bin/nvcc') + ' --version', ignore_failure=True, suppress_warning=True) if bool(stdout.rstrip()): regex = r'release (\S+),' match = re.search(regex, stdout) if match: return str(match.group(1)) raise NvccParseOutputError('Unable to parse nvcc version output from {}' .format(stdout)) else: return None
Example 4
Source File: build.py From cupy with MIT License | 5 votes |
def get_cuda_version(formatted=False): """Return CUDA Toolkit version cached in check_cuda_version().""" global _cuda_version if _cuda_version is None: msg = 'check_cuda_version() must be called first.' raise RuntimeError(msg) if formatted: return _format_cuda_version(_cuda_version) return _cuda_version
Example 5
Source File: run.py From mead-baseline with Apache License 2.0 | 5 votes |
def get_cuda_version(framework): if framework == 'pytorch': import torch cuda = version_str_to_tuple(torch.version.cuda) cudnn = torch.backends.cudnn.version() cudnn_major = cudnn // 1000 cudnn = cudnn % 1000 cudnn_minor = cudnn // 100 cudnn_patch = cudnn % 100 cudnn = Version(cudnn_major, cudnn_minor, cudnn_patch) return cuda, cudnn return file_based_cuda_version()
Example 6
Source File: requirements.py From trains-agent with Apache License 2.0 | 4 votes |
def get_cuda_version(config): # type: (ConfigTree) -> (Text, Text) # we assume os.environ already updated the config['agent.cuda_version'] & config['agent.cudnn_version'] cuda_version = config['agent.cuda_version'] cudnn_version = config['agent.cudnn_version'] if cuda_version and cudnn_version: return normalize_cuda_version(cuda_version), normalize_cuda_version(cudnn_version) if not cuda_version and is_windows_platform(): try: cuda_vers = [int(k.replace('CUDA_PATH_V', '').replace('_', '')) for k in os.environ.keys() if k.startswith('CUDA_PATH_V')] cuda_vers = max(cuda_vers) if cuda_vers > 40: cuda_version = cuda_vers except: pass if not cuda_version: try: try: nvcc = 'nvcc.exe' if is_windows_platform() else 'nvcc' if is_windows_platform() and 'CUDA_PATH' in os.environ: nvcc = os.path.join(os.environ['CUDA_PATH'], nvcc) output = Argv(nvcc, '--version').get_output() except OSError: raise CudaNotFound('nvcc not found') match = re.search(r'release (.{3})', output).group(1) cuda_version = Text(int(float(match) * 10)) except: pass if not cuda_version: try: try: output = Argv('nvidia-smi',).get_output() except OSError: raise CudaNotFound('nvcc not found') match = re.search(r'CUDA Version: ([0-9]+).([0-9]+)', output) match = match.group(1)+'.'+match.group(2) cuda_version = Text(int(float(match) * 10)) except: pass if not cudnn_version: try: cuda_lib = which('nvcc') if is_windows_platform: cudnn_h = path.sep.join(cuda_lib.split(path.sep)[:-2] + ['include', 'cudnn.h']) else: cudnn_h = path.join(path.sep, *(cuda_lib.split(path.sep)[:-2] + ['include', 'cudnn.h'])) cudnn_major, cudnn_minor = None, None try: include_file = open(cudnn_h) except OSError: raise CudaNotFound('Could not read cudnn.h') with include_file: for line in include_file: if 'CUDNN_MAJOR' in line: cudnn_major = line.split()[-1] if 'CUDNN_MINOR' in line: cudnn_minor = line.split()[-1] if cudnn_major and cudnn_minor: break cudnn_version = cudnn_major + (cudnn_minor or '0') except: pass return (normalize_cuda_version(cuda_version or 0), normalize_cuda_version(cudnn_version or 0))