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
This commit is contained in:
Hong Xu
2019-11-06 07:09:08 -08:00
committed by Facebook Github Bot
parent bc91e19861
commit ff9d508b88
3 changed files with 6 additions and 49 deletions

View File

@ -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

View File

@ -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,
})

View File

@ -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