Skip to content

Commit

Permalink
Locate libdevice files for OSS build.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jingyue Wu authored and tensorflower-gardener committed Dec 7, 2016
1 parent 008f80e commit b2bcf5f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
14 changes: 14 additions & 0 deletions tensorflow/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 36 additions & 0 deletions tensorflow/core/platform/cuda_libdevice_path_test.cc
Original file line number Diff line number Diff line change
@@ -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<string> 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
2 changes: 1 addition & 1 deletion tensorflow/core/platform/default/build_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
17 changes: 15 additions & 2 deletions tensorflow/core/platform/default/cuda_libdevice_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ limitations under the License.

#include "tensorflow/core/platform/cuda_libdevice_path.h"

#include <stdlib.h>

#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
6 changes: 6 additions & 0 deletions third_party/gpus/cuda/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,9 @@ cc_library(
],
visibility = ["//visibility:public"],
)

cc_library(
name = "libdevice_root",
data = glob(["nvvm/libdevice/*.bc"]),
visibility = ["//visibility:public"],
)

0 comments on commit b2bcf5f

Please sign in to comment.