From 7eb34751d7fb4a50fac992ad347b025aac8ee64b Mon Sep 17 00:00:00 2001 From: Jingyue Wu Date: Wed, 1 Feb 2017 22:17:39 -0800 Subject: [PATCH] CudaRoot() returns the configured CUDA toolkit path. Fixes the problem of XLA being unable to find libdevice files if not executed through bazel. For example, http://stackoverflow.com/questions/41729019/notfounderror-running-tensorflow-xla-example-libdevice-compute-35-10-bc/41800414#41800414 Change: 146329331 --- .../contrib/cmake/tf_core_framework.cmake | 6 ++++++ tensorflow/contrib/makefile/Makefile | 2 ++ tensorflow/core/BUILD | 1 + .../core/platform/default/build_config.bzl | 4 ++-- .../platform/default/cuda_libdevice_path.cc | 21 +++++-------------- third_party/gpus/cuda/cuda_config.h.tpl | 2 ++ third_party/gpus/cuda_configure.bzl | 2 ++ 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/tensorflow/contrib/cmake/tf_core_framework.cmake b/tensorflow/contrib/cmake/tf_core_framework.cmake index d5e02056c4e..72b8b997ace 100644 --- a/tensorflow/contrib/cmake/tf_core_framework.cmake +++ b/tensorflow/contrib/cmake/tf_core_framework.cmake @@ -129,6 +129,12 @@ file(GLOB tf_core_platform_srcs "${tensorflow_source_dir}/tensorflow/core/platform/*.cc" "${tensorflow_source_dir}/tensorflow/core/platform/default/*.h" "${tensorflow_source_dir}/tensorflow/core/platform/default/*.cc") +if (NOT tensorflow_ENABLE_GPU) + file(GLOB tf_core_platform_gpu_srcs + "${tensorflow_source_dir}/tensorflow/core/platform/cuda_libdevice_path.*" + "${tensorflow_source_dir}/tensorflow/core/platform/default/cuda_libdevice_path.*") + list(REMOVE_ITEM tf_core_platform_srcs ${tf_core_platform_gpu_srcs}) +endif() list(APPEND tf_core_lib_srcs ${tf_core_platform_srcs}) if(UNIX) diff --git a/tensorflow/contrib/makefile/Makefile b/tensorflow/contrib/makefile/Makefile index aa3a39da305..2e38905dcea 100644 --- a/tensorflow/contrib/makefile/Makefile +++ b/tensorflow/contrib/makefile/Makefile @@ -458,9 +458,11 @@ $(wildcard tensorflow/core/lib/jpeg/*) \ $(wildcard tensorflow/core/lib/png/*) \ $(wildcard tensorflow/core/util/events_writer.*) \ $(wildcard tensorflow/core/util/reporter.*) \ +$(wildcard tensorflow/core/platform/default/cuda_libdevice_path.*) \ $(wildcard tensorflow/core/platform/default/stream_executor.*) \ $(wildcard tensorflow/core/platform/default/test_benchmark.*) \ $(wildcard tensorflow/core/platform/cuda.h) \ +$(wildcard tensorflow/core/platform/cuda_libdevice_path.*) \ $(wildcard tensorflow/core/platform/cloud/*) \ $(wildcard tensorflow/core/platform/google/*) \ $(wildcard tensorflow/core/platform/google/*/*) \ diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index 620d5d00270..aed6cec605c 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -781,6 +781,7 @@ filegroup( "lib/gif/**/*", "util/events_writer.*", "util/reporter.*", + "platform/**/cuda_libdevice_path.*", "platform/default/stream_executor.*", "platform/default/test_benchmark.*", "platform/cuda.h", diff --git a/tensorflow/core/platform/default/build_config.bzl b/tensorflow/core/platform/default/build_config.bzl index 09bbda63874..48ef8dfa8d4 100644 --- a/tensorflow/core/platform/default/build_config.bzl +++ b/tensorflow/core/platform/default/build_config.bzl @@ -152,10 +152,10 @@ def tf_additional_cupti_wrapper_deps(): return ["//tensorflow/core/platform/default/gpu:cupti_wrapper"] def tf_additional_libdevice_data(): - return ["@local_config_cuda//cuda:libdevice_root"] + return [] def tf_additional_libdevice_deps(): - return [] + return ["@local_config_cuda//cuda:cuda_headers"] def tf_additional_libdevice_srcs(): return ["platform/default/cuda_libdevice_path.cc"] diff --git a/tensorflow/core/platform/default/cuda_libdevice_path.cc b/tensorflow/core/platform/default/cuda_libdevice_path.cc index 2587ad897ef..20ee3ad621a 100644 --- a/tensorflow/core/platform/default/cuda_libdevice_path.cc +++ b/tensorflow/core/platform/default/cuda_libdevice_path.cc @@ -17,27 +17,16 @@ limitations under the License. #include -#include "tensorflow/core/lib/io/path.h" -#include "tensorflow/core/lib/strings/strcat.h" -#include "tensorflow/core/platform/env.h" +#if !defined(PLATFORM_GOOGLE) +#include "cuda/cuda_config.h" +#endif #include "tensorflow/core/platform/logging.h" namespace tensorflow { string CudaRoot() { - // 'bazel test' sets TEST_SRCDIR. - const string kRelativeCudaRoot = io::JoinPath("local_config_cuda", "cuda"); - const char* test_srcdir = getenv("TEST_SRCDIR"); - if (test_srcdir && test_srcdir[0] != '\0') { - return io::JoinPath(test_srcdir, kRelativeCudaRoot); - } - - LOG(INFO) << "TEST_SRCDIR environment variable not set: using " - << kRelativeCudaRoot - << " under this executable's runfiles directory as the CUDA root."; - return io::JoinPath( - strings::StrCat(Env::Default()->GetExecutablePath(), ".runfiles"), - kRelativeCudaRoot); + VLOG(3) << "CUDA root = " << TF_CUDA_TOOLKIT_PATH; + return TF_CUDA_TOOLKIT_PATH; } } // namespace tensorflow diff --git a/third_party/gpus/cuda/cuda_config.h.tpl b/third_party/gpus/cuda/cuda_config.h.tpl index ea51fbb26f0..811b040e8c1 100644 --- a/third_party/gpus/cuda/cuda_config.h.tpl +++ b/third_party/gpus/cuda/cuda_config.h.tpl @@ -21,4 +21,6 @@ limitations under the License. #define TF_CUDA_VERSION "%{cuda_version}" #define TF_CUDNN_VERSION "%{cudnn_version}" +#define TF_CUDA_TOOLKIT_PATH "%{cuda_toolkit_path}" + #endif // CUDA_CUDA_CONFIG_H_ diff --git a/third_party/gpus/cuda_configure.bzl b/third_party/gpus/cuda_configure.bzl index c94f67bc947..1edc76ec7e8 100644 --- a/third_party/gpus/cuda_configure.bzl +++ b/third_party/gpus/cuda_configure.bzl @@ -700,6 +700,7 @@ def _create_dummy_repository(repository_ctx): "%{cuda_compute_capabilities}": ",".join([ "CudaVersion(\"%s\")" % c for c in _DEFAULT_CUDA_COMPUTE_CAPABILITIES]), + "%{cuda_toolkit_path}": _DEFAULT_CUDA_TOOLKIT_PATH, }) # If cuda_configure is not configured to build with GPU support, and the user @@ -802,6 +803,7 @@ def _create_cuda_repository(repository_ctx): "%{cuda_compute_capabilities}": ",".join( ["CudaVersion(\"%s\")" % c for c in cuda_config.compute_capabilities]), + "%{cuda_toolkit_path}": cuda_config.cuda_toolkit_path, })