mirror of
https://github.com/zebrajr/tensorflow.git
synced 2026-01-15 12:15:41 +00:00
Suggest default CUDA/cuDNN/TensorRT versions after initial auto-detection.
Reduce spew on error message when some file was not found. PiperOrigin-RevId: 243810113
This commit is contained in:
committed by
TensorFlower Gardener
parent
651b0bcbbc
commit
0cb8a070d9
30
configure.py
30
configure.py
@@ -33,6 +33,9 @@ except ImportError:
|
|||||||
from distutils.spawn import find_executable as which
|
from distutils.spawn import find_executable as which
|
||||||
# pylint: enable=g-import-not-at-top
|
# pylint: enable=g-import-not-at-top
|
||||||
|
|
||||||
|
_DEFAULT_CUDA_VERSION = '10'
|
||||||
|
_DEFAULT_CUDNN_VERSION = '7'
|
||||||
|
_DEFAULT_TENSORRT_VERSION = '5'
|
||||||
_DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,7.0'
|
_DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,7.0'
|
||||||
|
|
||||||
_TF_OPENCL_VERSION = '1.2'
|
_TF_OPENCL_VERSION = '1.2'
|
||||||
@@ -865,21 +868,25 @@ def set_tf_cuda_paths(environ_cp):
|
|||||||
|
|
||||||
def set_tf_cuda_version(environ_cp):
|
def set_tf_cuda_version(environ_cp):
|
||||||
"""Set TF_CUDA_VERSION."""
|
"""Set TF_CUDA_VERSION."""
|
||||||
ask_cuda_version = ('Please specify the CUDA SDK version you want to use. '
|
ask_cuda_version = (
|
||||||
'[Leave empty to accept any version]: ')
|
'Please specify the CUDA SDK version you want to use. '
|
||||||
|
'[Leave empty to default to CUDA %s]: ') % _DEFAULT_CUDA_VERSION
|
||||||
tf_cuda_version = get_from_env_or_user_or_default(environ_cp,
|
tf_cuda_version = get_from_env_or_user_or_default(environ_cp,
|
||||||
'TF_CUDA_VERSION',
|
'TF_CUDA_VERSION',
|
||||||
ask_cuda_version, '')
|
ask_cuda_version,
|
||||||
|
_DEFAULT_CUDA_VERSION)
|
||||||
environ_cp['TF_CUDA_VERSION'] = tf_cuda_version
|
environ_cp['TF_CUDA_VERSION'] = tf_cuda_version
|
||||||
|
|
||||||
|
|
||||||
def set_tf_cudnn_version(environ_cp):
|
def set_tf_cudnn_version(environ_cp):
|
||||||
"""Set TF_CUDNN_VERSION."""
|
"""Set TF_CUDNN_VERSION."""
|
||||||
ask_cudnn_version = ('Please specify the cuDNN version you want to use. '
|
ask_cudnn_version = (
|
||||||
'[Leave empty to accept any version]: ')
|
'Please specify the cuDNN version you want to use. '
|
||||||
|
'[Leave empty to default to cuDNN %s]: ') % _DEFAULT_CUDNN_VERSION
|
||||||
tf_cudnn_version = get_from_env_or_user_or_default(environ_cp,
|
tf_cudnn_version = get_from_env_or_user_or_default(environ_cp,
|
||||||
'TF_CUDNN_VERSION',
|
'TF_CUDNN_VERSION',
|
||||||
ask_cudnn_version, '')
|
ask_cudnn_version,
|
||||||
|
_DEFAULT_CUDNN_VERSION)
|
||||||
environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version
|
environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version
|
||||||
|
|
||||||
|
|
||||||
@@ -922,11 +929,10 @@ def set_tf_tensorrt_version(environ_cp):
|
|||||||
|
|
||||||
ask_tensorrt_version = (
|
ask_tensorrt_version = (
|
||||||
'Please specify the TensorRT version you want to use. '
|
'Please specify the TensorRT version you want to use. '
|
||||||
'[Leave empty to accept any version]: ')
|
'[Leave empty to default to TensorRT %s]: ') % _DEFAULT_TENSORRT_VERSION
|
||||||
tf_tensorrt_version = get_from_env_or_user_or_default(environ_cp,
|
tf_tensorrt_version = get_from_env_or_user_or_default(
|
||||||
'TF_TENSORRT_VERSION',
|
environ_cp, 'TF_TENSORRT_VERSION', ask_tensorrt_version,
|
||||||
ask_tensorrt_version,
|
_DEFAULT_TENSORRT_VERSION)
|
||||||
'')
|
|
||||||
environ_cp['TF_TENSORRT_VERSION'] = tf_tensorrt_version
|
environ_cp['TF_TENSORRT_VERSION'] = tf_tensorrt_version
|
||||||
|
|
||||||
|
|
||||||
@@ -1331,7 +1337,7 @@ def validate_cuda_config(environ_cp):
|
|||||||
|
|
||||||
if proc.wait():
|
if proc.wait():
|
||||||
# Errors from find_cuda_config.py were sent to stderr.
|
# Errors from find_cuda_config.py were sent to stderr.
|
||||||
print('\n\nAsking for detailed CUDA configuration...\n')
|
print('Asking for detailed CUDA configuration...\n')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
config = dict(
|
config = dict(
|
||||||
|
|||||||
72
third_party/gpus/find_cuda_config.py
vendored
72
third_party/gpus/find_cuda_config.py
vendored
@@ -139,7 +139,7 @@ def _get_ld_config_paths():
|
|||||||
match = pattern.match(line.decode("ascii"))
|
match = pattern.match(line.decode("ascii"))
|
||||||
if match:
|
if match:
|
||||||
result.add(os.path.dirname(match.group(1)))
|
result.add(os.path.dirname(match.group(1)))
|
||||||
return list(result)
|
return sorted(list(result))
|
||||||
|
|
||||||
|
|
||||||
def _get_default_cuda_paths(cuda_version):
|
def _get_default_cuda_paths(cuda_version):
|
||||||
@@ -155,42 +155,47 @@ def _get_default_cuda_paths(cuda_version):
|
|||||||
"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v%s\\" %
|
"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v%s\\" %
|
||||||
cuda_version)
|
cuda_version)
|
||||||
]
|
]
|
||||||
return ["/usr/local/cuda-%s" % cuda_version, "/usr"] + _get_ld_config_paths()
|
return ["/usr/local/cuda-%s" % cuda_version, "/usr/local/cuda", "/usr"
|
||||||
|
] + _get_ld_config_paths()
|
||||||
|
|
||||||
|
|
||||||
def _header_paths(base_paths):
|
def _header_paths():
|
||||||
return _cartesian_product(base_paths, [
|
"""Returns hard-coded set of relative paths to look for header files."""
|
||||||
|
return [
|
||||||
"",
|
"",
|
||||||
"include",
|
"include",
|
||||||
"include/cuda",
|
"include/cuda",
|
||||||
"include/*-linux-gnu",
|
"include/*-linux-gnu",
|
||||||
"extras/CUPTI/include",
|
"extras/CUPTI/include",
|
||||||
"include/cuda/CUPTI",
|
"include/cuda/CUPTI",
|
||||||
])
|
]
|
||||||
|
|
||||||
|
|
||||||
def _library_paths(base_paths):
|
def _library_paths():
|
||||||
return _cartesian_product(base_paths, [
|
"""Returns hard-coded set of relative paths to look for library files."""
|
||||||
|
return [
|
||||||
"",
|
"",
|
||||||
"lib64",
|
"lib64",
|
||||||
"lib",
|
"lib",
|
||||||
"lib/*-linux-gnu",
|
"lib/*-linux-gnu",
|
||||||
"lib/x64",
|
"lib/x64",
|
||||||
"extras/CUPTI/*",
|
"extras/CUPTI/*",
|
||||||
])
|
]
|
||||||
|
|
||||||
|
|
||||||
def _not_found_error(paths, filepattern):
|
def _not_found_error(base_paths, relative_paths, filepattern):
|
||||||
|
base_paths = "".join(["\n '%s'" % path for path in sorted(base_paths)])
|
||||||
|
relative_paths = "".join(["\n '%s'" % path for path in relative_paths])
|
||||||
return ConfigError(
|
return ConfigError(
|
||||||
"Could not find any %s in:%s\n" %
|
"Could not find any %s in any subdirectory:%s\nof:%s\n" %
|
||||||
(filepattern, "".join(["\n %s" % path for path in sorted(paths)])))
|
(filepattern, relative_paths, base_paths))
|
||||||
|
|
||||||
|
|
||||||
def _find_file(paths, filepattern):
|
def _find_file(base_paths, relative_paths, filepattern):
|
||||||
for path in paths:
|
for path in _cartesian_product(base_paths, relative_paths):
|
||||||
for file in glob.glob(os.path.join(path, filepattern)):
|
for file in glob.glob(os.path.join(path, filepattern)):
|
||||||
return file
|
return file
|
||||||
raise _not_found_error(paths, filepattern)
|
raise _not_found_error(base_paths, relative_paths, filepattern)
|
||||||
|
|
||||||
|
|
||||||
def _find_library(base_paths, library_name, required_version):
|
def _find_library(base_paths, library_name, required_version):
|
||||||
@@ -203,24 +208,26 @@ def _find_library(base_paths, library_name, required_version):
|
|||||||
else:
|
else:
|
||||||
filepattern = ".".join(["lib" + library_name, "so"] +
|
filepattern = ".".join(["lib" + library_name, "so"] +
|
||||||
required_version.split(".")[:1]) + "*"
|
required_version.split(".")[:1]) + "*"
|
||||||
return _find_file(_library_paths(base_paths), filepattern)
|
return _find_file(base_paths, _library_paths(), filepattern)
|
||||||
|
|
||||||
|
|
||||||
def _find_versioned_file(paths, filepattern, required_version, get_version):
|
def _find_versioned_file(base_paths, relative_paths, filepattern,
|
||||||
|
required_version, get_version):
|
||||||
"""Returns first valid path to a file that matches the requested version."""
|
"""Returns first valid path to a file that matches the requested version."""
|
||||||
for path in paths:
|
for path in _cartesian_product(base_paths, relative_paths):
|
||||||
for file in glob.glob(os.path.join(path, filepattern)):
|
for file in glob.glob(os.path.join(path, filepattern)):
|
||||||
actual_version = get_version(file)
|
actual_version = get_version(file)
|
||||||
if _matches_version(actual_version, required_version):
|
if _matches_version(actual_version, required_version):
|
||||||
return file, actual_version
|
return file, actual_version
|
||||||
raise _not_found_error(
|
raise _not_found_error(
|
||||||
paths, filepattern + " matching version '%s'" % required_version)
|
base_paths, relative_paths,
|
||||||
|
filepattern + " matching version '%s'" % required_version)
|
||||||
|
|
||||||
|
|
||||||
def _find_header(base_paths, header_name, required_version, get_version):
|
def _find_header(base_paths, header_name, required_version, get_version):
|
||||||
"""Returns first valid path to a header that matches the requested version."""
|
"""Returns first valid path to a header that matches the requested version."""
|
||||||
return _find_versioned_file(
|
return _find_versioned_file(base_paths, _header_paths(), header_name,
|
||||||
_header_paths(base_paths), header_name, required_version, get_version)
|
required_version, get_version)
|
||||||
|
|
||||||
|
|
||||||
def _find_cuda_config(base_paths, required_version):
|
def _find_cuda_config(base_paths, required_version):
|
||||||
@@ -247,20 +254,18 @@ def _find_cuda_config(base_paths, required_version):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
nvcc_name = "nvcc.exe" if _is_windows() else "nvcc"
|
nvcc_name = "nvcc.exe" if _is_windows() else "nvcc"
|
||||||
nvcc_path, nvcc_version = _find_versioned_file(
|
nvcc_path, nvcc_version = _find_versioned_file(base_paths, [
|
||||||
_cartesian_product(base_paths, [
|
"",
|
||||||
"",
|
"bin",
|
||||||
"bin",
|
], nvcc_name, cuda_version, get_nvcc_version)
|
||||||
]), nvcc_name, cuda_version, get_nvcc_version)
|
|
||||||
|
|
||||||
nvvm_path = _find_file(
|
nvvm_path = _find_file(base_paths, [
|
||||||
_cartesian_product(base_paths, [
|
"nvvm/libdevice",
|
||||||
"nvvm/libdevice",
|
"share/cuda",
|
||||||
"share/cuda",
|
"lib/nvidia-cuda-toolkit/libdevice",
|
||||||
"lib/nvidia-cuda-toolkit/libdevice",
|
], "libdevice*.10.bc")
|
||||||
]), "libdevice*.10.bc")
|
|
||||||
|
|
||||||
cupti_header_path = _find_file(_header_paths(base_paths), "cupti.h")
|
cupti_header_path = _find_file(base_paths, _header_paths(), "cupti.h")
|
||||||
cupti_library_path = _find_library(base_paths, "cupti", required_version)
|
cupti_library_path = _find_library(base_paths, "cupti", required_version)
|
||||||
|
|
||||||
cuda_binary_dir = os.path.dirname(nvcc_path)
|
cuda_binary_dir = os.path.dirname(nvcc_path)
|
||||||
@@ -311,7 +316,7 @@ def _find_cublas_config(base_paths, required_version, cuda_version):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
# There is no version info available before CUDA 10.1, just find the file.
|
# There is no version info available before CUDA 10.1, just find the file.
|
||||||
header_path = _find_file(_header_paths(base_paths), "cublas_api.h")
|
header_path = _find_file(base_paths, _header_paths(), "cublas_api.h")
|
||||||
# cuBLAS version is the same as CUDA version (x.y).
|
# cuBLAS version is the same as CUDA version (x.y).
|
||||||
cublas_version = required_version
|
cublas_version = required_version
|
||||||
|
|
||||||
@@ -411,6 +416,7 @@ def find_cuda_config():
|
|||||||
cuda_version = os.environ.get("TF_CUDA_VERSION", "")
|
cuda_version = os.environ.get("TF_CUDA_VERSION", "")
|
||||||
base_paths = _list_from_env("TF_CUDA_PATHS",
|
base_paths = _list_from_env("TF_CUDA_PATHS",
|
||||||
_get_default_cuda_paths(cuda_version))
|
_get_default_cuda_paths(cuda_version))
|
||||||
|
base_paths = [path for path in base_paths if os.path.exists(path)]
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
if "cuda" in libraries:
|
if "cuda" in libraries:
|
||||||
|
|||||||
Reference in New Issue
Block a user