def check_compute_capabilities(compiler, settings): """Return compute capabilities of the installed devices.""" global _compute_capabilities try: src = ''' #include <cuda_runtime_api.h> #include <stdio.h> #define CHECK_CUDART(x) { if ((x) != cudaSuccess) return 1; } int main() { int device_count; CHECK_CUDART(cudaGetDeviceCount(&device_count)); for (int i = 0; i < device_count; i++) { cudaDeviceProp prop; CHECK_CUDART(cudaGetDeviceProperties(&prop, i)); printf("%d%d ", prop.major, prop.minor); } return 0; } ''' out = build_and_run( compiler, src, include_dirs=settings['include_dirs'], libraries=('cudart',), library_dirs=settings['library_dirs']) _compute_capabilities = set([int(o) for o in out.split()]) except Exception as e: utils.print_warning('Cannot check compute capability\n{0}'.format(e)) return False return True
def check_cutensor_version(compiler, settings): global _cutensor_version try: out = build_and_run(compiler, ''' #include <cutensor.h> #include <stdio.h> #ifdef CUTENSOR_MAJOR #ifndef CUTENSOR_VERSION #define CUTENSOR_VERSION \ (CUTENSOR_MAJOR * 1000 + CUTENSOR_MINOR * 100 + CUTENSOR_PATCH) #endif #else # define CUTENSOR_VERSION 0 #endif int main(int argc, char* argv[]) { printf("%d", CUTENSOR_VERSION); return 0; } ''', include_dirs=settings['include_dirs']) except Exception as e: utils.print_warning('Cannot check cuTENSOR version\n{0}'.format(e)) return False _cutensor_version = int(out) if _cutensor_version < 1000: utils.print_warning( 'Unsupported cuTENSOR version: {}'.format(_cutensor_version) ) return False return True
def get_cuda_path(): global _cuda_path # Use a magic word to represent the cache not filled because None is a # valid return value. if _cuda_path != 'NOT_INITIALIZED': return _cuda_path nvcc_path = utils.search_on_path(('nvcc', 'nvcc.exe')) cuda_path_default = None if nvcc_path is not None: cuda_path_default = os.path.normpath( os.path.join(os.path.dirname(nvcc_path), '..')) cuda_path = os.environ.get('CUDA_PATH', '') # Nvidia default on Windows if len(cuda_path) > 0 and cuda_path != cuda_path_default: utils.print_warning( 'nvcc path != CUDA_PATH', 'nvcc path: %s' % cuda_path_default, 'CUDA_PATH: %s' % cuda_path) if os.path.exists(cuda_path): _cuda_path = cuda_path elif cuda_path_default is not None: _cuda_path = cuda_path_default elif os.path.exists('/usr/local/cuda'): _cuda_path = '/usr/local/cuda' else: _cuda_path = None return _cuda_path
def check_cudnn_version(compiler, settings): global _cudnn_version try: out = build_and_run(compiler, ''' #include <cudnn.h> #include <stdio.h> int main() { printf("%d", CUDNN_VERSION); return 0; } ''', include_dirs=settings['include_dirs']) except Exception as e: utils.print_warning('Cannot check cuDNN version\n{0}'.format(e)) return False _cudnn_version = int(out) if not minimum_cudnn_version <= _cudnn_version: min_major = str(minimum_cudnn_version) utils.print_warning( 'Unsupported cuDNN version: {}'.format(str(_cudnn_version)), 'cuDNN >=v{} is required'.format(min_major)) return False return True
def check_hip_version(compiler, settings): global _hip_version try: out = build_and_run(compiler, ''' #include <hip/hip_version.h> #include <stdio.h> int main() { printf("%d", HIP_VERSION); return 0; } ''', include_dirs=settings['include_dirs']) except Exception as e: utils.print_warning('Cannot check HIP version', str(e)) return False _hip_version = int(out) if _hip_version < minimum_hip_version: utils.print_warning( 'ROCm/HIP version is too old: %d' % _hip_version, 'ROCm 3.5.0 or newer is required') return False return True
def check_cuda_version(compiler, settings): global _cuda_version try: out = build_and_run(compiler, ''' #include <cuda.h> #include <stdio.h> int main() { printf("%d", CUDA_VERSION); return 0; } ''', include_dirs=settings['include_dirs']) except Exception as e: utils.print_warning('Cannot check CUDA version', str(e)) return False _cuda_version = int(out) if _cuda_version < minimum_cuda_version: utils.print_warning( 'CUDA version is too old: %d' % _cuda_version, 'CUDA 10.2 or newer is required') return False return True
def check_jitify_version(compiler, settings): global _jitify_version try: cupy_jitify_include = _jitify_path # Unfortunately Jitify does not have any identifiable name (branch, # tag, etc), so we must use the commit here a = subprocess.run(' '.join(['git', 'rev-parse', '--short', 'HEAD']), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cupy_jitify_include) if a.returncode == 0: out = a.stdout.decode()[:-1] # unlike elsewhere, out is a str here else: raise RuntimeError('Cannot determine Jitify version from git') except Exception as e: utils.print_warning('Cannot determine Jitify version\n{}'.format(e)) # 0: Jitify is not built (makes no sense), -1: built with unknown ver out = -1 _jitify_version = out settings['define_macros'].append( ('CUPY_JITIFY_VERSION_CODE', _jitify_version)) return True # we always build Jitify
def check_thrust_version(compiler, settings): global _thrust_version try: out = build_and_run(compiler, ''' #include <thrust/version.h> #include <stdio.h> int main() { printf("%d", THRUST_VERSION); return 0; } ''', include_dirs=settings['include_dirs']) except Exception as e: utils.print_warning('Cannot check Thrust version\n{0}'.format(e)) return False _thrust_version = int(out) return True
def check_cusparselt_version(compiler, settings): global _cusparselt_version try: out = build_and_run(compiler, ''' #include <cusparseLt.h> #include <stdio.h> #ifndef CUSPARSELT_VERSION #define CUSPARSELT_VERSION 0 #endif int main(int argc, char* argv[]) { printf("%d", CUSPARSELT_VERSION); return 0; } ''', include_dirs=settings['include_dirs']) except Exception as e: utils.print_warning('Cannot check cuSPARSELt version\n{0}'.format(e)) return False _cusparselt_version = int(out) return True
def check_nccl_version(compiler, settings): global _nccl_version # NCCL 1.x does not provide version information. try: out = build_and_run(compiler, ''' #ifndef CUPY_USE_HIP #include <nccl.h> #else #include <rccl.h> #endif #include <stdio.h> #ifdef NCCL_MAJOR #ifndef NCCL_VERSION_CODE # define NCCL_VERSION_CODE \ (NCCL_MAJOR * 1000 + NCCL_MINOR * 100 + NCCL_PATCH) #endif #else # define NCCL_VERSION_CODE 0 #endif int main() { printf("%d", NCCL_VERSION_CODE); return 0; } ''', include_dirs=settings['include_dirs'], define_macros=settings['define_macros']) except Exception as e: utils.print_warning('Cannot include NCCL\n{0}'.format(e)) return False _nccl_version = int(out) return True
def check_nvtx(compiler, settings): if PLATFORM_WIN32: path = os.environ.get('NVTOOLSEXT_PATH', None) if path is None: utils.print_warning('NVTX unavailable: NVTOOLSEXT_PATH is not set') elif not os.path.exists(path): utils.print_warning( 'NVTX unavailable: NVTOOLSEXT_PATH is set but the directory ' 'does not exist') elif utils.search_on_path(['nvToolsExt64_1.dll']) is None: utils.print_warning( 'NVTX unavailable: nvToolsExt64_1.dll not found in PATH') else: return True return False return True
def check_cub_version(compiler, settings): global _cub_version global _cub_path # This is guaranteed to work for any CUB source because the search # precedence follows that of include paths. # - On CUDA, CUB < 1.9.9 does not provide version.cuh and would error out # - On ROCm, hipCUB has the same version as rocPRIM (as of ROCm 3.5.0) try: out = build_and_run(compiler, ''' #ifndef CUPY_USE_HIP #include <cub/version.cuh> #else #include <hipcub/hipcub_version.hpp> #endif #include <stdio.h> int main() { #ifndef CUPY_USE_HIP printf("%d", CUB_VERSION); #else printf("%d", HIPCUB_VERSION); #endif return 0; }''', include_dirs=settings['include_dirs'], define_macros=settings['define_macros']) except Exception as e: # could be in a git submodule? try: # CuPy's bundle cupy_cub_include = _cub_path a = subprocess.run(' '.join(['git', 'describe', '--tags']), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=cupy_cub_include) if a.returncode == 0: tag = a.stdout.decode()[:-1] # CUB's tag convention changed after 1.8.0: "v1.9.0" -> "1.9.0" # In any case, we normalize it to be in line with CUB_VERSION if tag.startswith('v'): tag = tag[1:] tag = tag.split('.') out = int(tag[0]) * 100000 + int(tag[1]) * 100 try: out += int(tag[2]) except ValueError: # there're local commits so tag is like 1.8.0-1-gdcbb288f, # we add the number of commits to the version local_patch = tag[2].split('-') out += int(local_patch[0]) + int(local_patch[1]) else: raise RuntimeError('Cannot determine CUB version from git tag' '\n{0}'.format(e)) except Exception as e: utils.print_warning('Cannot determine CUB version\n{0}'.format(e)) # 0: CUB is not built (makes no sense), -1: built with unknown ver out = -1 _cub_version = int(out) settings['define_macros'].append(('CUPY_CUB_VERSION_CODE', _cub_version)) return True # we always build CUB