Add a resoure loader library to load bazel data dependencies
PiperOrigin-RevId: 292490959 Change-Id: I0d2c7ba7574ef793499c4bd715de6da241f0467b
This commit is contained in:
parent
aff75e8303
commit
d9386b21c8
tensorflow/core/platform
@ -85,6 +85,7 @@ exports_files(
|
||||
"mutex.h",
|
||||
"net.h",
|
||||
"numa.h",
|
||||
"resource_loader.h",
|
||||
"snappy.h",
|
||||
"stacktrace_handler.h",
|
||||
"subprocess.h",
|
||||
@ -513,6 +514,13 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "resource_loader",
|
||||
testonly = 1,
|
||||
textual_hdrs = ["resource_loader.h"],
|
||||
deps = tf_platform_deps("resource_loader"),
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rocm_rocdl_path",
|
||||
textual_hdrs = ["rocm_rocdl_path.h"],
|
||||
@ -907,6 +915,22 @@ tf_cc_test(
|
||||
],
|
||||
)
|
||||
|
||||
tf_cc_test(
|
||||
name = "resource_loader_test",
|
||||
size = "small",
|
||||
srcs = ["resource_loader_test.cc"],
|
||||
data = [
|
||||
":resource_loader.h",
|
||||
],
|
||||
deps = [
|
||||
":resource_loader",
|
||||
":status",
|
||||
"//tensorflow/core:lib",
|
||||
"//tensorflow/core:test",
|
||||
"//tensorflow/core:test_main",
|
||||
],
|
||||
)
|
||||
|
||||
tf_cc_test(
|
||||
name = "ctstring_test",
|
||||
size = "small",
|
||||
|
@ -299,6 +299,22 @@ cc_library(
|
||||
}),
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "resource_loader",
|
||||
testonly = 1,
|
||||
srcs = ["resource_loader.cc"],
|
||||
hdrs = ["//tensorflow/core/platform:resource_loader.h"],
|
||||
tags = [
|
||||
"manual",
|
||||
"no_oss",
|
||||
"nobuilder",
|
||||
],
|
||||
deps = [
|
||||
"//tensorflow/core/platform:logging",
|
||||
"@bazel_tools//tools/cpp/runfiles",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "rocm_rocdl_path",
|
||||
srcs = ["rocm_rocdl_path.cc"],
|
||||
|
37
tensorflow/core/platform/default/resource_loader.cc
Normal file
37
tensorflow/core/platform/default/resource_loader.cc
Normal file
@ -0,0 +1,37 @@
|
||||
/* Copyright 2020 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/resource_loader.h"
|
||||
|
||||
#include "tensorflow/core/platform/logging.h"
|
||||
#include "tools/cpp/runfiles/runfiles.h"
|
||||
|
||||
using bazel::tools::cpp::runfiles::Runfiles;
|
||||
|
||||
namespace tensorflow {
|
||||
|
||||
std::string GetDataDependencyFilepath(const std::string& relative_path) {
|
||||
std::string error;
|
||||
std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest(&error));
|
||||
|
||||
if (runfiles == nullptr) {
|
||||
LOG(FATAL) << "Unable to access the data dependencies of this test.\n"
|
||||
"Make sure you are running this test using bazel.";
|
||||
}
|
||||
string root_dir = "org_tensorflow/";
|
||||
return runfiles->Rlocation(root_dir + relative_path);
|
||||
}
|
||||
|
||||
} // namespace tensorflow
|
32
tensorflow/core/platform/resource_loader.h
Normal file
32
tensorflow/core/platform/resource_loader.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* Copyright 2020 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.
|
||||
==============================================================================*/
|
||||
|
||||
// Small helper library to access "data" dependencies defined in BUILD files.
|
||||
// Requires the relative paths starting from tensorflow/...
|
||||
// For example, to get this file, a user would call:
|
||||
// GetDataDependencyFilepath("tensorflow/core/platform/resource_loadder.h")
|
||||
|
||||
#ifndef TENSORFLOW_CORE_PLATFORM_RESOURCE_LOADER_H_
|
||||
#define TENSORFLOW_CORE_PLATFORM_RESOURCE_LOADER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace tensorflow {
|
||||
|
||||
std::string GetDataDependencyFilepath(const std::string& relative_path);
|
||||
|
||||
} // namespace tensorflow
|
||||
|
||||
#endif // TENSORFLOW_CORE_PLATFORM_RESOURCE_LOADER_H_
|
33
tensorflow/core/platform/resource_loader_test.cc
Normal file
33
tensorflow/core/platform/resource_loader_test.cc
Normal file
@ -0,0 +1,33 @@
|
||||
/* Copyright 2020 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/resource_loader.h"
|
||||
|
||||
#include "tensorflow/core/platform/env.h"
|
||||
#include "tensorflow/core/platform/logging.h"
|
||||
#include "tensorflow/core/platform/status.h"
|
||||
#include "tensorflow/core/platform/test.h"
|
||||
|
||||
namespace tensorflow {
|
||||
|
||||
const char kDataDependencyPath[] = "tensorflow/core/platform/resource_loader.h";
|
||||
|
||||
TEST(ResourceLoaderTest, FindsAndOpensFile) {
|
||||
string filepath = GetDataDependencyFilepath(kDataDependencyPath);
|
||||
Status s = Env::Default()->FileExists(filepath);
|
||||
EXPECT_TRUE(s.ok()) << "No file found at this location: " << filepath;
|
||||
}
|
||||
|
||||
} // namespace tensorflow
|
Loading…
Reference in New Issue
Block a user