import os
envpathvar = os.environ['PATH']
print('From environment variables path:')
syspaths = envpathvar.split(';')
bin_paths = []
for syspath in syspaths:
if 'CUDA' in syspath:
print(f'{syspath}')
if 'bin' in syspath:
bin_paths.append(syspath)
if not bin_paths:
print('cuda not found in env paths')
for bin_path in bin_paths:
print()
cmdexec = f'"{bin_path}\\nvcc" --version'
print(f'Using: {cmdexec}')
for line in os.popen(cmdexec).read().split('\n'):
if 'release' in line:
cuda_ver = line.replace('Cuda compilation tools, release', '').strip()
print(f'CUDA Version: {cuda_ver}')
cudnn_h = bin_path.replace('bin', 'include\\cudnn_version.h')
if not os.path.exists(cudnn_h):
cudnn_h = bin_path.replace('bin', 'include\\cudnn.h')
if os.path.exists(cudnn_h):
with open(cudnn_h) as f:
lines = f.readlines()
cudnn_major = 0
cudnn_minor = 0
cudnn_patch = 0
for line in lines:
if '#define CUDNN_MAJOR' in line:
cudnn_major = line.replace('#define CUDNN_MAJOR', '').strip()
elif '#define CUDNN_MINOR' in line:
cudnn_minor = line.replace('#define CUDNN_MINOR', '').strip()
elif '#define CUDNN_PATCHLEVEL' in line:
cudnn_patch = line.replace('#define CUDNN_PATCHLEVEL', '').strip()
print(f'cuDNN Version: {cudnn_major}.{cudnn_minor}.{cudnn_patch}')
else:
print('cuDNN not found for this cuda')