From ff9d508b8858755a19b4e6235bf30558c5aa5f2e Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Wed, 6 Nov 2019 07:09:08 -0800 Subject: [PATCH] Remove tools/setup_helpers/cuda.py. (#28617) Summary: Except for the Windows default path, everything it does has been done in FindCUDA.cmake. Search for nvcc in path has been added to FindCUDA.cmake (https://github.com/pytorch/pytorch/issues/29160). The Windows default path part is moved to build_pytorch_libs.py. CUDA_HOME is kept for now because other parts of the build system is still using it. Pull Request resolved: https://github.com/pytorch/pytorch/pull/28617 Differential Revision: D18347814 Pulled By: ezyang fbshipit-source-id: 22bb7eccc17b559ce3efc1ca964e3fbb270b5b0f --- tools/build_pytorch_libs.py | 9 +++++--- tools/setup_helpers/cmake.py | 2 -- tools/setup_helpers/cuda.py | 44 ------------------------------------ 3 files changed, 6 insertions(+), 49 deletions(-) delete mode 100644 tools/setup_helpers/cuda.py diff --git a/tools/build_pytorch_libs.py b/tools/build_pytorch_libs.py index 9947ea71d3b..e5f85df64a8 100644 --- a/tools/build_pytorch_libs.py +++ b/tools/build_pytorch_libs.py @@ -5,7 +5,6 @@ import shutil from .setup_helpers.env import IS_64BIT, IS_WINDOWS, check_negative_env_flag from .setup_helpers.cmake import USE_NINJA -from .setup_helpers.cuda import USE_CUDA, CUDA_HOME def _overlay_windows_vcvars(env): @@ -33,8 +32,12 @@ def _create_build_env(): # you should NEVER add something to this list. It is bad practice to # have cmake read the environment my_env = os.environ.copy() - if USE_CUDA: - my_env['CUDA_BIN_PATH'] = CUDA_HOME + if 'CUDA_HOME' in my_env: # Keep CUDA_HOME. This env variable is still used in other part. + my_env['CUDA_BIN_PATH'] = my_env['CUDA_HOME'] + elif IS_WINDOWS: # we should eventually make this as part of FindCUDA. + cuda_win = glob('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v*.*') + if len(cuda_win) > 0: + my_env['CUDA_BIN_PATH'] = cuda_win[0] if IS_WINDOWS and USE_NINJA: # When using Ninja under Windows, the gcc toolchain will be chosen as diff --git a/tools/setup_helpers/cmake.py b/tools/setup_helpers/cmake.py index 894559ed432..0acbbd0c706 100644 --- a/tools/setup_helpers/cmake.py +++ b/tools/setup_helpers/cmake.py @@ -13,7 +13,6 @@ from distutils.version import LooseVersion from . import which from .env import (BUILD_DIR, IS_64BIT, IS_DARWIN, IS_WINDOWS, check_negative_env_flag) -from .cuda import USE_CUDA from .numpy_ import USE_NUMPY, NUMPY_INCLUDE_DIR @@ -265,7 +264,6 @@ class CMake: # are automatically passed to CMake; For other options you can add to additional_options above. 'BUILD_PYTHON': build_python, 'BUILD_TEST': build_test, - 'USE_CUDA': USE_CUDA, 'USE_NUMPY': USE_NUMPY, }) diff --git a/tools/setup_helpers/cuda.py b/tools/setup_helpers/cuda.py deleted file mode 100644 index 06f549d3d00..00000000000 --- a/tools/setup_helpers/cuda.py +++ /dev/null @@ -1,44 +0,0 @@ -import os -import glob -import ctypes.util - -from . import which -from .env import IS_WINDOWS, IS_LINUX, IS_DARWIN, check_negative_env_flag - -LINUX_HOME = '/usr/local/cuda' -WINDOWS_HOME = glob.glob('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v*.*') - - -def find_nvcc(): - nvcc = which('nvcc') - if nvcc is not None: - return os.path.dirname(nvcc) - else: - return None - - -if check_negative_env_flag('USE_CUDA'): - USE_CUDA = False - CUDA_HOME = None -else: - if IS_LINUX or IS_DARWIN: - CUDA_HOME = os.getenv('CUDA_HOME', LINUX_HOME) - else: - CUDA_HOME = os.getenv('CUDA_PATH', '').replace('\\', '/') - if CUDA_HOME == '' and len(WINDOWS_HOME) > 0: - CUDA_HOME = WINDOWS_HOME[0].replace('\\', '/') - if not os.path.exists(CUDA_HOME): - # We use nvcc path on Linux and cudart path on macOS - if IS_LINUX or IS_WINDOWS: - cuda_path = find_nvcc() - else: - cudart_path = ctypes.util.find_library('cudart') - if cudart_path is not None: - cuda_path = os.path.dirname(cudart_path) - else: - cuda_path = None - if cuda_path is not None: - CUDA_HOME = os.path.dirname(cuda_path) - else: - CUDA_HOME = None - USE_CUDA = CUDA_HOME is not None