From b2bcf5f75e5f83fe977cba12fdf764c5a2d76159 Mon Sep 17 00:00:00 2001 From: Jingyue Wu Date: Tue, 6 Dec 2016 15:39:11 -0800 Subject: [PATCH] Locate libdevice files for OSS build. 1. Created open-source target libdevice_root that wraps all libdevice files. 2. platform/posix/cuda_libdevice_path depends on the libdevice_root target. 3. Added cuda_libdevice_path_test that verifies libdevice files exist in the computed libdevice directory. Change: 141237087 --- tensorflow/core/BUILD | 14 ++++++++ .../core/platform/cuda_libdevice_path_test.cc | 36 +++++++++++++++++++ .../core/platform/default/build_config.bzl | 2 +- .../platform/default/cuda_libdevice_path.cc | 17 +++++++-- third_party/gpus/cuda/BUILD.tpl | 6 ++++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 tensorflow/core/platform/cuda_libdevice_path_test.cc diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index 429d123dea6..9d00a248df3 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -1802,6 +1802,20 @@ tf_cc_tests_gpu( ], ) +tf_cc_test_gpu( + name = "cuda_libdevice_path_test", + size = "small", + srcs = ["platform/cuda_libdevice_path_test.cc"], + linkstatic = tf_kernel_tests_linkstatic(), + tags = tf_cuda_tests_tags(), + deps = [ + ":cuda_libdevice_path", + ":lib", + ":test", + ":test_main", + ], +) + tf_cc_test_gpu( name = "memory_types_test", size = "small", diff --git a/tensorflow/core/platform/cuda_libdevice_path_test.cc b/tensorflow/core/platform/cuda_libdevice_path_test.cc new file mode 100644 index 00000000000..86295592a8b --- /dev/null +++ b/tensorflow/core/platform/cuda_libdevice_path_test.cc @@ -0,0 +1,36 @@ +/* Copyright 2016 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/core/platform/cuda_libdevice_path.h" + +#include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/platform/env.h" +#include "tensorflow/core/platform/test.h" + +namespace tensorflow { + +#if GOOGLE_CUDA +TEST(CudaLibdevicePathTest, LibdevicePath) { + VLOG(2) << "Libdevice root = " << LibdeviceRoot(); + std::vector libdevice_files; + TF_EXPECT_OK(Env::Default()->GetMatchingPaths( + io::JoinPath(LibdeviceRoot(), "libdevice.compute_*.bc"), + &libdevice_files)); + EXPECT_LT(0, libdevice_files.size()); +} +#endif + +} // namespace tensorflow diff --git a/tensorflow/core/platform/default/build_config.bzl b/tensorflow/core/platform/default/build_config.bzl index 6b20665ce5d..64a6ab0c7a8 100644 --- a/tensorflow/core/platform/default/build_config.bzl +++ b/tensorflow/core/platform/default/build_config.bzl @@ -143,7 +143,7 @@ def tf_additional_cupti_wrapper_deps(): return ["//tensorflow/core/platform/default/gpu:cupti_wrapper"] def tf_additional_libdevice_data(): - return [] + return ["@local_config_cuda//cuda:libdevice_root"] def tf_additional_libdevice_deps(): return [] diff --git a/tensorflow/core/platform/default/cuda_libdevice_path.cc b/tensorflow/core/platform/default/cuda_libdevice_path.cc index c5edb777376..38fc0aba96a 100644 --- a/tensorflow/core/platform/default/cuda_libdevice_path.cc +++ b/tensorflow/core/platform/default/cuda_libdevice_path.cc @@ -15,11 +15,24 @@ limitations under the License. #include "tensorflow/core/platform/cuda_libdevice_path.h" +#include + +#include "tensorflow/core/lib/strings/strcat.h" +#include "tensorflow/core/platform/default/logging.h" + namespace tensorflow { string CudaRoot() { - // TODO(b/33147798): Compute the CUDA root for open-source build. - return "."; + // 'bazel test' sets TEST_SRCDIR. + const string kRelativeCudaRoot = "local_config_cuda/cuda"; + const char* env = getenv("TEST_SRCDIR"); + if (env && env[0] != '\0') { + return strings::StrCat(env, "/", kRelativeCudaRoot); + } else { + LOG(WARNING) << "TEST_SRCDIR environment variable not set: " + << "using $PWD/" << kRelativeCudaRoot << "as the CUDA root."; + return kRelativeCudaRoot; + } } } // namespace tensorflow diff --git a/third_party/gpus/cuda/BUILD.tpl b/third_party/gpus/cuda/BUILD.tpl index cb985c22512..d3c307a6a08 100644 --- a/third_party/gpus/cuda/BUILD.tpl +++ b/third_party/gpus/cuda/BUILD.tpl @@ -160,3 +160,9 @@ cc_library( ], visibility = ["//visibility:public"], ) + +cc_library( + name = "libdevice_root", + data = glob(["nvvm/libdevice/*.bc"]), + visibility = ["//visibility:public"], +)