Replace references to tensorflow::StringPiece with absl::string_view. No functional changes.

PiperOrigin-RevId: 217170781
This commit is contained in:
Peter Hawkins 2018-10-15 10:55:40 -07:00 committed by TensorFlower Gardener
parent 09c208bd4a
commit 6fa6bd045c
391 changed files with 2459 additions and 1914 deletions
tensorflow
c
cc
compiler
contrib
core

View File

@ -78,10 +78,12 @@ tf_cuda_library(
deps = select({ deps = select({
"//tensorflow:android": [ "//tensorflow:android": [
":c_api_internal", ":c_api_internal",
"@com_google_absl//absl/strings",
"//tensorflow/core:android_tensorflow_lib_lite", "//tensorflow/core:android_tensorflow_lib_lite",
], ],
"//conditions:default": [ "//conditions:default": [
":c_api_internal", ":c_api_internal",
"@com_google_absl//absl/strings",
"//tensorflow/cc/saved_model:loader", "//tensorflow/cc/saved_model:loader",
"//tensorflow/cc:gradients", "//tensorflow/cc:gradients",
"//tensorflow/cc:ops", "//tensorflow/cc:ops",
@ -228,6 +230,7 @@ tf_cuda_cc_test(
"//tensorflow/core/kernels:array", "//tensorflow/core/kernels:array",
"//tensorflow/core/kernels:control_flow_ops", "//tensorflow/core/kernels:control_flow_ops",
"//tensorflow/core/kernels:math", "//tensorflow/core/kernels:math",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -19,6 +19,7 @@ limitations under the License.
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#ifndef __ANDROID__ #ifndef __ANDROID__
#include "tensorflow/cc/framework/gradients.h" #include "tensorflow/cc/framework/gradients.h"
@ -51,7 +52,6 @@ limitations under the License.
#include "tensorflow/core/lib/core/coding.h" #include "tensorflow/core/lib/core/coding.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/lib/gtl/array_slice.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/lib/strings/strcat.h"
@ -120,7 +120,7 @@ void TF_SetStatus(TF_Status* s, TF_Code code, const char* msg) {
s->status = Status::OK(); s->status = Status::OK();
return; return;
} }
s->status = Status(static_cast<Code>(code), tensorflow::StringPiece(msg)); s->status = Status(static_cast<Code>(code), absl::string_view(msg));
} }
TF_Code TF_GetCode(const TF_Status* s) { TF_Code TF_GetCode(const TF_Status* s) {
@ -1160,7 +1160,7 @@ void TF_ColocateWith(TF_OperationDescription* desc, TF_Operation* op) {
void TF_SetAttrString(TF_OperationDescription* desc, const char* attr_name, void TF_SetAttrString(TF_OperationDescription* desc, const char* attr_name,
const void* value, size_t length) { const void* value, size_t length) {
tensorflow::StringPiece s(static_cast<const char*>(value), length); absl::string_view s(static_cast<const char*>(value), length);
desc->node_builder.Attr(attr_name, s); desc->node_builder.Attr(attr_name, s);
} }
@ -1174,7 +1174,7 @@ void TF_SetAttrStringList(TF_OperationDescription* desc, const char* attr_name,
lengths[i]); lengths[i]);
} }
} else { } else {
std::vector<tensorflow::StringPiece> v; std::vector<absl::string_view> v;
v.reserve(num_values); v.reserve(num_values);
for (int i = 0; i < num_values; ++i) { for (int i = 0; i < num_values; ++i) {
v.emplace_back(static_cast<const char*>(values[i]), lengths[i]); v.emplace_back(static_cast<const char*>(values[i]), lengths[i]);

View File

@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "absl/strings/string_view.h"
#include "tensorflow/c/c_api_internal.h" #include "tensorflow/c/c_api_internal.h"
#include <algorithm> #include <algorithm>
@ -324,7 +325,7 @@ Status GraphToFunctionDef(const Graph& fn_body, const string& fn_name,
TF_RETURN_IF_ERROR( TF_RETURN_IF_ERROR(
NameRangesForNode(*node, node->op_def(), nullptr, &output_ranges)); NameRangesForNode(*node, node->op_def(), nullptr, &output_ranges));
for (const auto& output : output_ranges) { for (const auto& output : output_ranges) {
const StringPiece& output_name = output.first; const absl::string_view& output_name = output.first;
int index_start = output.second.first; int index_start = output.second.first;
int index_end = output.second.second; int index_end = output.second.second;
for (int i = index_start; i < index_end; ++i) { for (int i = index_start; i < index_end; ++i) {
@ -364,7 +365,7 @@ Status GraphToFunctionDef(const Graph& fn_body, const string& fn_name,
const uint64 hash = FunctionDefHash(*fdef); const uint64 hash = FunctionDefHash(*fdef);
string encoded; string encoded;
TF_RETURN_IF_ERROR(Base64Encode( TF_RETURN_IF_ERROR(Base64Encode(
StringPiece(reinterpret_cast<const char*>(&hash), sizeof(hash)), absl::string_view(reinterpret_cast<const char*>(&hash), sizeof(hash)),
&encoded)); &encoded));
// Besides letters and digits our Base64 encoding uses '_' and '-'. // Besides letters and digits our Base64 encoding uses '_' and '-'.
// Dash is invalid in operation names and multiple underscores in random // Dash is invalid in operation names and multiple underscores in random

View File

@ -21,6 +21,7 @@ limitations under the License.
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/c/c_test_util.h" #include "tensorflow/c/c_test_util.h"
#include "tensorflow/cc/saved_model/signature_constants.h" #include "tensorflow/cc/saved_model/signature_constants.h"
#include "tensorflow/cc/saved_model/tag_constants.h" #include "tensorflow/cc/saved_model/tag_constants.h"
@ -55,7 +56,7 @@ Status TF_TensorToTensor(const TF_Tensor* src, Tensor* dst);
namespace { namespace {
static void ExpectHasSubstr(StringPiece s, StringPiece expected) { static void ExpectHasSubstr(absl::string_view s, absl::string_view expected) {
EXPECT_TRUE(str_util::StrContains(s, expected)) EXPECT_TRUE(str_util::StrContains(s, expected))
<< "'" << s << "' does not contain '" << expected << "'"; << "'" << s << "' does not contain '" << expected << "'";
} }

View File

@ -50,6 +50,7 @@ tf_cuda_library(
], ],
"//conditions:default": [], "//conditions:default": [],
}) + [ }) + [
"@com_google_absl//absl/strings",
"//tensorflow/core/common_runtime/eager:eager_operation", "//tensorflow/core/common_runtime/eager:eager_operation",
"//tensorflow/core/distributed_runtime/eager:eager_client", "//tensorflow/core/distributed_runtime/eager:eager_client",
"//tensorflow/core/distributed_runtime/rpc/eager:grpc_eager_client", "//tensorflow/core/distributed_runtime/rpc/eager:grpc_eager_client",

View File

@ -21,6 +21,7 @@ limitations under the License.
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/c/c_api.h" #include "tensorflow/c/c_api.h"
#include "tensorflow/c/c_api_internal.h" #include "tensorflow/c/c_api_internal.h"
#include "tensorflow/c/eager/c_api_internal.h" #include "tensorflow/c/eager/c_api_internal.h"
@ -46,7 +47,6 @@ limitations under the License.
#include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/framework/tensor_shape.pb.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/core/refcount.h" #include "tensorflow/core/lib/core/refcount.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/gtl/cleanup.h" #include "tensorflow/core/lib/gtl/cleanup.h"
#include "tensorflow/core/lib/gtl/flatmap.h" #include "tensorflow/core/lib/gtl/flatmap.h"
#include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/gtl/map_util.h"
@ -526,8 +526,7 @@ TF_AttrType TFE_OpNameGetAttrType(TFE_Context* ctx,
void TFE_OpSetAttrString(TFE_Op* op, const char* attr_name, const void* value, void TFE_OpSetAttrString(TFE_Op* op, const char* attr_name, const void* value,
size_t length) { size_t length) {
op->operation.MutableAttrs()->Set( op->operation.MutableAttrs()->Set(
attr_name, attr_name, absl::string_view(static_cast<const char*>(value), length));
tensorflow::StringPiece(static_cast<const char*>(value), length));
} }
void TFE_OpSetAttrInt(TFE_Op* op, const char* attr_name, int64_t value) { void TFE_OpSetAttrInt(TFE_Op* op, const char* attr_name, int64_t value) {
@ -596,10 +595,9 @@ void TFE_OpSetAttrTensor(TFE_Op* op, const char* attr_name, TF_Tensor* tensor,
void TFE_OpSetAttrStringList(TFE_Op* op, const char* attr_name, void TFE_OpSetAttrStringList(TFE_Op* op, const char* attr_name,
const void* const* values, const size_t* lengths, const void* const* values, const size_t* lengths,
int num_values) { int num_values) {
std::vector<tensorflow::StringPiece> v(num_values); std::vector<absl::string_view> v(num_values);
for (int i = 0; i < num_values; ++i) { for (int i = 0; i < num_values; ++i) {
v[i] = tensorflow::StringPiece(static_cast<const char*>(values[i]), v[i] = absl::string_view(static_cast<const char*>(values[i]), lengths[i]);
lengths[i]);
} }
op->operation.MutableAttrs()->Set(attr_name, v); op->operation.MutableAttrs()->Set(attr_name, v);
} }

View File

@ -170,6 +170,7 @@ cc_library_with_android_deps(
"//tensorflow/core:framework", "//tensorflow/core:framework",
"//tensorflow/core:lib", "//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/strings",
], ],
) )
@ -603,6 +604,7 @@ cc_library_with_android_deps(
"//tensorflow/core:op_gen_lib", "//tensorflow/core:op_gen_lib",
"//tensorflow/core:proto_text", "//tensorflow/core:proto_text",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/strings",
], ],
) )
@ -622,6 +624,7 @@ tf_cc_test(
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"//tensorflow/core:test", "//tensorflow/core:test",
"//tensorflow/core:test_main", "//tensorflow/core:test_main",
"@com_google_absl//absl/strings",
], ],
) )
@ -683,6 +686,7 @@ tf_cc_binary(
"//tensorflow/core:lib", "//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"//tensorflow/core:tensorflow", "//tensorflow/core:tensorflow",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/cc/framework/cc_op_gen.h" #include "tensorflow/cc/framework/cc_op_gen.h"
#include "tensorflow/core/framework/api_def.pb.h" #include "tensorflow/core/framework/api_def.pb.h"
#include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/attr_value.pb.h"
@ -107,7 +108,7 @@ string ToTitle(const string& name) {
// ABC /// ABC // ABC /// ABC
// /// // ///
// DEF /// DEF // DEF /// DEF
string MakeComment(StringPiece text, StringPiece indent) { string MakeComment(absl::string_view text, absl::string_view indent) {
string ret; string ret;
while (!text.empty()) { while (!text.empty()) {
int last_non_space = -1; int last_non_space = -1;
@ -302,9 +303,9 @@ string ToCamelCase(const string& str) {
// attr_type when defining an object of that type. The bool is a flag to // attr_type when defining an object of that type. The bool is a flag to
// indicate whether to treat the type as const when accepting the C++ type as an // indicate whether to treat the type as const when accepting the C++ type as an
// argument to a function. // argument to a function.
std::pair<const char*, bool> AttrTypeName(StringPiece attr_type) { std::pair<const char*, bool> AttrTypeName(absl::string_view attr_type) {
static const auto* attr_type_map = static const auto* attr_type_map =
new std::unordered_map<StringPiece, std::pair<const char*, bool>, new std::unordered_map<absl::string_view, std::pair<const char*, bool>,
StringPieceHasher>{ StringPieceHasher>{
{"string", {"StringPiece", false}}, {"string", {"StringPiece", false}},
{"list(string)", {"gtl::ArraySlice<string>", true}}, {"list(string)", {"gtl::ArraySlice<string>", true}},
@ -331,9 +332,9 @@ std::pair<const char*, bool> AttrTypeName(StringPiece attr_type) {
return entry->second; return entry->second;
} }
const char* ListElementTypeName(StringPiece attr_type) { const char* ListElementTypeName(absl::string_view attr_type) {
static const auto* attr_list_type_map = static const auto* attr_list_type_map =
new std::unordered_map<StringPiece, const char*, StringPieceHasher>{ new std::unordered_map<absl::string_view, const char*, StringPieceHasher>{
{"list(string)", "string"}, {"list(string)", "string"},
{"list(int)", "int"}, {"list(int)", "int"},
{"list(float)", "float"}, {"list(float)", "float"},
@ -351,8 +352,8 @@ const char* ListElementTypeName(StringPiece attr_type) {
return entry->second; return entry->second;
} }
bool IsCPPKeyword(StringPiece name) { bool IsCPPKeyword(absl::string_view name) {
static const std::unordered_set<StringPiece, StringPieceHasher> static const std::unordered_set<absl::string_view, StringPieceHasher>
// Keywords obtained from http://en.cppreference.com/w/cpp/keyword // Keywords obtained from http://en.cppreference.com/w/cpp/keyword
kCPPReserved{ kCPPReserved{
"alignas", "alignas",
@ -462,7 +463,7 @@ bool IsCPPKeyword(StringPiece name) {
return kCPPReserved.count(name) > 0; return kCPPReserved.count(name) > 0;
} }
string AvoidCPPKeywords(StringPiece name) { string AvoidCPPKeywords(absl::string_view name) {
if (IsCPPKeyword(name)) { if (IsCPPKeyword(name)) {
return strings::StrCat(name, "_"); return strings::StrCat(name, "_");
} }
@ -516,7 +517,7 @@ struct OpInfo {
explicit OpInfo(const OpDef& graph_op_def, const ApiDef& api_def, explicit OpInfo(const OpDef& graph_op_def, const ApiDef& api_def,
const std::vector<string>& aliases); const std::vector<string>& aliases);
string GetOpAttrStruct() const; string GetOpAttrStruct() const;
string GetConstructorDecl(StringPiece op_name_prefix, string GetConstructorDecl(absl::string_view op_name_prefix,
bool include_attr) const; bool include_attr) const;
void WriteClassDecl(WritableFile* h) const; void WriteClassDecl(WritableFile* h) const;
void GetOutput(string* out) const; void GetOutput(string* out) const;
@ -574,7 +575,7 @@ OpInfo::OpInfo(const OpDef& graph_op_def, const ApiDef& api_def,
arg_names.push_back(AvoidCPPKeywords(api_def_arg.rename_to())); arg_names.push_back(AvoidCPPKeywords(api_def_arg.rename_to()));
// TODO(keveman): Include input type information. // TODO(keveman): Include input type information.
StringPiece description = api_def_arg.description(); absl::string_view description = api_def_arg.description();
if (!description.empty()) { if (!description.empty()) {
ConsumeEquals(&description); ConsumeEquals(&description);
strings::StrAppend(&comment, "* ", strings::StrAppend(&comment, "* ",
@ -768,7 +769,7 @@ string OpInfo::GetOpAttrStruct() const {
return struct_decl; return struct_decl;
} }
string OpInfo::GetConstructorDecl(StringPiece op_name_prefix, string OpInfo::GetConstructorDecl(absl::string_view op_name_prefix,
bool include_attr) const { bool include_attr) const {
const string prefix = strings::StrCat(op_name_prefix, op_name, "("); const string prefix = strings::StrCat(op_name_prefix, op_name, "(");
string c_decl; string c_decl;

View File

@ -13,11 +13,11 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "absl/strings/string_view.h"
#include "tensorflow/cc/framework/cc_op_gen.h" #include "tensorflow/cc/framework/cc_op_gen.h"
#include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/framework/op_def.pb.h"
#include "tensorflow/core/framework/op_gen_lib.h" #include "tensorflow/core/framework/op_gen_lib.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/io/path.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/env.h"
@ -69,7 +69,7 @@ int main(int argc, char* argv[]) {
exit(1); exit(1);
} }
bool include_internal = tensorflow::StringPiece("1") == argv[3]; bool include_internal = absl::string_view("1") == argv[3];
std::vector<tensorflow::string> api_def_dirs = tensorflow::str_util::Split( std::vector<tensorflow::string> api_def_dirs = tensorflow::str_util::Split(
argv[4], ",", tensorflow::str_util::SkipEmpty()); argv[4], ",", tensorflow::str_util::SkipEmpty());
tensorflow::PrintAllCCOps(argv[1], argv[2], include_internal, api_def_dirs); tensorflow::PrintAllCCOps(argv[1], argv[2], include_internal, api_def_dirs);

View File

@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/cc/framework/cc_op_gen.h" #include "tensorflow/cc/framework/cc_op_gen.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/framework/op_def.pb.h"
#include "tensorflow/core/framework/op_gen_lib.h" #include "tensorflow/core/framework/op_gen_lib.h"
#include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/status_test_util.h"
@ -61,12 +62,12 @@ op {
} }
)"; )";
void ExpectHasSubstr(StringPiece s, StringPiece expected) { void ExpectHasSubstr(absl::string_view s, absl::string_view expected) {
EXPECT_TRUE(str_util::StrContains(s, expected)) EXPECT_TRUE(str_util::StrContains(s, expected))
<< "'" << s << "' does not contain '" << expected << "'"; << "'" << s << "' does not contain '" << expected << "'";
} }
void ExpectDoesNotHaveSubstr(StringPiece s, StringPiece expected) { void ExpectDoesNotHaveSubstr(absl::string_view s, absl::string_view expected) {
EXPECT_FALSE(str_util::StrContains(s, expected)) EXPECT_FALSE(str_util::StrContains(s, expected))
<< "'" << s << "' contains '" << expected << "'"; << "'" << s << "' contains '" << expected << "'";
} }

View File

@ -16,6 +16,7 @@ limitations under the License.
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/cc/framework/scope_internal.h" #include "tensorflow/cc/framework/scope_internal.h"
#include "tensorflow/core/common_runtime/shape_refiner.h" #include "tensorflow/core/common_runtime/shape_refiner.h"
#include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/node_def_util.h"
@ -247,7 +248,7 @@ std::unordered_set<string> Scope::Impl::GetColocationConstraints(
std::vector<string> node_constraints; std::vector<string> node_constraints;
if (GetNodeAttr(attrs, kColocationAttrName, &node_constraints).ok()) { if (GetNodeAttr(attrs, kColocationAttrName, &node_constraints).ok()) {
for (const string& entry : node_constraints) { for (const string& entry : node_constraints) {
StringPiece s(entry); absl::string_view s(entry);
if (str_util::ConsumePrefix(&s, kColocationGroupPrefix)) { if (str_util::ConsumePrefix(&s, kColocationGroupPrefix)) {
current_constraints.emplace(s); current_constraints.emplace(s);
} }

View File

@ -95,6 +95,7 @@ cc_library(
deps = [ deps = [
":constants", ":constants",
":reader", ":reader",
"@com_google_absl//absl/strings",
] + if_not_mobile([ ] + if_not_mobile([
"//tensorflow/core:core_cpu", "//tensorflow/core:core_cpu",
"//tensorflow/core:framework", "//tensorflow/core:framework",

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <unordered_set> #include <unordered_set>
#include "absl/strings/string_view.h"
#include "tensorflow/cc/saved_model/constants.h" #include "tensorflow/cc/saved_model/constants.h"
#include "tensorflow/cc/saved_model/reader.h" #include "tensorflow/cc/saved_model/reader.h"
#include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/io/path.h"
@ -60,7 +61,7 @@ Tensor CreateStringTensor(const string& value) {
return tensor; return tensor;
} }
void AddAssetsTensorsToInputs(const StringPiece export_dir, void AddAssetsTensorsToInputs(const absl::string_view export_dir,
const std::vector<AssetFileDef>& asset_file_defs, const std::vector<AssetFileDef>& asset_file_defs,
std::vector<std::pair<string, Tensor>>* inputs) { std::vector<std::pair<string, Tensor>>* inputs) {
if (asset_file_defs.empty()) { if (asset_file_defs.empty()) {
@ -147,7 +148,8 @@ Status RunMainOp(const RunOptions& run_options, const string& export_dir,
std::vector<std::pair<string, Tensor>> inputs; std::vector<std::pair<string, Tensor>> inputs;
AddAssetsTensorsToInputs(export_dir, asset_file_defs, &inputs); AddAssetsTensorsToInputs(export_dir, asset_file_defs, &inputs);
RunMetadata run_metadata; RunMetadata run_metadata;
const StringPiece main_op_name = main_op_it->second.node_list().value(0); const absl::string_view main_op_name =
main_op_it->second.node_list().value(0);
return RunOnce(run_options, inputs, {}, {string(main_op_name)}, return RunOnce(run_options, inputs, {}, {string(main_op_name)},
nullptr /* outputs */, &run_metadata, session); nullptr /* outputs */, &run_metadata, session);
} }
@ -155,8 +157,8 @@ Status RunMainOp(const RunOptions& run_options, const string& export_dir,
} }
Status RunRestore(const RunOptions& run_options, const string& export_dir, Status RunRestore(const RunOptions& run_options, const string& export_dir,
const StringPiece restore_op_name, const absl::string_view restore_op_name,
const StringPiece variable_filename_const_op_name, const absl::string_view variable_filename_const_op_name,
const std::vector<AssetFileDef>& asset_file_defs, const std::vector<AssetFileDef>& asset_file_defs,
Session* session) { Session* session) {
LOG(INFO) << "Restoring SavedModel bundle."; LOG(INFO) << "Restoring SavedModel bundle.";

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/cc/ops/standard_ops.h" #include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor.h"
@ -165,8 +166,7 @@ void ConcurrentSessions(const Options& opts) {
namespace { namespace {
bool ParseInt32Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, bool ParseInt32Flag(absl::string_view arg, absl::string_view flag, int32* dst) {
int32* dst) {
if (tensorflow::str_util::ConsumePrefix(&arg, flag) && if (tensorflow::str_util::ConsumePrefix(&arg, flag) &&
tensorflow::str_util::ConsumePrefix(&arg, "=")) { tensorflow::str_util::ConsumePrefix(&arg, "=")) {
char extra; char extra;
@ -176,8 +176,7 @@ bool ParseInt32Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag,
return false; return false;
} }
bool ParseBoolFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, bool ParseBoolFlag(absl::string_view arg, absl::string_view flag, bool* dst) {
bool* dst) {
if (tensorflow::str_util::ConsumePrefix(&arg, flag)) { if (tensorflow::str_util::ConsumePrefix(&arg, flag)) {
if (arg.empty()) { if (arg.empty()) {
*dst = true; *dst = true;

View File

@ -18,6 +18,7 @@ limitations under the License.
#include "absl/container/flat_hash_set.h" #include "absl/container/flat_hash_set.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "tensorflow/compiler/jit/encapsulate_subgraphs_pass.h" #include "tensorflow/compiler/jit/encapsulate_subgraphs_pass.h"
#include "tensorflow/compiler/tf2xla/dump_graph.h" #include "tensorflow/compiler/tf2xla/dump_graph.h"
#include "tensorflow/compiler/xla/status_macros.h" #include "tensorflow/compiler/xla/status_macros.h"
@ -123,8 +124,8 @@ Status RewriteSubgraph(const std::vector<OutputTensor>& arg_source_tensors,
bool a_is_resource = (a->output_type(0) == DT_RESOURCE); bool a_is_resource = (a->output_type(0) == DT_RESOURCE);
bool b_is_resource = (b->output_type(0) == DT_RESOURCE); bool b_is_resource = (b->output_type(0) == DT_RESOURCE);
// Uses the name as a tiebreaker so the output is deterministic. // Uses the name as a tiebreaker so the output is deterministic.
StringPiece a_name(a->name()); absl::string_view a_name(a->name());
StringPiece b_name(b->name()); absl::string_view b_name(b->name());
return std::tie(a_is_resource, a_name) < std::tie(b_is_resource, b_name); return std::tie(a_is_resource, a_name) < std::tie(b_is_resource, b_name);
}); });

View File

@ -194,6 +194,7 @@ cc_library(
"//tensorflow/core/kernels:bounds_check", "//tensorflow/core/kernels:bounds_check",
"//tensorflow/core/kernels:conv_ops", "//tensorflow/core/kernels:conv_ops",
"//tensorflow/core/kernels:ops_util", "//tensorflow/core/kernels:ops_util",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span", "@com_google_absl//absl/types:span",
], ],
) )

View File

@ -16,6 +16,7 @@ limitations under the License.
// XLA-specific Ops for 2D convolution. // XLA-specific Ops for 2D convolution.
#include "tensorflow/compiler/tf2xla/kernels/conv_op_helpers.h" #include "tensorflow/compiler/tf2xla/kernels/conv_op_helpers.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h" #include "absl/types/span.h"
#include "tensorflow/compiler/tf2xla/shape_util.h" #include "tensorflow/compiler/tf2xla/shape_util.h"
#include "tensorflow/compiler/tf2xla/type_util.h" #include "tensorflow/compiler/tf2xla/type_util.h"
@ -198,10 +199,11 @@ Status CheckConvAttrs(const ConvOpAttrs& attrs) {
// Wrapper around ConvBackpropComputeDimensions that converts from XLA shapes // Wrapper around ConvBackpropComputeDimensions that converts from XLA shapes
// to TensorShapes. // to TensorShapes.
Status ConvBackpropComputeDimensionsV2XlaShapes( Status ConvBackpropComputeDimensionsV2XlaShapes(
StringPiece label, int num_spatial_dims, const xla::Shape& input_shape, absl::string_view label, int num_spatial_dims,
const xla::Shape& filter_shape, const xla::Shape& out_backprop_shape, const xla::Shape& input_shape, const xla::Shape& filter_shape,
absl::Span<const int32> dilations, const std::vector<int32>& strides, const xla::Shape& out_backprop_shape, absl::Span<const int32> dilations,
Padding padding, TensorFormat data_format, ConvBackpropDimensions* dims) { const std::vector<int32>& strides, Padding padding,
TensorFormat data_format, ConvBackpropDimensions* dims) {
TensorShape input_tensor_shape, filter_tensor_shape, TensorShape input_tensor_shape, filter_tensor_shape,
out_backprop_tensor_shape; out_backprop_tensor_shape;
TF_RETURN_IF_ERROR(XLAShapeToTensorShape(input_shape, &input_tensor_shape)); TF_RETURN_IF_ERROR(XLAShapeToTensorShape(input_shape, &input_tensor_shape));
@ -235,10 +237,9 @@ xla::StatusOr<ConvOpAttrs> ConvOpAttrs::Create(int num_spatial_dims,
return attrs; return attrs;
} }
xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp(StringPiece /*type_string*/, xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp(
xla::XlaOp conv_input, absl::string_view /*type_string*/, xla::XlaOp conv_input, xla::XlaOp filter,
xla::XlaOp filter, const ConvOpAttrs& attrs) {
const ConvOpAttrs& attrs) {
TF_RETURN_IF_ERROR(CheckConvAttrs(attrs)); TF_RETURN_IF_ERROR(CheckConvAttrs(attrs));
auto* builder = conv_input.builder(); auto* builder = conv_input.builder();
@ -309,8 +310,8 @@ xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp(StringPiece /*type_string*/,
} }
xla::StatusOr<xla::XlaOp> MakeXlaBackpropInputConvOp( xla::StatusOr<xla::XlaOp> MakeXlaBackpropInputConvOp(
StringPiece type_string, const xla::Shape& input_shape, xla::XlaOp filter, absl::string_view type_string, const xla::Shape& input_shape,
xla::XlaOp out_backprop, const ConvOpAttrs& attrs) { xla::XlaOp filter, xla::XlaOp out_backprop, const ConvOpAttrs& attrs) {
TF_RETURN_IF_ERROR(CheckConvAttrs(attrs)); TF_RETURN_IF_ERROR(CheckConvAttrs(attrs));
int num_dims = attrs.num_spatial_dims + 2; int num_dims = attrs.num_spatial_dims + 2;
@ -380,7 +381,7 @@ xla::StatusOr<xla::XlaOp> MakeXlaBackpropInputConvOp(
} }
xla::StatusOr<xla::XlaOp> MakeXlaBackpropFilterConvOp( xla::StatusOr<xla::XlaOp> MakeXlaBackpropFilterConvOp(
StringPiece type_string, xla::XlaOp activations, absl::string_view type_string, xla::XlaOp activations,
const xla::Shape& filter_shape, xla::XlaOp gradients, const xla::Shape& filter_shape, xla::XlaOp gradients,
const ConvOpAttrs& attrs) { const ConvOpAttrs& attrs) {
TF_RETURN_IF_ERROR(CheckConvAttrs(attrs)); TF_RETURN_IF_ERROR(CheckConvAttrs(attrs));

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/compiler/xla/client/xla_builder.h" #include "tensorflow/compiler/xla/client/xla_builder.h"
#include "tensorflow/compiler/xla/statusor.h" #include "tensorflow/compiler/xla/statusor.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
@ -52,15 +53,15 @@ struct ConvOpAttrs {
// Creates a new XLA forward or backward convolution with the given inputs and // Creates a new XLA forward or backward convolution with the given inputs and
// attributes. // attributes.
xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp(StringPiece type_string, xla::StatusOr<xla::XlaOp> MakeXlaForwardConvOp(absl::string_view type_string,
xla::XlaOp conv_input, xla::XlaOp conv_input,
xla::XlaOp filter, xla::XlaOp filter,
const ConvOpAttrs& attrs); const ConvOpAttrs& attrs);
xla::StatusOr<xla::XlaOp> MakeXlaBackpropInputConvOp( xla::StatusOr<xla::XlaOp> MakeXlaBackpropInputConvOp(
StringPiece type_string, const xla::Shape& input_shape, xla::XlaOp filter, absl::string_view type_string, const xla::Shape& input_shape,
xla::XlaOp out_backprop, const ConvOpAttrs& attrs); xla::XlaOp filter, xla::XlaOp out_backprop, const ConvOpAttrs& attrs);
xla::StatusOr<xla::XlaOp> MakeXlaBackpropFilterConvOp( xla::StatusOr<xla::XlaOp> MakeXlaBackpropFilterConvOp(
StringPiece type_string, xla::XlaOp activations, absl::string_view type_string, xla::XlaOp activations,
const xla::Shape& filter_shape, xla::XlaOp gradients, const xla::Shape& filter_shape, xla::XlaOp gradients,
const ConvOpAttrs& attrs); const ConvOpAttrs& attrs);

View File

@ -67,8 +67,8 @@ int main(int argc, char** argv) {
floats.push_back(value); floats.push_back(value);
} }
tensorflow::StringPiece content(absl::bit_cast<const char*>(floats.data()), absl::string_view content(absl::bit_cast<const char*>(floats.data()),
floats.size() * sizeof(float)); floats.size() * sizeof(float));
TF_CHECK_OK(tensorflow::WriteStringToFile(tensorflow::Env::Default(), TF_CHECK_OK(tensorflow::WriteStringToFile(tensorflow::Env::Default(),
output_file, content)); output_file, content));
return 0; return 0;

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <unistd.h> #include <unistd.h>
#include "absl/strings/string_view.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/file_system_helper.h" #include "tensorflow/core/platform/file_system_helper.h"
@ -26,7 +27,7 @@ namespace {
string RemoveSuffix(const string& name, const string& suffix) { string RemoveSuffix(const string& name, const string& suffix) {
string output(name); string output(name);
StringPiece piece(output); absl::string_view piece(output);
str_util::ConsumeSuffix(&piece, suffix); str_util::ConsumeSuffix(&piece, suffix);
return string(piece); return string(piece);
} }
@ -87,7 +88,7 @@ class RandomAccessFileFromAsset : public RandomAccessFile {
: asset_manager_(asset_manager), file_name_(name) {} : asset_manager_(asset_manager), file_name_(name) {}
~RandomAccessFileFromAsset() override = default; ~RandomAccessFileFromAsset() override = default;
Status Read(uint64 offset, size_t to_read, StringPiece* result, Status Read(uint64 offset, size_t to_read, absl::string_view* result,
char* scratch) const override { char* scratch) const override {
auto asset = ScopedAsset(AAssetManager_open( auto asset = ScopedAsset(AAssetManager_open(
asset_manager_, file_name_.c_str(), AASSET_MODE_RANDOM)); asset_manager_, file_name_.c_str(), AASSET_MODE_RANDOM));
@ -98,7 +99,7 @@ class RandomAccessFileFromAsset : public RandomAccessFile {
off64_t new_offset = AAsset_seek64(asset.get(), offset, SEEK_SET); off64_t new_offset = AAsset_seek64(asset.get(), offset, SEEK_SET);
off64_t length = AAsset_getLength64(asset.get()); off64_t length = AAsset_getLength64(asset.get());
if (new_offset < 0) { if (new_offset < 0) {
*result = StringPiece(scratch, 0); *result = absl::string_view(scratch, 0);
return errors::OutOfRange("Read after file end."); return errors::OutOfRange("Read after file end.");
} }
const off64_t region_left = const off64_t region_left =
@ -107,7 +108,7 @@ class RandomAccessFileFromAsset : public RandomAccessFile {
if (read < 0) { if (read < 0) {
return errors::Internal("Error reading from asset."); return errors::Internal("Error reading from asset.");
} }
*result = StringPiece(scratch, region_left); *result = absl::string_view(scratch, region_left);
return (region_left == to_read) return (region_left == to_read)
? Status::OK() ? Status::OK()
: errors::OutOfRange("Read less bytes than requested."); : errors::OutOfRange("Read less bytes than requested.");
@ -229,7 +230,7 @@ string AssetManagerFileSystem::NormalizeDirectoryPath(const string& fname) {
} }
string AssetManagerFileSystem::RemoveAssetPrefix(const string& name) { string AssetManagerFileSystem::RemoveAssetPrefix(const string& name) {
StringPiece piece(name); absl::string_view piece(name);
str_util::ConsumePrefix(&piece, prefix_); str_util::ConsumePrefix(&piece, prefix_);
return string(piece); return string(piece);
} }

View File

@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/bigtable/kernels/bigtable_lib.h" #include "tensorflow/contrib/bigtable/kernels/bigtable_lib.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
@ -342,7 +343,8 @@ class ToBigtableOp : public AsyncOpKernel {
template <typename T> template <typename T>
Status ParseScalarArgument(OpKernelContext* ctx, Status ParseScalarArgument(OpKernelContext* ctx,
const StringPiece& argument_name, T* output) { const absl::string_view& argument_name,
T* output) {
const Tensor* argument_t; const Tensor* argument_t;
TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t)); TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t));
if (!TensorShapeUtils::IsScalar(argument_t->shape())) { if (!TensorShapeUtils::IsScalar(argument_t->shape())) {

View File

@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.h" #include "tensorflow/contrib/bigtable/kernels/bigtable_range_helpers.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/logging.h"
namespace tensorflow { namespace tensorflow {
@ -55,11 +56,11 @@ const string& MultiModeKeyRange::begin_key() const { return begin_; }
const string& MultiModeKeyRange::end_key() const { return end_; } const string& MultiModeKeyRange::end_key() const { return end_; }
bool MultiModeKeyRange::contains_key(StringPiece key) const { bool MultiModeKeyRange::contains_key(absl::string_view key) const {
if (StringPiece(begin_) > key) { if (absl::string_view(begin_) > key) {
return false; return false;
} }
if (StringPiece(end_) <= key && !end_.empty()) { if (absl::string_view(end_) <= key && !end_.empty()) {
return false; return false;
} }
return true; return true;

View File

@ -18,7 +18,7 @@ limitations under the License.
#include <string> #include <string>
#include "tensorflow/core/lib/core/stringpiece.h" #include "absl/strings/string_view.h"
#include "tensorflow/core/platform/types.h" #include "tensorflow/core/platform/types.h"
namespace tensorflow { namespace tensorflow {
@ -52,7 +52,7 @@ class MultiModeKeyRange {
// The first invalid key after the valid range. // The first invalid key after the valid range.
const string& end_key() const; const string& end_key() const;
// Returns true if the provided key is a part of the range, false otherwise. // Returns true if the provided key is a part of the range, false otherwise.
bool contains_key(StringPiece key) const; bool contains_key(absl::string_view key) const;
private: private:
MultiModeKeyRange(string begin, string end) MultiModeKeyRange(string begin, string end)

View File

@ -46,6 +46,7 @@ cc_library(
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"//tensorflow/core/platform/cloud:curl_http_request", "//tensorflow/core/platform/cloud:curl_http_request",
"//tensorflow/core/platform/cloud:google_auth_provider", "//tensorflow/core/platform/cloud:google_auth_provider",
"@com_google_absl//absl/strings",
], ],
alwayslink = 1, alwayslink = 1,
) )
@ -65,6 +66,7 @@ tf_cc_test(
"//tensorflow/core:test", "//tensorflow/core:test",
"//tensorflow/core:test_main", "//tensorflow/core:test_main",
"//tensorflow/core/platform/cloud:http_request_fake", "//tensorflow/core/platform/cloud:http_request_fake",
"@com_google_absl//absl/strings",
], ],
) )
@ -85,6 +87,7 @@ tf_kernel_library(
"//tensorflow/core/platform/cloud:curl_http_request", "//tensorflow/core/platform/cloud:curl_http_request",
"//tensorflow/core/platform/cloud:gcs_file_system", "//tensorflow/core/platform/cloud:gcs_file_system",
"//tensorflow/core/platform/cloud:oauth_client", "//tensorflow/core/platform/cloud:oauth_client",
"@com_google_absl//absl/strings",
"@jsoncpp_git//:jsoncpp", "@jsoncpp_git//:jsoncpp",
], ],
) )

View File

@ -14,6 +14,7 @@ limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "tensorflow/contrib/cloud/kernels/bigquery_table_accessor.h" #include "tensorflow/contrib/cloud/kernels/bigquery_table_accessor.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/example/feature.pb.h" #include "tensorflow/core/example/feature.pb.h"
#include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/numbers.h"
@ -31,7 +32,7 @@ bool IsPartitionEmpty(const BigQueryTablePartition& partition) {
return false; return false;
} }
Status ParseJson(StringPiece json, Json::Value* result) { Status ParseJson(absl::string_view json, Json::Value* result) {
Json::Reader reader; Json::Reader reader;
if (!reader.parse(string(json), *result)) { if (!reader.parse(string(json), *result)) {
return errors::Internal("Couldn't parse JSON response from BigQuery."); return errors::Internal("Couldn't parse JSON response from BigQuery.");
@ -183,8 +184,8 @@ Status BigQueryTableAccessor::ReadRow(int64* row_id, Example* example) {
FullTableName()); FullTableName());
// Parse the returned row. // Parse the returned row.
StringPiece response_piece = absl::string_view response_piece =
StringPiece(&output_buffer[0], output_buffer.size()); absl::string_view(&output_buffer[0], output_buffer.size());
Json::Value root; Json::Value root;
TF_RETURN_IF_ERROR(ParseJson(response_piece, &root)); TF_RETURN_IF_ERROR(ParseJson(response_piece, &root));
for (unsigned int i = 0; i < root["rows"].size(); ++i) { for (unsigned int i = 0; i < root["rows"].size(); ++i) {
@ -261,8 +262,8 @@ Status BigQueryTableAccessor::ReadSchema() {
FullTableName()); FullTableName());
// Parse the schema. // Parse the schema.
StringPiece response_piece = absl::string_view response_piece =
StringPiece(&output_buffer[0], output_buffer.size()); absl::string_view(&output_buffer[0], output_buffer.size());
Json::Value root; Json::Value root;
TF_RETURN_IF_ERROR(ParseJson(response_piece, &root)); TF_RETURN_IF_ERROR(ParseJson(response_piece, &root));

View File

@ -14,6 +14,7 @@ limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "tensorflow/contrib/cloud/kernels/bigquery_table_accessor.h" #include "tensorflow/contrib/cloud/kernels/bigquery_table_accessor.h"
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/cloud/kernels/bigquery_table_accessor_test_data.h" #include "tensorflow/contrib/cloud/kernels/bigquery_table_accessor_test_data.h"
#include "tensorflow/core/example/feature.pb.h" #include "tensorflow/core/example/feature.pb.h"
#include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/status_test_util.h"
@ -29,7 +30,7 @@ constexpr char kTestProject[] = "test-project";
constexpr char kTestDataset[] = "test-dataset"; constexpr char kTestDataset[] = "test-dataset";
constexpr char kTestTable[] = "test-table"; constexpr char kTestTable[] = "test-table";
bool HasSubstr(StringPiece base, StringPiece substr) { bool HasSubstr(absl::string_view base, absl::string_view substr) {
bool ok = str_util::StrContains(base, substr); bool ok = str_util::StrContains(base, substr);
EXPECT_TRUE(ok) << base << ", expected substring " << substr; EXPECT_TRUE(ok) << base << ", expected substring " << substr;
return ok; return ok;

View File

@ -15,6 +15,7 @@ limitations under the License.
#include <sstream> #include <sstream>
#include "absl/strings/string_view.h"
#include "include/json/json.h" #include "include/json/json.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/tensor_shape.h"
@ -63,8 +64,8 @@ Status RetrieveGcsFs(OpKernelContext* ctx, RetryingGcsFileSystem** fs) {
} }
template <typename T> template <typename T>
Status ParseScalarArgument(OpKernelContext* ctx, StringPiece argument_name, Status ParseScalarArgument(OpKernelContext* ctx,
T* output) { absl::string_view argument_name, T* output) {
const Tensor* argument_t; const Tensor* argument_t;
TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t)); TF_RETURN_IF_ERROR(ctx->input(argument_name, &argument_t));
if (!TensorShapeUtils::IsScalar(argument_t->shape())) { if (!TensorShapeUtils::IsScalar(argument_t->shape())) {

View File

@ -29,6 +29,7 @@ cc_library(
"//tensorflow/contrib/ffmpeg/default:ffmpeg_lib", "//tensorflow/contrib/ffmpeg/default:ffmpeg_lib",
"//tensorflow/core:framework_headers_lib", "//tensorflow/core:framework_headers_lib",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
], ],
alwayslink = 1, alwayslink = 1,
) )
@ -57,6 +58,7 @@ cc_library(
"//tensorflow/contrib/ffmpeg/default:ffmpeg_lib", "//tensorflow/contrib/ffmpeg/default:ffmpeg_lib",
"//tensorflow/core:framework_headers_lib", "//tensorflow/core:framework_headers_lib",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
], ],
alwayslink = 1, alwayslink = 1,
) )

View File

@ -18,6 +18,7 @@
#include <cstdio> #include <cstdio>
#include <set> #include <set>
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/ffmpeg/ffmpeg_lib.h" #include "tensorflow/contrib/ffmpeg/ffmpeg_lib.h"
#include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
@ -41,8 +42,7 @@ const char* kValidFileFormats[] = {"mp3", "mp4", "ogg", "wav"};
* Decoding implementation, shared across V1 and V2 ops. Creates a new * Decoding implementation, shared across V1 and V2 ops. Creates a new
* output in the context. * output in the context.
*/ */
void Decode(OpKernelContext* context, void Decode(OpKernelContext* context, const absl::string_view& file_contents,
const tensorflow::StringPiece& file_contents,
const string& file_format, const int32 samples_per_second, const string& file_format, const int32 samples_per_second,
const int32 channel_count, const string& stream) { const int32 channel_count, const string& stream) {
// Write the input data to a temp file. // Write the input data to a temp file.
@ -135,7 +135,7 @@ class DecodeAudioOpV2 : public OpKernel {
"channel_count must be a rank-0 tensor but got shape ", "channel_count must be a rank-0 tensor but got shape ",
channel_count_tensor.shape().DebugString())); channel_count_tensor.shape().DebugString()));
const tensorflow::StringPiece contents = contents_tensor.scalar<string>()(); const absl::string_view contents = contents_tensor.scalar<string>()();
const string file_format = const string file_format =
str_util::Lowercase(file_format_tensor.scalar<string>()()); str_util::Lowercase(file_format_tensor.scalar<string>()());
const int32 samples_per_second = const int32 samples_per_second =
@ -245,7 +245,7 @@ class DecodeAudioOp : public OpKernel {
errors::InvalidArgument("contents must be scalar but got shape ", errors::InvalidArgument("contents must be scalar but got shape ",
contents.shape().DebugString())); contents.shape().DebugString()));
const tensorflow::StringPiece file_contents = contents.scalar<string>()(); const absl::string_view file_contents = contents.scalar<string>()();
Decode(context, file_contents, file_format_, samples_per_second_, Decode(context, file_contents, file_format_, samples_per_second_,
channel_count_, ""); channel_count_, "");
} }

View File

@ -18,6 +18,7 @@
#include <cstdio> #include <cstdio>
#include <set> #include <set>
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/ffmpeg/ffmpeg_lib.h" #include "tensorflow/contrib/ffmpeg/ffmpeg_lib.h"
#include "tensorflow/core/framework/op.h" #include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
@ -45,7 +46,7 @@ class DecodeVideoOp : public OpKernel {
errors::InvalidArgument( errors::InvalidArgument(
"contents must be a rank-0 tensor but got shape ", "contents must be a rank-0 tensor but got shape ",
contents_tensor.shape().DebugString())); contents_tensor.shape().DebugString()));
const tensorflow::StringPiece contents = contents_tensor.scalar<string>()(); const absl::string_view contents = contents_tensor.scalar<string>()();
// Write the input data to a temp file. // Write the input data to a temp file.
string extension; string extension;

View File

@ -20,6 +20,7 @@ cc_library(
deps = [ deps = [
"//tensorflow/core:framework_headers_lib", "//tensorflow/core:framework_headers_lib",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
"@protobuf_archive//:protobuf_headers", "@protobuf_archive//:protobuf_headers",
], ],
) )

View File

@ -25,6 +25,7 @@
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/io/path.h"
#include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/numbers.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
@ -303,7 +304,7 @@ FileDeleter::~FileDeleter() {
env.DeleteFile(filename_).IgnoreError(); env.DeleteFile(filename_).IgnoreError();
} }
Status WriteFile(const string& filename, StringPiece contents) { Status WriteFile(const string& filename, absl::string_view contents) {
Env& env = *Env::Default(); Env& env = *Env::Default();
std::unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
TF_RETURN_IF_ERROR(env.NewWritableFile(filename, &file)); TF_RETURN_IF_ERROR(env.NewWritableFile(filename, &file));

View File

@ -19,6 +19,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"
namespace tensorflow { namespace tensorflow {
@ -35,7 +36,7 @@ class FileDeleter {
}; };
// Writes binary data to a file. // Writes binary data to a file.
Status WriteFile(const string& filename, tensorflow::StringPiece contents); Status WriteFile(const string& filename, absl::string_view contents);
// Reads an audio file using ffmpeg and converts it into an array of samples in // Reads an audio file using ffmpeg and converts it into an array of samples in
// [-1.0, 1.0]. If there are multiple channels in the audio then each frame will // [-1.0, 1.0]. If there are multiple channels in the audio then each frame will

View File

@ -97,6 +97,7 @@ cc_library(
"//tensorflow/core/distributed_runtime:worker_cache", "//tensorflow/core/distributed_runtime:worker_cache",
"//tensorflow/core/distributed_runtime:worker_env", "//tensorflow/core/distributed_runtime:worker_env",
"//tensorflow/core/distributed_runtime:worker_interface", "//tensorflow/core/distributed_runtime:worker_interface",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/contrib/gdr/gdr_rendezvous_mgr.h" #include "tensorflow/contrib/gdr/gdr_rendezvous_mgr.h"
#include "google/protobuf/any.pb.h" #include "google/protobuf/any.pb.h"
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/gdr/gdr_memory_manager.h" #include "tensorflow/contrib/gdr/gdr_memory_manager.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/device_mgr.h"
@ -41,7 +42,7 @@ class GdrRecvTensorCall : public BaseRecvTensorCall {
GdrRecvTensorCall(WorkerInterface* wi, Device* dst_device, GdrRecvTensorCall(WorkerInterface* wi, Device* dst_device,
RemoteMemoryManager* remote_memory_manager, RemoteMemoryManager* remote_memory_manager,
const Rendezvous::Args& recv_args, int64 step_id, const Rendezvous::Args& recv_args, int64 step_id,
StringPiece key) absl::string_view key)
: wi_(wi), : wi_(wi),
dst_device_(dst_device), dst_device_(dst_device),
remote_memory_manager_(remote_memory_manager), remote_memory_manager_(remote_memory_manager),

View File

@ -13,6 +13,7 @@ cc_library(
deps = [ deps = [
"//tensorflow/core:framework_headers_lib", "//tensorflow/core:framework_headers_lib",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
"@farmhash_archive//:farmhash", "@farmhash_archive//:farmhash",
"@protobuf_archive//:protobuf_headers", "@protobuf_archive//:protobuf_headers",
], ],

View File

@ -19,6 +19,7 @@ limitations under the License.
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
#include "tensorflow/core/framework/kernel_def_builder.h" #include "tensorflow/core/framework/kernel_def_builder.h"
#include "tensorflow/core/framework/op_def_builder.h" #include "tensorflow/core/framework/op_def_builder.h"
@ -26,7 +27,6 @@ limitations under the License.
#include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/fingerprint.h" #include "tensorflow/core/platform/fingerprint.h"
#include "tensorflow/core/util/work_sharder.h" #include "tensorflow/core/util/work_sharder.h"
@ -92,8 +92,8 @@ string SparseTensorColumn<string>::Feature(int64 batch, int64 n) const {
} }
template <> template <>
StringPiece SparseTensorColumn<StringPiece>::Feature(int64 batch, absl::string_view SparseTensorColumn<absl::string_view>::Feature(
int64 n) const { int64 batch, int64 n) const {
const int64 start = feature_start_indices_[batch]; const int64 start = feature_start_indices_[batch];
return values_.vec<string>().data()[start + n]; return values_.vec<string>().data()[start + n];
} }
@ -130,8 +130,8 @@ string DenseTensorColumn<string>::Feature(int64 batch, int64 n) const {
} }
template <> template <>
StringPiece DenseTensorColumn<StringPiece>::Feature(int64 batch, absl::string_view DenseTensorColumn<absl::string_view>::Feature(int64 batch,
int64 n) const { int64 n) const {
return tensor_.matrix<string>()(batch, n); return tensor_.matrix<string>()(batch, n);
} }

View File

@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "absl/strings/string_view.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/tensor_shape.h"
@ -46,10 +47,10 @@ class DecodeLibsvmOp : public OpKernel {
std::vector<T> out_values; std::vector<T> out_values;
std::vector<std::pair<int64, int64>> out_indices; std::vector<std::pair<int64, int64>> out_indices;
for (int i = 0; i < input_flat.size(); ++i) { for (int i = 0; i < input_flat.size(); ++i) {
StringPiece line(input_flat(i)); absl::string_view line(input_flat(i));
str_util::RemoveWhitespaceContext(&line); str_util::RemoveWhitespaceContext(&line);
StringPiece piece; absl::string_view piece;
OP_REQUIRES(ctx, str_util::ConsumeNonWhitespace(&line, &piece), OP_REQUIRES(ctx, str_util::ConsumeNonWhitespace(&line, &piece),
errors::InvalidArgument("No label found for input[", i, errors::InvalidArgument("No label found for input[", i,
"]: \"", input_flat(i), "\"")); "]: \"", input_flat(i), "\""));
@ -64,7 +65,7 @@ class DecodeLibsvmOp : public OpKernel {
str_util::RemoveLeadingWhitespace(&line); str_util::RemoveLeadingWhitespace(&line);
while (str_util::ConsumeNonWhitespace(&line, &piece)) { while (str_util::ConsumeNonWhitespace(&line, &piece)) {
size_t p = piece.find(':'); size_t p = piece.find(':');
OP_REQUIRES(ctx, (p != StringPiece::npos), OP_REQUIRES(ctx, (p != absl::string_view::npos),
errors::InvalidArgument("Invalid feature \"", piece, "\"")); errors::InvalidArgument("Invalid feature \"", piece, "\""));
int64 feature_index; int64 feature_index;

View File

@ -79,6 +79,7 @@ cc_library(
":delegate_data", ":delegate_data",
":kernel", ":kernel",
":util", ":util",
"@com_google_absl//absl/strings",
"//tensorflow/contrib/lite/c:c_api_internal", "//tensorflow/contrib/lite/c:c_api_internal",
"//tensorflow/contrib/lite:kernel_api", "//tensorflow/contrib/lite:kernel_api",
"//tensorflow/contrib/lite:util", "//tensorflow/contrib/lite:util",
@ -176,6 +177,7 @@ tf_cc_test(
":kernel", ":kernel",
":test_util", ":test_util",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
"@com_google_absl//absl/strings",
] + select({ ] + select({
"//tensorflow:android": [ "//tensorflow:android": [
"//tensorflow/core:android_tensorflow_lib", "//tensorflow/core:android_tensorflow_lib",

View File

@ -16,6 +16,7 @@ limitations under the License.
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/lite/context_util.h" #include "tensorflow/contrib/lite/context_util.h"
#include "tensorflow/contrib/lite/delegates/flex/buffer_map.h" #include "tensorflow/contrib/lite/delegates/flex/buffer_map.h"
#include "tensorflow/contrib/lite/delegates/flex/kernel.h" #include "tensorflow/contrib/lite/delegates/flex/kernel.h"
@ -68,7 +69,7 @@ TfLiteStatus CopyFromBufferHandle(TfLiteContext* context,
} }
tensorflow::Tensor t = buffer_map->GetTensor(buffer_handle); tensorflow::Tensor t = buffer_map->GetTensor(buffer_handle);
tensorflow::StringPiece t_data = t.tensor_data(); absl::string_view t_data = t.tensor_data();
if (size != t_data.size()) { if (size != t_data.size()) {
context->ReportError( context->ReportError(

View File

@ -16,6 +16,7 @@ limitations under the License.
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/lite/delegates/flex/delegate_data.h" #include "tensorflow/contrib/lite/delegates/flex/delegate_data.h"
#include "tensorflow/contrib/lite/delegates/flex/test_util.h" #include "tensorflow/contrib/lite/delegates/flex/test_util.h"
@ -60,9 +61,9 @@ class KernelTest : public testing::FlexModelTest {
TfLiteBufferHandle buffer_handle, TfLiteBufferHandle buffer_handle,
void* data, size_t size) { void* data, size_t size) {
auto* delegate_data = reinterpret_cast<DelegateData*>(delegate->data_); auto* delegate_data = reinterpret_cast<DelegateData*>(delegate->data_);
tensorflow::StringPiece values = delegate_data->GetBufferMap(context) absl::string_view values = delegate_data->GetBufferMap(context)
->GetTensor(buffer_handle) ->GetTensor(buffer_handle)
.tensor_data(); .tensor_data();
memcpy(data, values.data(), values.size()); memcpy(data, values.data(), values.size());
return kTfLiteOk; return kTfLiteOk;
}; };

View File

@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "absl/strings/string_view.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
#if GOOGLE_CUDA #if GOOGLE_CUDA
@ -35,7 +36,7 @@ Status ReplaceReduce(Graph* graph, Node* node) {
TF_RETURN_IF_ERROR(GetNodeAttr(node->attrs(), "T", &dtype)); TF_RETURN_IF_ERROR(GetNodeAttr(node->attrs(), "T", &dtype));
int num_devices = node->num_inputs(); int num_devices = node->num_inputs();
string shared_name = node->name(); string shared_name = node->name();
auto make_builder = [&](StringPiece op_name, StringPiece suffix) { auto make_builder = [&](absl::string_view op_name, absl::string_view suffix) {
return NodeBuilder(strings::StrCat(shared_name, suffix), op_name) return NodeBuilder(strings::StrCat(shared_name, suffix), op_name)
.Attr("reduction", reduction) .Attr("reduction", reduction)
.Attr("num_devices", num_devices) .Attr("num_devices", num_devices)
@ -159,7 +160,7 @@ Status ReplaceBroadcast(Graph* graph, Node* node) {
} }
string shared_name = node->name(); string shared_name = node->name();
auto make_builder = [&](StringPiece op_name, StringPiece suffix) { auto make_builder = [&](absl::string_view op_name, absl::string_view suffix) {
return NodeBuilder(strings::StrCat(shared_name, suffix), op_name) return NodeBuilder(strings::StrCat(shared_name, suffix), op_name)
.Attr("num_devices", num_devices) .Attr("num_devices", num_devices)
.Attr("shared_name", shared_name) .Attr("shared_name", shared_name)
@ -255,7 +256,7 @@ class NcclReplacePass : public GraphOptimizationPass {
} }
// Find reduction and broadcast ops and replace them with Send/Recv ops. // Find reduction and broadcast ops and replace them with Send/Recv ops.
for (Node* node : graph->op_nodes()) { for (Node* node : graph->op_nodes()) {
StringPiece type = node->type_string(); absl::string_view type = node->type_string();
if (!str_util::StartsWith(type, "Nccl")) { if (!str_util::StartsWith(type, "Nccl")) {
continue; continue;
} }

View File

@ -35,6 +35,7 @@ cc_library(
"//tensorflow/core:lib", "//tensorflow/core:lib",
"//tensorflow/core:lib_proto_parsing", "//tensorflow/core:lib_proto_parsing",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -15,17 +15,17 @@ limitations under the License.
#include "tensorflow/contrib/saved_model/cc/saved_model/signature_def_utils.h" #include "tensorflow/contrib/saved_model/cc/saved_model/signature_def_utils.h"
#include "absl/strings/string_view.h"
#include "tensorflow/cc/saved_model/signature_constants.h" #include "tensorflow/cc/saved_model/signature_constants.h"
#include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/protobuf.h"
namespace tensorflow { namespace tensorflow {
namespace { namespace {
template <class T> template <class T>
Status FindInProtobufMap(StringPiece description, Status FindInProtobufMap(absl::string_view description,
const protobuf::Map<string, T>& map, const string& key, const protobuf::Map<string, T>& map, const string& key,
const T** value) { const T** value) {
const auto it = map.find(key); const auto it = map.find(key);

View File

@ -190,6 +190,7 @@ cc_library(
"//tensorflow/core:core_cpu", "//tensorflow/core:core_cpu",
"//tensorflow/core:lib", "//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/strings",
], ],
) )
@ -206,6 +207,7 @@ cc_library(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
":signature_lite", ":signature_lite",
"@com_google_absl//absl/strings",
"//tensorflow/core:lib_internal", "//tensorflow/core:lib_internal",
] + if_not_mobile([ ] + if_not_mobile([
":manifest_proto_cc", ":manifest_proto_cc",
@ -342,6 +344,7 @@ tf_cc_test(
"//tensorflow/core:test", "//tensorflow/core:test",
"//tensorflow/core:test_main", "//tensorflow/core:test_main",
"//tensorflow/core:testlib", "//tensorflow/core:testlib",
"@com_google_absl//absl/strings",
], ],
) )
@ -370,6 +373,7 @@ cc_library(
deps = [ deps = [
":session_bundle", ":session_bundle",
":signature", ":signature",
"@com_google_absl//absl/strings",
"//tensorflow/cc/saved_model:loader", "//tensorflow/cc/saved_model:loader",
"//tensorflow/cc/saved_model:signature_constants", "//tensorflow/cc/saved_model:signature_constants",
] + if_not_mobile([ ] + if_not_mobile([

View File

@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/contrib/session_bundle/bundle_shim.h" #include "tensorflow/contrib/session_bundle/bundle_shim.h"
#include "absl/strings/string_view.h"
#include "tensorflow/cc/saved_model/loader.h" #include "tensorflow/cc/saved_model/loader.h"
#include "tensorflow/cc/saved_model/signature_constants.h" #include "tensorflow/cc/saved_model/signature_constants.h"
#include "tensorflow/contrib/session_bundle/manifest.pb.h" #include "tensorflow/contrib/session_bundle/manifest.pb.h"
@ -23,7 +24,6 @@ limitations under the License.
#include "tensorflow/core/graph/graph_constructor.h" #include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h" #include "tensorflow/core/protobuf/meta_graph.pb.h"
#include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session.h"
#include "tensorflow/core/public/session_options.h" #include "tensorflow/core/public/session_options.h"
@ -129,7 +129,7 @@ Status MaybeBuildPredictSignatureDef(
Status LoadSavedModelFromLegacySessionBundlePath( Status LoadSavedModelFromLegacySessionBundlePath(
const SessionOptions& session_options, const RunOptions& run_options, const SessionOptions& session_options, const RunOptions& run_options,
const StringPiece session_bundle_export_dir, const absl::string_view session_bundle_export_dir,
SavedModelBundle* saved_model_bundle) { SavedModelBundle* saved_model_bundle) {
if (session_bundle_export_dir.empty()) { if (session_bundle_export_dir.empty()) {
return Status(error::Code::NOT_FOUND, "Export directory path is empty."); return Status(error::Code::NOT_FOUND, "Export directory path is empty.");

View File

@ -20,6 +20,7 @@ limitations under the License.
#include <vector> #include <vector>
#include "google/protobuf/any.pb.h" #include "google/protobuf/any.pb.h"
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/session_bundle/manifest.pb.h" #include "tensorflow/contrib/session_bundle/manifest.pb.h"
#include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/graph_def_util.h" #include "tensorflow/core/framework/graph_def_util.h"
@ -62,7 +63,7 @@ Status CreateSessionFromGraphDef(const SessionOptions& options,
return (*session)->Create(graph); return (*session)->Create(graph);
} }
Status GetMetaGraphDefFromExport(const StringPiece export_dir, Status GetMetaGraphDefFromExport(const absl::string_view export_dir,
MetaGraphDef* meta_graph_def) { MetaGraphDef* meta_graph_def) {
const string meta_graph_def_path = const string meta_graph_def_path =
io::JoinPath(export_dir, kMetaGraphDefFilename); io::JoinPath(export_dir, kMetaGraphDefFilename);
@ -77,7 +78,7 @@ Tensor CreateStringTensor(const string& value) {
} }
// Adds Assets related tensors (assets_dir and asset files) to the inputs. // Adds Assets related tensors (assets_dir and asset files) to the inputs.
void AddAssetsTensorsToInputs(const StringPiece export_dir, void AddAssetsTensorsToInputs(const absl::string_view export_dir,
const std::vector<AssetFile>& asset_files, const std::vector<AssetFile>& asset_files,
std::vector<std::pair<string, Tensor>>* inputs) { std::vector<std::pair<string, Tensor>>* inputs) {
if (asset_files.empty()) { if (asset_files.empty()) {
@ -108,7 +109,7 @@ void AddAssetsTensorsToInputs(const StringPiece export_dir,
// prefix.data-* are present in the filesystem. So if we see export.index // prefix.data-* are present in the filesystem. So if we see export.index
// present in the export_dir, we know the export is in V2 format and we return // present in the export_dir, we know the export is in V2 format and we return
// <export_dir>/export as this prefix. // <export_dir>/export as this prefix.
string GetVariablesFilename(const StringPiece export_dir) { string GetVariablesFilename(const absl::string_view export_dir) {
const char kVariablesFilename[] = "export"; const char kVariablesFilename[] = "export";
const string kVariablesIndexFilename = MetaFilename("export"); // V2 ckpts const string kVariablesIndexFilename = MetaFilename("export"); // V2 ckpts
const char kVariablesFilenamePattern[] = "export-\?\?\?\?\?-of-\?\?\?\?\?"; const char kVariablesFilenamePattern[] = "export-\?\?\?\?\?-of-\?\?\?\?\?";
@ -128,10 +129,11 @@ string GetVariablesFilename(const StringPiece export_dir) {
} }
} }
Status RunRestoreOp(const RunOptions& run_options, const StringPiece export_dir, Status RunRestoreOp(const RunOptions& run_options,
const absl::string_view export_dir,
const std::vector<AssetFile>& asset_files, const std::vector<AssetFile>& asset_files,
const StringPiece restore_op_name, const absl::string_view restore_op_name,
const StringPiece variables_filename_const_op_name, const absl::string_view variables_filename_const_op_name,
Session* session) { Session* session) {
LOG(INFO) << "Running restore op for SessionBundle: " << restore_op_name LOG(INFO) << "Running restore op for SessionBundle: " << restore_op_name
<< ", " << variables_filename_const_op_name; << ", " << variables_filename_const_op_name;
@ -145,9 +147,10 @@ Status RunRestoreOp(const RunOptions& run_options, const StringPiece export_dir,
nullptr /* outputs */, &run_metadata); nullptr /* outputs */, &run_metadata);
} }
Status RunInitOp(const RunOptions& run_options, const StringPiece export_dir, Status RunInitOp(const RunOptions& run_options,
const absl::string_view export_dir,
const std::vector<AssetFile>& asset_files, const std::vector<AssetFile>& asset_files,
const StringPiece init_op_name, Session* session) { const absl::string_view init_op_name, Session* session) {
LOG(INFO) << "Running init op for SessionBundle"; LOG(INFO) << "Running init op for SessionBundle";
std::vector<std::pair<string, Tensor>> inputs; std::vector<std::pair<string, Tensor>> inputs;
AddAssetsTensorsToInputs(export_dir, asset_files, &inputs); AddAssetsTensorsToInputs(export_dir, asset_files, &inputs);
@ -158,7 +161,7 @@ Status RunInitOp(const RunOptions& run_options, const StringPiece export_dir,
Status LoadSessionBundleFromPathUsingRunOptionsInternal( Status LoadSessionBundleFromPathUsingRunOptionsInternal(
const SessionOptions& options, const RunOptions& run_options, const SessionOptions& options, const RunOptions& run_options,
const StringPiece export_dir, SessionBundle* const bundle) { const absl::string_view export_dir, SessionBundle* const bundle) {
LOG(INFO) << "Attempting to load a SessionBundle from: " << export_dir; LOG(INFO) << "Attempting to load a SessionBundle from: " << export_dir;
LOG(INFO) << "Using RunOptions: " << DebugStringIfAvailable(run_options); LOG(INFO) << "Using RunOptions: " << DebugStringIfAvailable(run_options);
TF_RETURN_IF_ERROR( TF_RETURN_IF_ERROR(
@ -227,17 +230,16 @@ Status LoadSessionBundleFromPathUsingRunOptionsInternal(
} // namespace } // namespace
Status LoadSessionBundleFromPath(const SessionOptions& options, Status LoadSessionBundleFromPath(const SessionOptions& options,
const StringPiece export_dir, const absl::string_view export_dir,
SessionBundle* const bundle) { SessionBundle* const bundle) {
TF_RETURN_IF_ERROR(LoadSessionBundleFromPathUsingRunOptions( TF_RETURN_IF_ERROR(LoadSessionBundleFromPathUsingRunOptions(
options, RunOptions(), export_dir, bundle)); options, RunOptions(), export_dir, bundle));
return Status::OK(); return Status::OK();
} }
Status LoadSessionBundleFromPathUsingRunOptions(const SessionOptions& options, Status LoadSessionBundleFromPathUsingRunOptions(
const RunOptions& run_options, const SessionOptions& options, const RunOptions& run_options,
const StringPiece export_dir, const absl::string_view export_dir, SessionBundle* const bundle) {
SessionBundle* const bundle) {
const uint64 start_microseconds = Env::Default()->NowMicros(); const uint64 start_microseconds = Env::Default()->NowMicros();
const Status status = LoadSessionBundleFromPathUsingRunOptionsInternal( const Status status = LoadSessionBundleFromPathUsingRunOptionsInternal(
options, run_options, export_dir, bundle); options, run_options, export_dir, bundle);
@ -263,7 +265,7 @@ Status LoadSessionBundleFromPathUsingRunOptions(const SessionOptions& options,
return status; return status;
} }
bool IsPossibleExportDirectory(const StringPiece directory) { bool IsPossibleExportDirectory(const absl::string_view directory) {
const string meta_graph_def_path = const string meta_graph_def_path =
io::JoinPath(directory, kMetaGraphDefFilename); io::JoinPath(directory, kMetaGraphDefFilename);
return Env::Default()->FileExists(meta_graph_def_path).ok(); return Env::Default()->FileExists(meta_graph_def_path).ok();

View File

@ -20,10 +20,10 @@ limitations under the License.
#include <memory> #include <memory>
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/session_bundle/manifest.pb.h" #include "tensorflow/contrib/session_bundle/manifest.pb.h"
#include "tensorflow/contrib/session_bundle/signature.h" #include "tensorflow/contrib/session_bundle/signature.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h" #include "tensorflow/core/protobuf/meta_graph.pb.h"
#include "tensorflow/core/protobuf/saver.pb.h" #include "tensorflow/core/protobuf/saver.pb.h"
#include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session.h"
@ -60,7 +60,7 @@ struct SessionBundle {
// Loads a manifest and initialized session using the output of an Exporter. // Loads a manifest and initialized session using the output of an Exporter.
Status LoadSessionBundleFromPath(const SessionOptions& options, Status LoadSessionBundleFromPath(const SessionOptions& options,
const StringPiece export_dir, const absl::string_view export_dir,
SessionBundle* bundle); SessionBundle* bundle);
// Similar to the LoadSessionBundleFromPath(), but also allows the session run // Similar to the LoadSessionBundleFromPath(), but also allows the session run
@ -70,14 +70,14 @@ Status LoadSessionBundleFromPath(const SessionOptions& options,
// This method is EXPERIMENTAL and may change or be removed. // This method is EXPERIMENTAL and may change or be removed.
Status LoadSessionBundleFromPathUsingRunOptions( Status LoadSessionBundleFromPathUsingRunOptions(
const SessionOptions& session_options, const RunOptions& run_options, const SessionOptions& session_options, const RunOptions& run_options,
const StringPiece export_dir, SessionBundle* bundle); const absl::string_view export_dir, SessionBundle* bundle);
// Sanity checks whether the directory looks like an export directory. Note that // Sanity checks whether the directory looks like an export directory. Note that
// we don't try to load any data in this method. // we don't try to load any data in this method.
// //
// If the method returns false this is definitely not an export directory, if it // If the method returns false this is definitely not an export directory, if it
// returns true, it is no guarantee that the model will load. // returns true, it is no guarantee that the model will load.
bool IsPossibleExportDirectory(const StringPiece export_dir); bool IsPossibleExportDirectory(const absl::string_view export_dir);
} // namespace serving } // namespace serving
} // namespace tensorflow } // namespace tensorflow

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <memory> #include <memory>
#include "google/protobuf/any.pb.h" #include "google/protobuf/any.pb.h"
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/session_bundle/manifest.pb.h" #include "tensorflow/contrib/session_bundle/manifest.pb.h"
#include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor.h"
@ -25,7 +26,6 @@ limitations under the License.
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test.h"
#include "tensorflow/core/public/session.h" #include "tensorflow/core/public/session.h"
@ -34,7 +34,7 @@ namespace tensorflow {
namespace serving { namespace serving {
namespace { namespace {
static bool HasSubstr(StringPiece base, StringPiece substr) { static bool HasSubstr(absl::string_view base, absl::string_view substr) {
bool ok = str_util::StrContains(base, substr); bool ok = str_util::StrContains(base, substr);
EXPECT_TRUE(ok) << base << ", expected substring " << substr; EXPECT_TRUE(ok) << base << ", expected substring " << substr;
return ok; return ok;

View File

@ -47,6 +47,7 @@ cc_library(
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"//tensorflow/core/kernels:summary_interface", "//tensorflow/core/kernels:summary_interface",
"//tensorflow/core/lib/db:sqlite", "//tensorflow/core/lib/db:sqlite",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -16,12 +16,12 @@ limitations under the License.
#include <deque> #include <deque>
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/tensorboard/db/summary_converter.h" #include "tensorflow/contrib/tensorboard/db/summary_converter.h"
#include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/register_types.h" #include "tensorflow/core/framework/register_types.h"
#include "tensorflow/core/framework/summary.pb.h" #include "tensorflow/core/framework/summary.pb.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/db/sqlite.h" #include "tensorflow/core/lib/db/sqlite.h"
#include "tensorflow/core/lib/random/random.h" #include "tensorflow/core/lib/random/random.h"
#include "tensorflow/core/util/event.pb.h" #include "tensorflow/core/util/event.pb.h"
@ -136,7 +136,7 @@ void PatchPluginName(SummaryMetadata* metadata, const char* name) {
} }
} }
Status SetDescription(Sqlite* db, int64 id, const StringPiece& markdown) { Status SetDescription(Sqlite* db, int64 id, const absl::string_view& markdown) {
const char* sql = R"sql( const char* sql = R"sql(
INSERT OR REPLACE INTO Descriptions (id, description) VALUES (?, ?) INSERT OR REPLACE INTO Descriptions (id, description) VALUES (?, ?)
)sql"; )sql";
@ -260,12 +260,12 @@ class GraphWriter {
for (int node_id = 0; node_id < graph_->node_size(); ++node_id) { for (int node_id = 0; node_id < graph_->node_size(); ++node_id) {
const NodeDef& node = graph_->node(node_id); const NodeDef& node = graph_->node(node_id);
for (int idx = 0; idx < node.input_size(); ++idx) { for (int idx = 0; idx < node.input_size(); ++idx) {
StringPiece name = node.input(idx); absl::string_view name = node.input(idx);
int64 input_node_id; int64 input_node_id;
int64 input_node_idx = 0; int64 input_node_idx = 0;
int64 is_control = 0; int64 is_control = 0;
size_t i = name.rfind(':'); size_t i = name.rfind(':');
if (i != StringPiece::npos) { if (i != absl::string_view::npos) {
if (!strings::safe_strto64(name.substr(i + 1, name.size() - i - 1), if (!strings::safe_strto64(name.substr(i + 1, name.size() - i - 1),
&input_node_idx)) { &input_node_idx)) {
return errors::DataLoss("Bad NodeDef.input: ", name); return errors::DataLoss("Bad NodeDef.input: ", name);
@ -369,7 +369,8 @@ class GraphWriter {
const uint64 now_; const uint64 now_;
const int64 graph_id_; const int64 graph_id_;
std::vector<string> name_copies_; std::vector<string> name_copies_;
std::unordered_map<StringPiece, int64, StringPieceHasher> name_to_node_id_; std::unordered_map<absl::string_view, int64, StringPieceHasher>
name_to_node_id_;
TF_DISALLOW_COPY_AND_ASSIGN(GraphWriter); TF_DISALLOW_COPY_AND_ASSIGN(GraphWriter);
}; };
@ -680,7 +681,7 @@ class SeriesWriter {
} else { } else {
SqliteTransaction txn(*db); SqliteTransaction txn(*db);
TF_RETURN_IF_ERROR( TF_RETURN_IF_ERROR(
Update(db, step, computed_time, t, StringPiece(), rowid)); Update(db, step, computed_time, t, absl::string_view(), rowid));
TF_RETURN_IF_ERROR(UpdateNdString(db, t, rowid)); TF_RETURN_IF_ERROR(UpdateNdString(db, t, rowid));
return txn.Commit(); return txn.Commit();
} }
@ -690,7 +691,7 @@ class SeriesWriter {
} }
Status Update(Sqlite* db, int64 step, double computed_time, const Tensor& t, Status Update(Sqlite* db, int64 step, double computed_time, const Tensor& t,
const StringPiece& data, int64 rowid) { const absl::string_view& data, int64 rowid) {
const char* sql = R"sql( const char* sql = R"sql(
UPDATE OR REPLACE UPDATE OR REPLACE
Tensors Tensors

View File

@ -29,6 +29,7 @@ cc_library(
"//tensorflow/core:framework", "//tensorflow/core:framework",
"//tensorflow/core:lib", "//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -19,6 +19,7 @@ limitations under the License.
#include <ctime> #include <ctime>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/contrib/tpu/profiler/op_profile.pb.h" #include "tensorflow/contrib/tpu/profiler/op_profile.pb.h"
#include "tensorflow/contrib/tpu/profiler/trace_events.pb.h" #include "tensorflow/contrib/tpu/profiler/trace_events.pb.h"
#include "tensorflow/contrib/tpu/profiler/trace_events_to_json.h" #include "tensorflow/contrib/tpu/profiler/trace_events_to_json.h"
@ -63,7 +64,8 @@ Status WriteGzippedDataToFile(const string& filename, const string& data) {
return Status::OK(); return Status::OK();
} }
Status DumpTraceToLogDirectory(StringPiece run_dir, const string& host_prefix, Status DumpTraceToLogDirectory(absl::string_view run_dir,
const string& host_prefix,
const string& encoded_trace, std::ostream* os) { const string& encoded_trace, std::ostream* os) {
string proto_path = string proto_path =
JoinPath(run_dir, StrCat(host_prefix, kProtoTraceFileName)); JoinPath(run_dir, StrCat(host_prefix, kProtoTraceFileName));
@ -86,7 +88,7 @@ Status DumpTraceToLogDirectory(StringPiece run_dir, const string& host_prefix,
return Status::OK(); return Status::OK();
} }
Status DumpOpProfileToLogDirectory(StringPiece run_dir, Status DumpOpProfileToLogDirectory(absl::string_view run_dir,
const string& host_prefix, const string& host_prefix,
const tpu::op_profile::Profile& profile, const tpu::op_profile::Profile& profile,
std::ostream* os) { std::ostream* os) {
@ -107,7 +109,7 @@ Status DumpOpProfileToLogDirectory(StringPiece run_dir,
return Status::OK(); return Status::OK();
} }
Status DumpToolDataToLogDirectory(StringPiece run_dir, Status DumpToolDataToLogDirectory(absl::string_view run_dir,
const string& host_prefix, const string& host_prefix,
const tensorflow::ProfileToolData& tool, const tensorflow::ProfileToolData& tool,
std::ostream* os) { std::ostream* os) {

View File

@ -42,6 +42,7 @@ cc_library(
deps = [ deps = [
"//tensorflow/core:framework", "//tensorflow/core:framework",
"//tensorflow/core:lib", "//tensorflow/core:lib",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -17,7 +17,7 @@ limitations under the License.
#include <vector> #include <vector>
#include "tensorflow/core/lib/core/stringpiece.h" #include "absl/strings/string_view.h"
#include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/numbers.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/lib/strings/strcat.h"
@ -32,7 +32,7 @@ string VerbsUtil::AppendStepidToKey(const string& key, int64 step_id) {
// static // static
void VerbsUtil::GetKeyAndStepId(const string& key_with_step_id, string& key, void VerbsUtil::GetKeyAndStepId(const string& key_with_step_id, string& key,
int64& step_id) { int64& step_id) {
StringPiece s(key_with_step_id); absl::string_view s(key_with_step_id);
// a key (with step_id) has exact 6 parts if split by ";" // a key (with step_id) has exact 6 parts if split by ";"
// part 1: src_device; // part 1: src_device;
// part 2: src_incarnation; // part 2: src_incarnation;

View File

@ -485,6 +485,7 @@ cc_library(
":platform_port", ":platform_port",
":platform_protobuf", ":platform_protobuf",
"//tensorflow/core/platform/default/build_config:env", "//tensorflow/core/platform/default/build_config:env",
"@com_google_absl//absl/strings",
], ],
) )
@ -514,6 +515,7 @@ cc_library(
":lib", ":lib",
":lib_platform", ":lib_platform",
":platform_env", ":platform_env",
"@com_google_absl//absl/strings",
], ],
) )
@ -592,6 +594,7 @@ cc_library(
"//tensorflow/core/platform/default/build_config:other", "//tensorflow/core/platform/default/build_config:other",
"//tensorflow/core/platform/default/build_config:platformlib", "//tensorflow/core/platform/default/build_config:platformlib",
"//tensorflow/core/platform/default/build_config:port", "//tensorflow/core/platform/default/build_config:port",
"@com_google_absl//absl/strings",
], ],
) )
@ -978,6 +981,7 @@ cc_library(
":lib", ":lib",
":lib_internal", ":lib_internal",
":protos_all_cc", ":protos_all_cc",
"@com_google_absl//absl/strings",
], ],
) )
@ -1478,6 +1482,7 @@ cc_library(
"//tensorflow/core/kernels:ops_testutil", "//tensorflow/core/kernels:ops_testutil",
"//tensorflow/core/kernels:ops_util", "//tensorflow/core/kernels:ops_util",
"//tensorflow/core/kernels:random_ops", "//tensorflow/core/kernels:random_ops",
"@com_google_absl//absl/strings",
], ],
) )
@ -2193,6 +2198,7 @@ cc_library(
":lib_proto_parsing", ":lib_proto_parsing",
":abi", ":abi",
":core_stringpiece", ":core_stringpiece",
"@com_google_absl//absl/strings",
"//third_party/eigen3", "//third_party/eigen3",
"//tensorflow/core/platform/default/build_config:platformlib", "//tensorflow/core/platform/default/build_config:platformlib",
"@snappy", "@snappy",
@ -2618,6 +2624,7 @@ tf_cuda_library(
":protos_all_cc", ":protos_all_cc",
":stats_calculator_portable", ":stats_calculator_portable",
":version_lib", ":version_lib",
"@com_google_absl//absl/strings",
"//tensorflow/core/platform/default/build_config:platformlib", "//tensorflow/core/platform/default/build_config:platformlib",
"//tensorflow/core/kernels:bounds_check", "//tensorflow/core/kernels:bounds_check",
"//third_party/eigen3", "//third_party/eigen3",
@ -2748,6 +2755,7 @@ tf_cuda_library(
":proto_text", ":proto_text",
":protos_all_cc", ":protos_all_cc",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
], ],
) )
@ -2792,6 +2800,7 @@ tf_cuda_library(
":function_ops_op_lib", ":function_ops_op_lib",
":functional_grad", ":functional_grad",
":functional_ops_op_lib", ":functional_ops_op_lib",
"@com_google_absl//absl/strings",
"//tensorflow/core/kernels:bounds_check", "//tensorflow/core/kernels:bounds_check",
"//tensorflow/core/kernels:required", "//tensorflow/core/kernels:required",
":core_cpu_impl", ":core_cpu_impl",
@ -2921,6 +2930,7 @@ tf_cuda_library(
":lib_internal", ":lib_internal",
":proto_text", ":proto_text",
":protos_all_cc", ":protos_all_cc",
"@com_google_absl//absl/strings",
"//third_party/eigen3", "//third_party/eigen3",
"//tensorflow/core/grappler:grappler_item", "//tensorflow/core/grappler:grappler_item",
] + mkl_deps(), ] + mkl_deps(),
@ -3000,6 +3010,7 @@ tf_cuda_library(
":protos_all_cc", ":protos_all_cc",
"//tensorflow/core/debug:debug_graph_utils", "//tensorflow/core/debug:debug_graph_utils",
"//tensorflow/core/kernels:function_ops", "//tensorflow/core/kernels:function_ops",
"@com_google_absl//absl/strings",
], ],
alwayslink = 1, alwayslink = 1,
) )
@ -3123,6 +3134,7 @@ tf_cuda_library(
":protos_all_cc", ":protos_all_cc",
":stream_executor", ":stream_executor",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
], ],
alwayslink = 1, alwayslink = 1,
) )
@ -3252,6 +3264,7 @@ cc_library(
":lib", ":lib",
":lib_internal", ":lib_internal",
":protos_all_cc", ":protos_all_cc",
"@com_google_absl//absl/strings",
], ],
) )
@ -3367,6 +3380,7 @@ tf_cc_tests(
":test", ":test",
":test_main", ":test_main",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
"@zlib_archive//:zlib", "@zlib_archive//:zlib",
], ],
) )
@ -3398,6 +3412,7 @@ tf_cc_test(
":test", ":test",
":test_main", ":test_main",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
], ],
) )
@ -3469,6 +3484,7 @@ tf_cc_test(
":protos_all_cc", ":protos_all_cc",
":test", ":test",
":test_main", ":test_main",
"@com_google_absl//absl/strings",
], ],
) )
@ -3518,6 +3534,7 @@ tf_cc_test(
":lib_internal", ":lib_internal",
":test", ":test",
":test_main", ":test_main",
"@com_google_absl//absl/strings",
], ],
) )
@ -3679,6 +3696,7 @@ tf_cc_tests(
"//tensorflow/cc:while_loop", "//tensorflow/cc:while_loop",
"//tensorflow/core/kernels:ops_util", "//tensorflow/core/kernels:ops_util",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
], ],
) )
@ -3715,6 +3733,7 @@ tf_cc_tests(
"//tensorflow/cc:sendrecv_ops", "//tensorflow/cc:sendrecv_ops",
"//tensorflow/core/kernels:ops_util", "//tensorflow/core/kernels:ops_util",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
], ],
) )
@ -3898,6 +3917,7 @@ tf_cc_tests_gpu(
":testlib", ":testlib",
"//tensorflow/cc:cc_ops", "//tensorflow/cc:cc_ops",
"//tensorflow/core/kernels:ops_util", "//tensorflow/core/kernels:ops_util",
"@com_google_absl//absl/strings",
], ],
) )
@ -3946,6 +3966,7 @@ tf_cuda_cc_test(
":testlib", ":testlib",
"//tensorflow/cc:cc_ops", "//tensorflow/cc:cc_ops",
"//tensorflow/core/kernels:ops_util", "//tensorflow/core/kernels:ops_util",
"@com_google_absl//absl/strings",
], ],
) )
@ -4062,6 +4083,7 @@ tf_cc_test(
"//tensorflow/core/kernels:immutable_constant_op", "//tensorflow/core/kernels:immutable_constant_op",
"//tensorflow/core/kernels:matmul_op", "//tensorflow/core/kernels:matmul_op",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
], ],
) )
@ -4172,6 +4194,7 @@ tf_cuda_cc_test(
":test", ":test",
":test_main", ":test_main",
":testlib", ":testlib",
"@com_google_absl//absl/strings",
"//third_party/eigen3", "//third_party/eigen3",
"//tensorflow/cc:cc_ops", "//tensorflow/cc:cc_ops",
"//tensorflow/core/kernels:collective_ops", "//tensorflow/core/kernels:collective_ops",
@ -4212,6 +4235,7 @@ tf_cc_test(
":test", ":test",
":test_main", ":test_main",
":testlib", ":testlib",
"@com_google_absl//absl/strings",
"//third_party/eigen3", "//third_party/eigen3",
"//tensorflow/cc:cc_ops", "//tensorflow/cc:cc_ops",
# Link with support for TensorFlow Debugger (tfdbg). # Link with support for TensorFlow Debugger (tfdbg).
@ -4352,6 +4376,7 @@ tf_cc_test(
"//tensorflow/core/kernels:random_ops", "//tensorflow/core/kernels:random_ops",
"//tensorflow/core/kernels:shape_ops", "//tensorflow/core/kernels:shape_ops",
"//third_party/eigen3", "//third_party/eigen3",
"@com_google_absl//absl/strings",
], ],
) )
@ -4744,6 +4769,7 @@ tf_cc_tests(
"//tensorflow/cc:client_session", "//tensorflow/cc:client_session",
"//tensorflow/cc:function_ops", "//tensorflow/cc:function_ops",
"//tensorflow/cc:ops", "//tensorflow/cc:ops",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/constant_folding.h" #include "tensorflow/core/common_runtime/constant_folding.h"
#include "tensorflow/cc/ops/array_ops_internal.h" #include "tensorflow/cc/ops/array_ops_internal.h"
@ -640,7 +641,7 @@ class TestTFFileSystem : public ::tensorflow::NullFileSystem {
return ::tensorflow::errors::Unimplemented( return ::tensorflow::errors::Unimplemented(
"NewReadOnlyMemoryRegionFromFile unimplemented"); "NewReadOnlyMemoryRegionFromFile unimplemented");
} }
const ::tensorflow::StringPiece sp = data_tensor_.tensor_data(); const ::absl::string_view sp = data_tensor_.tensor_data();
*result = std::unique_ptr<::tensorflow::ReadOnlyMemoryRegion>( *result = std::unique_ptr<::tensorflow::ReadOnlyMemoryRegion>(
new TestReadOnlyMemoryRegion(sp.data(), sp.size())); new TestReadOnlyMemoryRegion(sp.data(), sp.size()));
return ::tensorflow::Status::OK(); return ::tensorflow::Status::OK();

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <atomic> #include <atomic>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/dma_helper.h" #include "tensorflow/core/common_runtime/dma_helper.h"
#include "tensorflow/core/framework/variant_op_registry.h" #include "tensorflow/core/framework/variant_op_registry.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
@ -48,7 +49,7 @@ std::vector<RegistrationInfo>* MutableRegistry() {
} }
void CopyHostToDevice(const Tensor* input, Allocator* cpu_allocator, void CopyHostToDevice(const Tensor* input, Allocator* cpu_allocator,
Allocator* out_allocator, StringPiece edge_name, Allocator* out_allocator, absl::string_view edge_name,
Device* dst, Tensor* output, Device* dst, Tensor* output,
DeviceContext* recv_dev_context, StatusCallback done) { DeviceContext* recv_dev_context, StatusCallback done) {
if (input->dtype() == DT_VARIANT) { if (input->dtype() == DT_VARIANT) {
@ -113,7 +114,7 @@ void CopyHostToDevice(const Tensor* input, Allocator* cpu_allocator,
} }
void CopyDeviceToHost(const Tensor* input, Allocator* cpu_allocator, void CopyDeviceToHost(const Tensor* input, Allocator* cpu_allocator,
Allocator* out_allocator, StringPiece edge_name, Allocator* out_allocator, absl::string_view edge_name,
Device* src, Tensor* output, Device* src, Tensor* output,
DeviceContext* send_dev_context, StatusCallback done) { DeviceContext* send_dev_context, StatusCallback done) {
if (input->dtype() == DT_VARIANT) { if (input->dtype() == DT_VARIANT) {
@ -246,7 +247,8 @@ void CopyDeviceToDevice(CopyTensor::CopyFunction copy_function,
} // namespace } // namespace
// static // static
void CopyTensor::ViaDMA(StringPiece edge_name, DeviceContext* send_dev_context, void CopyTensor::ViaDMA(absl::string_view edge_name,
DeviceContext* send_dev_context,
DeviceContext* recv_dev_context, Device* src, DeviceContext* recv_dev_context, Device* src,
Device* dst, const AllocatorAttributes src_alloc_attr, Device* dst, const AllocatorAttributes src_alloc_attr,
const AllocatorAttributes dst_alloc_attr, const AllocatorAttributes dst_alloc_attr,

View File

@ -16,6 +16,7 @@ limitations under the License.
#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_COPY_TENSOR_H_ #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_COPY_TENSOR_H_
#define TENSORFLOW_CORE_COMMON_RUNTIME_COPY_TENSOR_H_ #define TENSORFLOW_CORE_COMMON_RUNTIME_COPY_TENSOR_H_
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/framework/allocator.h" #include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/framework/device_base.h" #include "tensorflow/core/framework/device_base.h"
@ -40,7 +41,8 @@ class CopyTensor {
// the type of devices and memory in use, the copy may be performed // the type of devices and memory in use, the copy may be performed
// synchronously or asynchronously. 'done' will be invoked only // synchronously or asynchronously. 'done' will be invoked only
// after the copy is actually complete. // after the copy is actually complete.
static void ViaDMA(StringPiece edge_name, DeviceContext* send_dev_context, static void ViaDMA(absl::string_view edge_name,
DeviceContext* send_dev_context,
DeviceContext* recv_dev_context, Device* src, Device* dst, DeviceContext* recv_dev_context, Device* src, Device* dst,
const AllocatorAttributes src_alloc_attr, const AllocatorAttributes src_alloc_attr,
const AllocatorAttributes dst_alloc_attr, const AllocatorAttributes dst_alloc_attr,

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/device_mgr.h"
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/local_device.h" #include "tensorflow/core/common_runtime/local_device.h"
#include "tensorflow/core/framework/device_attributes.pb.h" #include "tensorflow/core/framework/device_attributes.pb.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
@ -51,11 +52,11 @@ DeviceMgr::~DeviceMgr() {
for (Device* p : devices_) delete p; for (Device* p : devices_) delete p;
} }
StringPiece DeviceMgr::CopyToBackingStore(StringPiece s) { absl::string_view DeviceMgr::CopyToBackingStore(absl::string_view s) {
size_t n = s.size(); size_t n = s.size();
char* space = name_backing_store_.Alloc(n); char* space = name_backing_store_.Alloc(n);
memcpy(space, s.data(), n); memcpy(space, s.data(), n);
return StringPiece(space, n); return absl::string_view(space, n);
} }
void DeviceMgr::ListDeviceAttributes( void DeviceMgr::ListDeviceAttributes(
@ -89,11 +90,11 @@ string DeviceMgr::DeviceMappingString() const {
return out; return out;
} }
Status DeviceMgr::LookupDevice(StringPiece name, Device** device) const { Status DeviceMgr::LookupDevice(absl::string_view name, Device** device) const {
Status s; Status s;
auto iter = device_map_.find(name); auto iter = device_map_.find(name);
if (iter == device_map_.end()) { if (iter == device_map_.end()) {
std::vector<StringPiece> device_names; std::vector<absl::string_view> device_names;
for (auto&& itr : device_map_) { for (auto&& itr : device_map_) {
device_names.push_back(itr.first); device_names.push_back(itr.first);
} }

View File

@ -21,10 +21,10 @@ limitations under the License.
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/lib/core/arena.h" #include "tensorflow/core/lib/core/arena.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/lib/gtl/inlined_vector.h"
#include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/macros.h"
@ -53,7 +53,7 @@ class DeviceMgr {
// Assigns *device with pointer to Device of the given name. // Assigns *device with pointer to Device of the given name.
// Accepts either a full device name, or just the replica-local suffix. // Accepts either a full device name, or just the replica-local suffix.
Status LookupDevice(StringPiece name, Device** device) const; Status LookupDevice(absl::string_view name, Device** device) const;
// Clears given containers of all devices if 'container' is // Clears given containers of all devices if 'container' is
// non-empty. Otherwise, clears default containers of all devices. // non-empty. Otherwise, clears default containers of all devices.
@ -66,9 +66,9 @@ class DeviceMgr {
typedef gtl::InlinedVector<Device*, 8> DeviceVec; typedef gtl::InlinedVector<Device*, 8> DeviceVec;
DeviceVec devices_; DeviceVec devices_;
StringPiece CopyToBackingStore(StringPiece s); absl::string_view CopyToBackingStore(absl::string_view s);
std::unordered_map<StringPiece, Device*, StringPieceHasher> device_map_; std::unordered_map<absl::string_view, Device*, StringPieceHasher> device_map_;
core::Arena name_backing_store_; // Storage for keys in device_map_ core::Arena name_backing_store_; // Storage for keys in device_map_
std::unordered_map<string, int> device_type_counts_; std::unordered_map<string, int> device_type_counts_;

View File

@ -19,9 +19,9 @@ limitations under the License.
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/device_factory.h" #include "tensorflow/core/common_runtime/device_factory.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/gtl/map_util.h"
namespace tensorflow { namespace tensorflow {
@ -68,7 +68,7 @@ static bool DeviceTypeComparator(const DeviceType& a, const DeviceType& b) {
return a_priority > b_priority; return a_priority > b_priority;
} }
return StringPiece(a.type()) < StringPiece(b.type()); return absl::string_view(a.type()) < absl::string_view(b.type());
} }
std::vector<DeviceType> DeviceSet::PrioritizedDeviceTypeList() const { std::vector<DeviceType> DeviceSet::PrioritizedDeviceTypeList() const {

View File

@ -19,6 +19,7 @@ limitations under the License.
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/collective_executor_mgr.h" #include "tensorflow/core/common_runtime/collective_executor_mgr.h"
#include "tensorflow/core/common_runtime/collective_param_resolver_local.h" #include "tensorflow/core/common_runtime/collective_param_resolver_local.h"
#include "tensorflow/core/common_runtime/constant_folding.h" #include "tensorflow/core/common_runtime/constant_folding.h"
@ -1192,7 +1193,7 @@ Status DirectSession::CreateExecutors(
if (run_state_args->is_partial_run) { if (run_state_args->is_partial_run) {
ek->graph = std::move(run_state_args->graph); ek->graph = std::move(run_state_args->graph);
std::unordered_set<StringPiece, StringPieceHasher> names; std::unordered_set<absl::string_view, StringPieceHasher> names;
for (const string& input : callable_options.feed()) { for (const string& input : callable_options.feed()) {
TensorId id(ParseTensorName(input)); TensorId id(ParseTensorName(input));
names.emplace(id.first); names.emplace(id.first);

View File

@ -23,6 +23,7 @@ limitations under the License.
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/costmodel_manager.h" #include "tensorflow/core/common_runtime/costmodel_manager.h"
#include "tensorflow/core/common_runtime/debugger_state_interface.h" #include "tensorflow/core/common_runtime/debugger_state_interface.h"
#include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/device_mgr.h"
@ -65,7 +66,8 @@ class DirectSession : public Session {
~DirectSession() override; ~DirectSession() override;
typedef std::vector<std::pair<string, Tensor>> NamedTensorList; typedef std::vector<std::pair<string, Tensor>> NamedTensorList;
typedef std::unordered_map<StringPiece, Node*, StringPieceHasher> NameNodeMap; typedef std::unordered_map<absl::string_view, Node*, StringPieceHasher>
NameNodeMap;
::tensorflow::Status Create(const GraphDef& graph) override; ::tensorflow::Status Create(const GraphDef& graph) override;
::tensorflow::Status Extend(const GraphDef& graph) override; ::tensorflow::Status Extend(const GraphDef& graph) override;

View File

@ -22,6 +22,7 @@ limitations under the License.
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device_factory.h" #include "tensorflow/core/common_runtime/device_factory.h"
#include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/device_mgr.h"
#include "tensorflow/core/common_runtime/function_testlib.h" #include "tensorflow/core/common_runtime/function_testlib.h"
@ -2040,8 +2041,8 @@ void TestFeedAndFetchTensorsInDeviceMemory(
<< DataType_Name(dtype); << DataType_Name(dtype);
TF_ASSERT_OK(session->ReleaseCallable(handle)) << DataType_Name(dtype); TF_ASSERT_OK(session->ReleaseCallable(handle)) << DataType_Name(dtype);
ASSERT_EQ(1, outputs.size()); ASSERT_EQ(1, outputs.size());
const StringPiece actual_data = outputs[0].tensor_data(); const absl::string_view actual_data = outputs[0].tensor_data();
const StringPiece expected_data = host_tensor.tensor_data(); const absl::string_view expected_data = host_tensor.tensor_data();
EXPECT_EQ(expected_data.size(), actual_data.size()) << DataType_Name(dtype); EXPECT_EQ(expected_data.size(), actual_data.size()) << DataType_Name(dtype);
EXPECT_EQ(0, memcmp(expected_data.data(), actual_data.data(), EXPECT_EQ(0, memcmp(expected_data.data(), actual_data.data(),
std::min(expected_data.size(), actual_data.size()))) std::min(expected_data.size(), actual_data.size())))

View File

@ -49,6 +49,7 @@ tf_cuda_library(
deps = [ deps = [
":eager_executor", ":eager_executor",
":kernel_and_device", ":kernel_and_device",
"@com_google_absl//absl/strings",
] + select({ ] + select({
"//tensorflow:android": [ "//tensorflow:android": [
"//tensorflow/core:android_tensorflow_lib_lite", "//tensorflow/core:android_tensorflow_lib_lite",
@ -197,6 +198,7 @@ cc_library(
":eager_operation", ":eager_operation",
":kernel_and_device", ":kernel_and_device",
":tensor_handle", ":tensor_handle",
"@com_google_absl//absl/strings",
] + select({ ] + select({
"//tensorflow:android": [ "//tensorflow:android": [
"//tensorflow/core:android_tensorflow_lib_lite", "//tensorflow/core:android_tensorflow_lib_lite",
@ -221,6 +223,7 @@ tf_cuda_library(
deps = [ deps = [
":kernel_and_device", ":kernel_and_device",
"@farmhash_archive//:farmhash", "@farmhash_archive//:farmhash",
"@com_google_absl//absl/strings",
# Only the TF_AttrType enum is required, so pull in just the C headers. # Only the TF_AttrType enum is required, so pull in just the C headers.
# TODO(b/113535673): Break this dependency and avoid the C header completely. # TODO(b/113535673): Break this dependency and avoid the C header completely.
"//tensorflow/c:c_api_headers", "//tensorflow/c:c_api_headers",

View File

@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/core/common_runtime/eager/attr_builder.h" #include "tensorflow/core/common_runtime/eager/attr_builder.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device_factory.h" #include "tensorflow/core/common_runtime/device_factory.h"
#include "tensorflow/core/common_runtime/eager/kernel_and_device.h" #include "tensorflow/core/common_runtime/eager/kernel_and_device.h"
#include "tensorflow/core/common_runtime/rendezvous_mgr.h" #include "tensorflow/core/common_runtime/rendezvous_mgr.h"
@ -96,11 +97,12 @@ Status AttrTypeMapForOp(const char* op_name, const AttrTypeMap** out) {
return Status::OK(); return Status::OK();
} }
#define DEFINE_SET_ATTR(value_type, value_field) \ #define DEFINE_SET_ATTR(value_type, value_field) \
template <> \ template <> \
AttrBuilder& AttrBuilder::Set(StringPiece attr_name, value_type&& value) { \ AttrBuilder& AttrBuilder::Set(absl::string_view attr_name, \
value_field.push_back(std::make_pair(attr_name, value)); \ value_type&& value) { \
return *this; \ value_field.push_back(std::make_pair(attr_name, value)); \
return *this; \
} }
DEFINE_SET_ATTR(float, float_attrs_); DEFINE_SET_ATTR(float, float_attrs_);
@ -194,13 +196,13 @@ void CombineUnordered(const tensorflow::Fprint128& a,
b->high64 += a.high64; b->high64 += a.high64;
} }
inline tensorflow::Fprint128 CacheKeyHelper(StringPiece s, inline tensorflow::Fprint128 CacheKeyHelper(absl::string_view s,
const tensorflow::Fprint128& b) { const tensorflow::Fprint128& b) {
tensorflow::Fprint128 a = tensorflow::Fingerprint128(s); tensorflow::Fprint128 a = tensorflow::Fingerprint128(s);
return FingerprintCat128(a, b); return FingerprintCat128(a, b);
} }
inline tensorflow::Fprint128 CacheKeyHelper(StringPiece s, uint64 b) { inline tensorflow::Fprint128 CacheKeyHelper(absl::string_view s, uint64 b) {
return CacheKeyHelper(s, {b, b}); return CacheKeyHelper(s, {b, b});
} }

View File

@ -21,6 +21,7 @@ limitations under the License.
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
#include "absl/strings/string_view.h"
#include "tensorflow/c/c_api.h" #include "tensorflow/c/c_api.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/eager/kernel_and_device.h" #include "tensorflow/core/common_runtime/eager/kernel_and_device.h"
@ -94,7 +95,7 @@ class AttrBuilder {
AttrBuilder& NumInputs(int n); AttrBuilder& NumInputs(int n);
template <class T> template <class T>
AttrBuilder& Set(StringPiece attr_name, T&& value) { AttrBuilder& Set(absl::string_view attr_name, T&& value) {
MayBeInitializeNodeDef(); MayBeInitializeNodeDef();
SetInAttrValueMap(node_def_->mutable_attr(), attr_name, value); SetInAttrValueMap(node_def_->mutable_attr(), attr_name, value);
return *this; return *this;
@ -107,7 +108,8 @@ class AttrBuilder {
private: private:
template <class T> template <class T>
using AttrVec = tensorflow::gtl::InlinedVector<std::pair<StringPiece, T>, 2>; using AttrVec =
tensorflow::gtl::InlinedVector<std::pair<absl::string_view, T>, 2>;
void MayBeInitializeNodeDef(); void MayBeInitializeNodeDef();
// Fill `m` with the attr-value pairs set via AttrBuilder::Set() so far, as // Fill `m` with the attr-value pairs set via AttrBuilder::Set() so far, as
@ -119,7 +121,7 @@ class AttrBuilder {
void FillAttrValueMap(AttrValueMap* m, bool include_those_in_node_def) const; void FillAttrValueMap(AttrValueMap* m, bool include_those_in_node_def) const;
template <class T> template <class T>
void SetInAttrValueMap(AttrValueMap* m, StringPiece attr_name, void SetInAttrValueMap(AttrValueMap* m, absl::string_view attr_name,
T&& value) const { T&& value) const {
DCHECK(!node_def_finalized_) DCHECK(!node_def_finalized_)
<< "Calling SetInAttrValueMap after BuildNodeDef."; << "Calling SetInAttrValueMap after BuildNodeDef.";
@ -148,16 +150,15 @@ class AttrBuilder {
}; // namespace tensorflow }; // namespace tensorflow
template <> template <>
AttrBuilder& AttrBuilder::Set(StringPiece attr_name, int&& value); AttrBuilder& AttrBuilder::Set(absl::string_view attr_name, int&& value);
template <> template <>
AttrBuilder& AttrBuilder::Set(StringPiece attr_name, float&& value); AttrBuilder& AttrBuilder::Set(absl::string_view attr_name, float&& value);
template <> template <>
AttrBuilder& AttrBuilder::Set(StringPiece attr_name, bool&& value); AttrBuilder& AttrBuilder::Set(absl::string_view attr_name, bool&& value);
template <> template <>
AttrBuilder& AttrBuilder::Set(StringPiece attr_name, AttrBuilder& AttrBuilder::Set(absl::string_view attr_name,
tensorflow::DataType&& value); tensorflow::DataType&& value);
} // namespace tensorflow } // namespace tensorflow
#endif // TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_ATTR_BUILDER_H_ #endif // TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_ATTR_BUILDER_H_

View File

@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/core/common_runtime/eager/context.h" #include "tensorflow/core/common_runtime/eager/context.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device_set.h" #include "tensorflow/core/common_runtime/device_set.h"
#include "tensorflow/core/common_runtime/process_util.h" #include "tensorflow/core/common_runtime/process_util.h"
#include "tensorflow/core/framework/resource_mgr.h" #include "tensorflow/core/framework/resource_mgr.h"
@ -24,7 +25,7 @@ limitations under the License.
namespace tensorflow { namespace tensorflow {
namespace { namespace {
bool ReadBoolFromEnvVar(StringPiece env_var_name, bool default_val) { bool ReadBoolFromEnvVar(absl::string_view env_var_name, bool default_val) {
bool val; bool val;
if (tensorflow::ReadBoolFromEnvVar(env_var_name, default_val, &val).ok()) { if (tensorflow::ReadBoolFromEnvVar(env_var_name, default_val, &val).ok()) {
return val; return val;

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/device_set.h" #include "tensorflow/core/common_runtime/device_set.h"
#include "tensorflow/core/common_runtime/eager/context.h" #include "tensorflow/core/common_runtime/eager/context.h"
@ -820,7 +821,7 @@ Status FindDeviceFromName(EagerContext* ctx, const char* device_name,
} }
Status ExecuteSend(EagerContext* ctx, tensorflow::Device* device, Status ExecuteSend(EagerContext* ctx, tensorflow::Device* device,
TensorHandle* h, StringPiece wire_id, TensorHandle* h, absl::string_view wire_id,
const string& recv_device) { const string& recv_device) {
const tensorflow::AttrTypeMap* types; const tensorflow::AttrTypeMap* types;
TF_RETURN_IF_ERROR(tensorflow::AttrTypeMapForOp("_Send", &types)); TF_RETURN_IF_ERROR(tensorflow::AttrTypeMapForOp("_Send", &types));
@ -847,7 +848,7 @@ Status ExecuteSend(EagerContext* ctx, tensorflow::Device* device,
} }
Status ExecuteRecv(EagerContext* ctx, tensorflow::Device* device, Status ExecuteRecv(EagerContext* ctx, tensorflow::Device* device,
DataType dtype, StringPiece wire_id, DataType dtype, absl::string_view wire_id,
const string& send_device, int64 send_device_incarnation, const string& send_device, int64 send_device_incarnation,
TensorHandle** result) { TensorHandle** result) {
const tensorflow::AttrTypeMap* types; const tensorflow::AttrTypeMap* types;

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <deque> #include <deque>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/executor.h" #include "tensorflow/core/common_runtime/executor.h"
#include "tensorflow/core/common_runtime/executor_factory.h" #include "tensorflow/core/common_runtime/executor_factory.h"
@ -583,7 +584,7 @@ Status FunctionLibraryRuntimeImpl::ReleaseHandle(Handle handle) {
return Status::OK(); return Status::OK();
} }
void DumpGraph(StringPiece label, const Graph* g) { void DumpGraph(absl::string_view label, const Graph* g) {
// TODO(zhifengc): Change Graph to record #nodes. // TODO(zhifengc): Change Graph to record #nodes.
VLOG(1) << "Graph " << label << " #nodes " << g->num_nodes() << " #edges " VLOG(1) << "Graph " << label << " #nodes " << g->num_nodes() << " #edges "
<< g->num_edges(); << g->num_edges();

View File

@ -19,6 +19,7 @@ limitations under the License.
#include <functional> #include <functional>
#include <memory> #include <memory>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/device_mgr.h"
#include "tensorflow/core/common_runtime/process_function_library_runtime.h" #include "tensorflow/core/common_runtime/process_function_library_runtime.h"
@ -124,7 +125,7 @@ bool ExpandInlineFunctions(FunctionLibraryRuntime* lib, Graph* graph);
// Dump the contents of the "graph" to log files if the logging level is // Dump the contents of the "graph" to log files if the logging level is
// sufficiently high. // sufficiently high.
void DumpGraph(StringPiece label, const Graph* g); void DumpGraph(absl::string_view label, const Graph* g);
// Applies graph rewrite optimization such as inlining, dead code // Applies graph rewrite optimization such as inlining, dead code
// removal, etc. // removal, etc.

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <atomic> #include <atomic>
#include <utility> #include <utility>
#include "absl/strings/string_view.h"
#include "tensorflow/cc/ops/array_ops_internal.h" #include "tensorflow/cc/ops/array_ops_internal.h"
#include "tensorflow/cc/ops/function_ops.h" #include "tensorflow/cc/ops/function_ops.h"
#include "tensorflow/cc/ops/functional_ops.h" #include "tensorflow/cc/ops/functional_ops.h"
@ -55,7 +56,7 @@ Status GetOpSig(const string& op, const OpDef** sig) {
return OpRegistry::Global()->LookUpOpDef(op, sig); return OpRegistry::Global()->LookUpOpDef(op, sig);
} }
void HasError(const Status& s, StringPiece substr) { void HasError(const Status& s, absl::string_view substr) {
EXPECT_TRUE(str_util::StrContains(s.ToString(), substr)) EXPECT_TRUE(str_util::StrContains(s.ToString(), substr))
<< s << ", expected substring " << substr; << s << ", expected substring " << substr;
} }

View File

@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "absl/strings/string_view.h"
#if GOOGLE_CUDA #if GOOGLE_CUDA
#include "tensorflow/core/common_runtime/gpu/gpu_device.h" #include "tensorflow/core/common_runtime/gpu/gpu_device.h"
@ -53,7 +54,7 @@ Status GetComputeCapability(PlatformGpuId gpu_id, int* cc_major,
return Status::OK(); return Status::OK();
} }
void ExpectErrorMessageSubstr(const Status& s, StringPiece substr) { void ExpectErrorMessageSubstr(const Status& s, absl::string_view substr) {
EXPECT_TRUE(str_util::StrContains(s.ToString(), substr)) EXPECT_TRUE(str_util::StrContains(s.ToString(), substr))
<< s << ", expected substring " << substr; << s << ", expected substring " << substr;
} }

View File

@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/gpu/gpu_event_mgr.h" #include "tensorflow/core/common_runtime/gpu/gpu_event_mgr.h"
#include "tensorflow/core/common_runtime/gpu/gpu_util.h" #include "tensorflow/core/common_runtime/gpu/gpu_util.h"
@ -31,7 +32,7 @@ void GPUDeviceContext::CopyCPUTensorToDevice(const Tensor* cpu_tensor,
} }
void GPUDeviceContext::CopyDeviceTensorToCPU(const Tensor* device_tensor, void GPUDeviceContext::CopyDeviceTensorToCPU(const Tensor* device_tensor,
StringPiece tensor_name, absl::string_view tensor_name,
Device* device, Tensor* cpu_tensor, Device* device, Tensor* cpu_tensor,
StatusCallback done) { StatusCallback done) {
GPUUtil::CopyGPUTensorToCPU(device, this, device_tensor, cpu_tensor, done); GPUUtil::CopyGPUTensorToCPU(device, this, device_tensor, cpu_tensor, done);

View File

@ -16,6 +16,7 @@ limitations under the License.
#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_GPU_DEVICE_CONTEXT_H_ #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_GPU_DEVICE_CONTEXT_H_
#define TENSORFLOW_CORE_COMMON_RUNTIME_GPU_DEVICE_CONTEXT_H_ #define TENSORFLOW_CORE_COMMON_RUNTIME_GPU_DEVICE_CONTEXT_H_
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/framework/device_base.h" #include "tensorflow/core/framework/device_base.h"
#include "tensorflow/core/lib/gtl/inlined_vector.h" #include "tensorflow/core/lib/gtl/inlined_vector.h"
@ -53,9 +54,9 @@ class GPUDeviceContext : public DeviceContext {
Tensor* device_tensor, Tensor* device_tensor,
StatusCallback done) const override; StatusCallback done) const override;
void CopyDeviceTensorToCPU(const Tensor* device_tensor, StringPiece edge_name, void CopyDeviceTensorToCPU(const Tensor* device_tensor,
Device* device, Tensor* cpu_tensor, absl::string_view edge_name, Device* device,
StatusCallback done) override; Tensor* cpu_tensor, StatusCallback done) override;
void MaintainLifetimeOnStream(const Tensor* t, void MaintainLifetimeOnStream(const Tensor* t,
se::Stream* stream) const override {} se::Stream* stream) const override {}

View File

@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/core/common_runtime/lower_if_while.h" #include "tensorflow/core/common_runtime/lower_if_while.h"
#include "absl/strings/string_view.h"
#include "tensorflow/cc/client/client_session.h" #include "tensorflow/cc/client/client_session.h"
#include "tensorflow/cc/framework/ops.h" #include "tensorflow/cc/framework/ops.h"
#include "tensorflow/cc/ops/array_ops.h" #include "tensorflow/cc/ops/array_ops.h"
@ -38,7 +39,7 @@ namespace {
typedef FunctionDefHelper FDH; typedef FunctionDefHelper FDH;
static void AssertHasSubstr(StringPiece s, StringPiece expected) { static void AssertHasSubstr(absl::string_view s, absl::string_view expected) {
ASSERT_TRUE(str_util::StrContains(s, expected)) ASSERT_TRUE(str_util::StrContains(s, expected))
<< "'" << s << "' does not contain '" << expected << "'"; << "'" << s << "' does not contain '" << expected << "'";
} }

View File

@ -20,6 +20,7 @@ limitations under the License.
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/framework/device_attributes.pb.h" #include "tensorflow/core/framework/device_attributes.pb.h"
#include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph.pb.h"
@ -28,7 +29,6 @@ limitations under the License.
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
namespace tensorflow { namespace tensorflow {
@ -37,8 +37,9 @@ namespace {
// We hoist the conversion from C-style string literal to StringPiece here, // We hoist the conversion from C-style string literal to StringPiece here,
// so that we can avoid the many repeated calls to strlen(). // so that we can avoid the many repeated calls to strlen().
const StringPiece kColocationAttrNameStringPiece(kColocationAttrName); const absl::string_view kColocationAttrNameStringPiece(kColocationAttrName);
const StringPiece kColocationGroupPrefixStringPiece(kColocationGroupPrefix); const absl::string_view kColocationGroupPrefixStringPiece(
kColocationGroupPrefix);
// Returns a list of devices having type in supported_device_types. The // Returns a list of devices having type in supported_device_types. The
// returned list is sorted by preferred type (higher numeric type is preferred). // returned list is sorted by preferred type (higher numeric type is preferred).
@ -68,7 +69,7 @@ std::vector<Device*> FilterSupportedDevices(
if (a_priority != b_priority) { if (a_priority != b_priority) {
return a_priority > b_priority; return a_priority > b_priority;
} }
return StringPiece(a->name()) < StringPiece(b->name()); return absl::string_view(a->name()) < absl::string_view(b->name());
}; };
std::vector<Device*>::iterator sort_start; std::vector<Device*>::iterator sort_start;
if (filtered_default_device != nullptr) { if (filtered_default_device != nullptr) {
@ -144,7 +145,7 @@ class ColocationGraph {
// 'string' values stored in NodeDef attribute lists, as well as StringPiece // 'string' values stored in NodeDef attribute lists, as well as StringPiece
// values that refer to 'string' values from NodeDef::name(), without // values that refer to 'string' values from NodeDef::name(), without
// performing any string allocations. // performing any string allocations.
std::unordered_map<StringPiece, const Node*, StringPieceHasher> std::unordered_map<absl::string_view, const Node*, StringPieceHasher>
colocation_group_root; colocation_group_root;
for (Node* node : graph_->op_nodes()) { for (Node* node : graph_->op_nodes()) {
@ -161,7 +162,7 @@ class ColocationGraph {
node->attrs().Find(kColocationAttrNameStringPiece); node->attrs().Find(kColocationAttrNameStringPiece);
if (attr_value != nullptr && attr_value->has_list()) { if (attr_value != nullptr && attr_value->has_list()) {
for (const string& class_spec : attr_value->list().s()) { for (const string& class_spec : attr_value->list().s()) {
StringPiece spec(class_spec); absl::string_view spec(class_spec);
if (str_util::ConsumePrefix(&spec, if (str_util::ConsumePrefix(&spec,
kColocationGroupPrefixStringPiece)) { kColocationGroupPrefixStringPiece)) {
found_spec = true; found_spec = true;
@ -183,9 +184,9 @@ class ColocationGraph {
} }
Status ColocateNodeToGroup( Status ColocateNodeToGroup(
std::unordered_map<StringPiece, const Node*, StringPieceHasher>* std::unordered_map<absl::string_view, const Node*, StringPieceHasher>*
colocation_group_root, colocation_group_root,
Node* node, StringPiece colocation_group) { Node* node, absl::string_view colocation_group) {
const Node*& root_node = (*colocation_group_root)[colocation_group]; const Node*& root_node = (*colocation_group_root)[colocation_group];
if (root_node == nullptr) { if (root_node == nullptr) {
// This is the first node of the colocation group, so // This is the first node of the colocation group, so

View File

@ -16,10 +16,10 @@ limitations under the License.
#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_PROFILE_HANDLER_H_ #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_PROFILE_HANDLER_H_
#define TENSORFLOW_CORE_COMMON_RUNTIME_PROFILE_HANDLER_H_ #define TENSORFLOW_CORE_COMMON_RUNTIME_PROFILE_HANDLER_H_
#include "absl/strings/string_view.h"
#include "tensorflow/core/framework/step_stats.pb.h" #include "tensorflow/core/framework/step_stats.pb.h"
#include "tensorflow/core/graph/types.h" #include "tensorflow/core/graph/types.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/stringpiece.h"
namespace tensorflow { namespace tensorflow {
@ -41,8 +41,9 @@ class ProfileHandler {
// - op_type: String name of the Op. // - op_type: String name of the Op.
// - details: Main content for timeline click text. // - details: Main content for timeline click text.
virtual void RecordOneOp(const string& device, const NodeExecStats& stats, virtual void RecordOneOp(const string& device, const NodeExecStats& stats,
bool is_copy, StringPiece label, StringPiece op_type, bool is_copy, absl::string_view label,
StringPiece details) = 0; absl::string_view op_type,
absl::string_view details) = 0;
// Records that the current step finished. // Records that the current step finished.
// //

View File

@ -19,6 +19,7 @@ limitations under the License.
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/eval_const_tensor.h" #include "tensorflow/core/common_runtime/eval_const_tensor.h"
#include "tensorflow/core/framework/common_shape_fns.h" #include "tensorflow/core/framework/common_shape_fns.h"
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
@ -68,7 +69,7 @@ Status InferShapesForFunctionSubNode(const Node* node, ShapeRefiner* refiner,
TF_RETURN_IF_ERROR(refiner->AddNode(node)); TF_RETURN_IF_ERROR(refiner->AddNode(node));
InferenceContext* node_context = CHECK_NOTNULL(refiner->GetContext(node)); InferenceContext* node_context = CHECK_NOTNULL(refiner->GetContext(node));
if (StringPiece(node->type_string()) == kArgOp) { if (absl::string_view(node->type_string()) == kArgOp) {
// Handle special node: function input. // Handle special node: function input.
// Shapes for these nodes are provided in the outer inference // Shapes for these nodes are provided in the outer inference
// context. // context.
@ -88,7 +89,7 @@ Status InferShapesForFunctionSubNode(const Node* node, ShapeRefiner* refiner,
if (resource) { if (resource) {
node_context->set_output_handle_shapes_and_types(0, *resource); node_context->set_output_handle_shapes_and_types(0, *resource);
} }
} else if (StringPiece(node->type_string()) == kRetvalOp) { } else if (absl::string_view(node->type_string()) == kRetvalOp) {
// Handle special node: function output. // Handle special node: function output.
// Shapes inferred for these nodes go into the outer inference // Shapes inferred for these nodes go into the outer inference
// context. // context.

View File

@ -14,6 +14,7 @@ limitations under the License.
==============================================================================*/ ==============================================================================*/
#include "tensorflow/core/common_runtime/step_stats_collector.h" #include "tensorflow/core/common_runtime/step_stats_collector.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/costmodel_manager.h" #include "tensorflow/core/common_runtime/costmodel_manager.h"
#include "tensorflow/core/framework/allocation_description.pb.h" #include "tensorflow/core/framework/allocation_description.pb.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
@ -22,7 +23,6 @@ limitations under the License.
#include "tensorflow/core/framework/tracking_allocator.h" #include "tensorflow/core/framework/tracking_allocator.h"
#include "tensorflow/core/graph/costmodel.h" #include "tensorflow/core/graph/costmodel.h"
#include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/strings/numbers.h" #include "tensorflow/core/lib/strings/numbers.h"
#include "tensorflow/core/lib/strings/scanner.h" #include "tensorflow/core/lib/strings/scanner.h"
#include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/lib/strings/stringprintf.h"
@ -212,7 +212,7 @@ static int ExtractGpuWithStreamAll(string device_name) {
scanner.RestartCapture().Many(strings::Scanner::DIGIT).StopCapture(); scanner.RestartCapture().Many(strings::Scanner::DIGIT).StopCapture();
// Check that the digits are preceded by the 'device:GPU:' string // Check that the digits are preceded by the 'device:GPU:' string
scanner.OneLiteral(":UPG:ecived"); scanner.OneLiteral(":UPG:ecived");
StringPiece capture; absl::string_view capture;
bool matched = scanner.GetResult(nullptr, &capture); bool matched = scanner.GetResult(nullptr, &capture);
if (!matched) { if (!matched) {
@ -241,7 +241,7 @@ static int ExtractGpuWithoutStream(string device_name) {
scanner.RestartCapture().Many(strings::Scanner::DIGIT).StopCapture(); scanner.RestartCapture().Many(strings::Scanner::DIGIT).StopCapture();
// Check that the digits are preceded by the 'device:GPU:' string // Check that the digits are preceded by the 'device:GPU:' string
scanner.OneLiteral(":UPG:ecived"); scanner.OneLiteral(":UPG:ecived");
StringPiece capture; absl::string_view capture;
bool matched = scanner.GetResult(nullptr, &capture); bool matched = scanner.GetResult(nullptr, &capture);
if (!matched) { if (!matched) {
@ -276,7 +276,7 @@ void StepStatsCollector::BuildCostModel(
const DeviceStepStats* hardware_stats; const DeviceStepStats* hardware_stats;
}; };
std::unordered_map<StringPiece, DeviceStats, StringPieceHasher> std::unordered_map<absl::string_view, DeviceStats, StringPieceHasher>
per_device_stats; per_device_stats;
std::unordered_map<int, const DeviceStepStats*> gpu_hardware_stats; std::unordered_map<int, const DeviceStepStats*> gpu_hardware_stats;
@ -295,7 +295,7 @@ void StepStatsCollector::BuildCostModel(
} }
for (auto& itr : per_device_stats) { for (auto& itr : per_device_stats) {
const StringPiece device_name = itr.first; const absl::string_view device_name = itr.first;
const int gpu_id = ExtractGpuWithoutStream(string(device_name)); const int gpu_id = ExtractGpuWithoutStream(string(device_name));
if (gpu_id >= 0) { if (gpu_id >= 0) {
// Reference the gpu hardware stats in addition to the regular stats // Reference the gpu hardware stats in addition to the regular stats
@ -307,7 +307,7 @@ void StepStatsCollector::BuildCostModel(
} }
for (auto itr : device_map) { for (auto itr : device_map) {
const StringPiece device = itr.first; const absl::string_view device = itr.first;
if (per_device_stats.find(device) == per_device_stats.end()) { if (per_device_stats.find(device) == per_device_stats.end()) {
continue; continue;
} }
@ -316,7 +316,8 @@ void StepStatsCollector::BuildCostModel(
CostModel* cm = cost_model_manager->FindOrCreateCostModel(graph); CostModel* cm = cost_model_manager->FindOrCreateCostModel(graph);
cm->IncrementUpdateTimes(); cm->IncrementUpdateTimes();
std::unordered_map<StringPiece, Node*, StringPieceHasher> name_to_node; std::unordered_map<absl::string_view, Node*, StringPieceHasher>
name_to_node;
for (Node* n : graph->nodes()) { for (Node* n : graph->nodes()) {
name_to_node.emplace(n->name(), n); name_to_node.emplace(n->name(), n);
} }

View File

@ -109,6 +109,7 @@ tf_cuda_library(
"//tensorflow/core:lib_internal", "//tensorflow/core:lib_internal",
"//tensorflow/core:proto_text", "//tensorflow/core:proto_text",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/strings",
], ],
alwayslink = 1, alwayslink = 1,
) )
@ -132,6 +133,7 @@ tf_cuda_library(
"//tensorflow/core:lib_internal", "//tensorflow/core:lib_internal",
"//tensorflow/core:proto_text", "//tensorflow/core:proto_text",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"@com_google_absl//absl/strings",
], ],
alwayslink = 1, alwayslink = 1,
) )

View File

@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/core/debug/debug_graph_utils.h" #include "tensorflow/core/debug/debug_graph_utils.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/memory_types.h" #include "tensorflow/core/common_runtime/memory_types.h"
#include "tensorflow/core/framework/kernel_def.pb.h" #include "tensorflow/core/framework/kernel_def.pb.h"
#include "tensorflow/core/framework/node_def_builder.h" #include "tensorflow/core/framework/node_def_builder.h"
@ -344,7 +345,7 @@ Status DebugNodeInserter::ParseDebugOpName(
std::vector<string> attribute_segs = str_util::Split(arguments, ";"); std::vector<string> attribute_segs = str_util::Split(arguments, ";");
for (const string& attribute_seg : attribute_segs) { for (const string& attribute_seg : attribute_segs) {
StringPiece seg(attribute_seg); absl::string_view seg(attribute_seg);
str_util::RemoveWhitespaceContext(&seg); str_util::RemoveWhitespaceContext(&seg);
if (seg.empty()) { if (seg.empty()) {
continue; continue;

View File

@ -23,6 +23,7 @@ limitations under the License.
#include <limits> #include <limits>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#ifndef PLATFORM_WINDOWS #ifndef PLATFORM_WINDOWS
#include "grpcpp/create_channel.h" #include "grpcpp/create_channel.h"
@ -308,7 +309,7 @@ Status ReadEventFromFile(const string& dump_file_path, Event* event) {
return s; return s;
} }
StringPiece result; absl::string_view result;
s = file->Read(0, file_size, &result, &(content)[0]); s = file->Read(0, file_size, &result, &(content)[0]);
if (!s.ok()) { if (!s.ok()) {
return s; return s;

View File

@ -172,6 +172,7 @@ cc_library(
"//tensorflow/core:lib", "//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"//tensorflow/core:worker_proto_cc", "//tensorflow/core:worker_proto_cc",
"@com_google_absl//absl/strings",
], ],
) )
@ -288,6 +289,7 @@ cc_library(
"//tensorflow/core:core_cpu_internal", "//tensorflow/core:core_cpu_internal",
"//tensorflow/core:lib", "//tensorflow/core:lib",
"//tensorflow/core:worker_proto_cc", "//tensorflow/core:worker_proto_cc",
"@com_google_absl//absl/strings",
], ],
) )
@ -344,6 +346,7 @@ cc_library(
"//tensorflow/core:master_proto_cc", "//tensorflow/core:master_proto_cc",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"//tensorflow/core/debug:debug_graph_utils", "//tensorflow/core/debug:debug_graph_utils",
"@com_google_absl//absl/strings",
], ],
) )
@ -397,6 +400,7 @@ cc_library(
"//tensorflow/core:framework_internal", "//tensorflow/core:framework_internal",
"//tensorflow/core:lib", "//tensorflow/core:lib",
"//tensorflow/core:lib_internal", "//tensorflow/core:lib_internal",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/copy_tensor.h" #include "tensorflow/core/common_runtime/copy_tensor.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/device_mgr.h"
@ -144,8 +145,8 @@ BaseRemoteRendezvous::~BaseRemoteRendezvous() {
// Returns true if "device_name" is a valid full name of local device // Returns true if "device_name" is a valid full name of local device
// of the "worker". This helper is purely based on the worker name // of the "worker". This helper is purely based on the worker name
// and device name and does no lookups in the worker->device_mgr. // and device name and does no lookups in the worker->device_mgr.
static bool IsLocalDevice(const StringPiece worker_name, static bool IsLocalDevice(const absl::string_view worker_name,
const StringPiece device_name) { const absl::string_view device_name) {
return str_util::StartsWith(device_name, worker_name); return str_util::StartsWith(device_name, worker_name);
} }

View File

@ -19,6 +19,7 @@ limitations under the License.
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/process_util.h" #include "tensorflow/core/common_runtime/process_util.h"
#include "tensorflow/core/common_runtime/profile_handler.h" #include "tensorflow/core/common_runtime/profile_handler.h"
#include "tensorflow/core/common_runtime/stats_publisher_interface.h" #include "tensorflow/core/common_runtime/stats_publisher_interface.h"
@ -235,7 +236,7 @@ class MasterSession::ReffedClientGraph : public core::RefCounted {
const bool is_partial_; const bool is_partial_;
const CallableOptions callable_opts_; const CallableOptions callable_opts_;
WorkerCacheInterface* const worker_cache_; // Not owned. WorkerCacheInterface* const worker_cache_; // Not owned.
std::unordered_map<StringPiece, Node*, StringPieceHasher> name_to_node_; std::unordered_map<absl::string_view, Node*, StringPieceHasher> name_to_node_;
const bool should_deregister_; const bool should_deregister_;
std::atomic<int64> execution_count_ = {0}; std::atomic<int64> execution_count_ = {0};
@ -296,12 +297,14 @@ class MasterSession::ReffedClientGraph : public core::RefCounted {
// This is a generic method that handles Run, PartialRun, and RunCallable. // This is a generic method that handles Run, PartialRun, and RunCallable.
template <class FetchListType, class ClientRequestType, template <class FetchListType, class ClientRequestType,
class ClientResponseType> class ClientResponseType>
Status RunPartitionsHelper( Status RunPartitionsHelper(const std::unordered_map<absl::string_view, size_t,
const std::unordered_map<StringPiece, size_t, StringPieceHasher>& feeds, StringPieceHasher>& feeds,
const FetchListType& fetches, const MasterEnv* env, int64 step_id, const FetchListType& fetches, const MasterEnv* env,
int64 execution_count, PerStepState* pss, CallOptions* call_opts, int64 step_id, int64 execution_count,
const ClientRequestType& req, ClientResponseType* resp, PerStepState* pss, CallOptions* call_opts,
CancellationManager* cm, bool is_last_partial_run); const ClientRequestType& req,
ClientResponseType* resp, CancellationManager* cm,
bool is_last_partial_run);
// Deregisters the partitions on the workers. Called in the // Deregisters the partitions on the workers. Called in the
// destructor and does not wait for the rpc completion. // destructor and does not wait for the rpc completion.
@ -729,7 +732,7 @@ Status MasterSession::ReffedClientGraph::RunPartitions(
VLOG(2) << "RunPartitions step_id " << step_id << " execution_count " VLOG(2) << "RunPartitions step_id " << step_id << " execution_count "
<< execution_count; << execution_count;
// Maps the names of fed tensors to their index in `req`. // Maps the names of fed tensors to their index in `req`.
std::unordered_map<StringPiece, size_t, StringPieceHasher> feeds(3); std::unordered_map<absl::string_view, size_t, StringPieceHasher> feeds(3);
for (size_t i = 0; i < req.num_feeds(); ++i) { for (size_t i = 0; i < req.num_feeds(); ++i) {
if (!feeds.insert({req.feed_name(i), i}).second) { if (!feeds.insert({req.feed_name(i), i}).second) {
return errors::InvalidArgument("Duplicated feeds: ", req.feed_name(i)); return errors::InvalidArgument("Duplicated feeds: ", req.feed_name(i));
@ -753,7 +756,7 @@ Status MasterSession::ReffedClientGraph::RunPartitions(
VLOG(2) << "RunPartitions step_id " << step_id << " execution_count " VLOG(2) << "RunPartitions step_id " << step_id << " execution_count "
<< execution_count; << execution_count;
// Maps the names of fed tensors to their index in `req`. // Maps the names of fed tensors to their index in `req`.
std::unordered_map<StringPiece, size_t, StringPieceHasher> feeds(3); std::unordered_map<absl::string_view, size_t, StringPieceHasher> feeds(3);
for (size_t i = 0; i < callable_opts_.feed_size(); ++i) { for (size_t i = 0; i < callable_opts_.feed_size(); ++i) {
if (!feeds.insert({callable_opts_.feed(i), i}).second) { if (!feeds.insert({callable_opts_.feed(i), i}).second) {
// MakeCallable will fail if there are two feeds with the same name. // MakeCallable will fail if there are two feeds with the same name.

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/process_util.h" #include "tensorflow/core/common_runtime/process_util.h"
#include "tensorflow/core/distributed_runtime/worker_cache.h" #include "tensorflow/core/distributed_runtime/worker_cache.h"
@ -33,9 +34,9 @@ namespace tensorflow {
// parsing into one place. // parsing into one place.
// //
// Parses and returns the local device part (e.g., cpu:0, gpu:4). // Parses and returns the local device part (e.g., cpu:0, gpu:4).
string GetLocalDeviceName(StringPiece fullname) { string GetLocalDeviceName(absl::string_view fullname) {
auto pos = fullname.rfind('/'); auto pos = fullname.rfind('/');
CHECK_NE(pos, StringPiece::npos); CHECK_NE(pos, absl::string_view::npos);
fullname.remove_prefix(pos + 1); fullname.remove_prefix(pos + 1);
return string(fullname); return string(fullname);
} }

View File

@ -119,6 +119,7 @@ cc_library(
"//tensorflow/core:lib", "//tensorflow/core:lib",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"//tensorflow/core:worker_proto_cc", "//tensorflow/core:worker_proto_cc",
"@com_google_absl//absl/strings",
], ],
) )
@ -208,6 +209,7 @@ cc_library(
"//tensorflow/core:master_proto_cc", "//tensorflow/core:master_proto_cc",
"//tensorflow/core/distributed_runtime:call_options", "//tensorflow/core/distributed_runtime:call_options",
"//tensorflow/core/distributed_runtime:master_interface", "//tensorflow/core/distributed_runtime:master_interface",
"@com_google_absl//absl/strings",
], ],
alwayslink = 1, alwayslink = 1,
) )
@ -226,6 +228,7 @@ cc_library(
"//tensorflow/core:lib_internal", "//tensorflow/core:lib_internal",
"//tensorflow/core:master_proto_cc", "//tensorflow/core:master_proto_cc",
"//tensorflow/core/distributed_runtime:master", "//tensorflow/core/distributed_runtime:master",
"@com_google_absl//absl/strings",
], ],
alwayslink = 1, alwayslink = 1,
) )
@ -254,6 +257,7 @@ cc_library(
"//tensorflow/core/distributed_runtime:worker_cache", "//tensorflow/core/distributed_runtime:worker_cache",
"//tensorflow/core/distributed_runtime:worker_env", "//tensorflow/core/distributed_runtime:worker_env",
"//tensorflow/core/distributed_runtime:worker_interface", "//tensorflow/core/distributed_runtime:worker_interface",
"@com_google_absl//absl/strings",
], ],
) )
@ -316,6 +320,7 @@ tf_cc_binary(
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"//tensorflow/core/distributed_runtime:server_lib", "//tensorflow/core/distributed_runtime:server_lib",
"//tensorflow/core/kernels:data_flow", "//tensorflow/core/kernels:data_flow",
"@com_google_absl//absl/strings",
], ],
) )
@ -341,6 +346,7 @@ tf_cc_binary(
"//tensorflow/core/kernels:matmul_op", "//tensorflow/core/kernels:matmul_op",
"//tensorflow/core/kernels:reduction_ops", "//tensorflow/core/kernels:reduction_ops",
"//tensorflow/core/kernels:variable_ops", "//tensorflow/core/kernels:variable_ops",
"@com_google_absl//absl/strings",
], ],
) )
@ -479,6 +485,7 @@ tf_cuda_cc_test(
"//tensorflow/core/kernels:dense_update_ops", "//tensorflow/core/kernels:dense_update_ops",
"//tensorflow/core/kernels:matmul_op", "//tensorflow/core/kernels:matmul_op",
"//tensorflow/core/kernels:variable_ops", "//tensorflow/core/kernels:variable_ops",
"@com_google_absl//absl/strings",
], ],
) )

View File

@ -33,6 +33,7 @@ limitations under the License.
#include "grpcpp/alarm.h" #include "grpcpp/alarm.h"
#include "grpcpp/server_builder.h" #include "grpcpp/server_builder.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/distributed_runtime/master.h" #include "tensorflow/core/distributed_runtime/master.h"
#include "tensorflow/core/distributed_runtime/rpc/async_service_interface.h" #include "tensorflow/core/distributed_runtime/rpc/async_service_interface.h"
#include "tensorflow/core/distributed_runtime/rpc/grpc_call.h" #include "tensorflow/core/distributed_runtime/rpc/grpc_call.h"
@ -286,12 +287,12 @@ class GrpcMasterService : public AsyncServiceInterface {
// Start tracing, including the ID attached to the RPC. // Start tracing, including the ID attached to the RPC.
tracing::ScopedActivity* TraceRpc( tracing::ScopedActivity* TraceRpc(
StringPiece name, absl::string_view name,
const std::multimap<::grpc::string_ref, ::grpc::string_ref>& metadata) { const std::multimap<::grpc::string_ref, ::grpc::string_ref>& metadata) {
StringPiece id; absl::string_view id;
auto it = metadata.find(GrpcIdKey()); auto it = metadata.find(GrpcIdKey());
if (it != metadata.end()) { if (it != metadata.end()) {
id = StringPiece(it->second.data(), it->second.size()); id = absl::string_view(it->second.data(), it->second.size());
} }
return new tracing::ScopedActivity(name, id); return new tracing::ScopedActivity(name, id);
} }

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <utility> #include <utility>
#include "absl/strings/string_view.h"
#include "tensorflow/core/distributed_runtime/call_options.h" #include "tensorflow/core/distributed_runtime/call_options.h"
#include "tensorflow/core/distributed_runtime/master_interface.h" #include "tensorflow/core/distributed_runtime/master_interface.h"
#include "tensorflow/core/distributed_runtime/rpc/grpc_master_service_impl.h" #include "tensorflow/core/distributed_runtime/rpc/grpc_master_service_impl.h"
@ -119,7 +120,7 @@ class GrpcRemoteMaster : public MasterInterface {
private: private:
// Start tracing, attaching a unique ID to both the trace and the RPC. // Start tracing, attaching a unique ID to both the trace and the RPC.
tracing::ScopedActivity TraceRpc(StringPiece name, tracing::ScopedActivity TraceRpc(absl::string_view name,
::grpc::ClientContext* ctx) { ::grpc::ClientContext* ctx) {
string trace_id = strings::StrCat(tracing::GetUniqueArg()); string trace_id = strings::StrCat(tracing::GetUniqueArg());
ctx->AddMetadata(GrpcIdKey(), trace_id); ctx->AddMetadata(GrpcIdKey(), trace_id);

View File

@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/core/distributed_runtime/rpc/grpc_session.h" #include "tensorflow/core/distributed_runtime/rpc/grpc_session.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/distributed_runtime/rpc/grpc_testlib.h" #include "tensorflow/core/distributed_runtime/rpc/grpc_testlib.h"
#include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph.pb.h"
@ -667,7 +668,7 @@ TEST(GrpcSessionTest, LongErrorMessage) {
auto a = test::graph::Constant(&g, Tensor()); auto a = test::graph::Constant(&g, Tensor());
a->set_assigned_device_name(dev_a); a->set_assigned_device_name(dev_a);
std::vector<char> long_string_buffer(1024 * 1024, 'x'); std::vector<char> long_string_buffer(1024 * 1024, 'x');
StringPiece long_string(long_string_buffer.data(), 1024 * 1024); absl::string_view long_string(long_string_buffer.data(), 1024 * 1024);
string name = strings::StrCat(long_string, "fantasia!"); string name = strings::StrCat(long_string, "fantasia!");
auto a_err = test::graph::Error(&g, a, name); auto a_err = test::graph::Error(&g, a, name);
a_err->set_assigned_device_name(dev_a); a_err->set_assigned_device_name(dev_a);

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/core/distributed_runtime/rpc/grpc_tensor_coding.h" #include "tensorflow/core/distributed_runtime/rpc/grpc_tensor_coding.h"
#include "grpcpp/support/byte_buffer.h" #include "grpcpp/support/byte_buffer.h"
#include "grpcpp/support/slice.h" #include "grpcpp/support/slice.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/dma_helper.h" #include "tensorflow/core/common_runtime/dma_helper.h"
#include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor.pb.h" #include "tensorflow/core/framework/tensor.pb.h"
@ -158,7 +159,7 @@ void EncodeTensorToByteBuffer(bool is_dead, const Tensor& val,
io::ProtoEncodeHelper e_skeleton(skeleton.data(), skeleton.size()); io::ProtoEncodeHelper e_skeleton(skeleton.data(), skeleton.size());
EncodeSkeleton(val, &e_skeleton); EncodeSkeleton(val, &e_skeleton);
StringPiece tdata = val.tensor_data(); absl::string_view tdata = val.tensor_data();
uint32 overall_tensor_proto_bytesize = uint32 overall_tensor_proto_bytesize =
(e_skeleton.size() + (e_skeleton.size() +
VarLengthEncodingSize(TensorProto::kTensorContentFieldNumber, VarLengthEncodingSize(TensorProto::kTensorContentFieldNumber,
@ -197,7 +198,7 @@ void EncodeTensorToByteBuffer(bool is_dead, const Tensor& val,
e.WriteVarlengthBeginning(RecvTensorResponse::kTensorFieldNumber, e.WriteVarlengthBeginning(RecvTensorResponse::kTensorFieldNumber,
overall_tensor_proto_bytesize); overall_tensor_proto_bytesize);
// (C) // (C)
e.WriteRawBytes(StringPiece(e_skeleton.data(), e_skeleton.size())); e.WriteRawBytes(absl::string_view(e_skeleton.data(), e_skeleton.size()));
// (D1) & (D2) // (D1) & (D2)
e.WriteVarlengthBeginning(TensorProto::kTensorContentFieldNumber, e.WriteVarlengthBeginning(TensorProto::kTensorContentFieldNumber,
tdata.size()); tdata.size());

View File

@ -20,6 +20,7 @@ limitations under the License.
#include "grpcpp/security/credentials.h" #include "grpcpp/security/credentials.h"
#include "grpcpp/server_builder.h" #include "grpcpp/server_builder.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/distributed_runtime/server_lib.h" #include "tensorflow/core/distributed_runtime/server_lib.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
@ -56,7 +57,7 @@ Status FillServerDef(const string& cluster_spec, const string& job_name,
const string& job_name = job_pieces[0]; const string& job_name = job_pieces[0];
job_def->set_name(job_name); job_def->set_name(job_name);
// Does a bit more validation of the tasks_per_replica. // Does a bit more validation of the tasks_per_replica.
const StringPiece spec = job_pieces[1]; const absl::string_view spec = job_pieces[1];
// job_str is of form <job_name>|<host_ports>. // job_str is of form <job_name>|<host_ports>.
const std::vector<string> host_ports = str_util::Split(spec, ';'); const std::vector<string> host_ports = str_util::Split(spec, ';');
for (size_t i = 0; i < host_ports.size(); ++i) { for (size_t i = 0; i < host_ports.size(); ++i) {

View File

@ -19,6 +19,7 @@ limitations under the License.
#include "grpcpp/security/credentials.h" #include "grpcpp/security/credentials.h"
#include "grpcpp/server_builder.h" #include "grpcpp/server_builder.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/distributed_runtime/server_lib.h" #include "tensorflow/core/distributed_runtime/server_lib.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
@ -50,7 +51,7 @@ Status FillServerDef(const string& job_spec, const string& job_name,
CHECK_EQ(2, job_pieces.size()) << job_str; CHECK_EQ(2, job_pieces.size()) << job_str;
job_def->set_name(job_pieces[0]); job_def->set_name(job_pieces[0]);
// Does a bit more validation of the tasks_per_replica. // Does a bit more validation of the tasks_per_replica.
const StringPiece spec = job_pieces[1]; const absl::string_view spec = job_pieces[1];
// job_str is of form <job_name>|<host_ports>. // job_str is of form <job_name>|<host_ports>.
const std::vector<string> host_ports = str_util::Split(spec, ';'); const std::vector<string> host_ports = str_util::Split(spec, ';');
uint32 tasks_per_replica = host_ports.size(); uint32 tasks_per_replica = host_ports.size();

View File

@ -17,6 +17,7 @@ limitations under the License.
#include <unordered_set> #include <unordered_set>
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/common_runtime/device_mgr.h" #include "tensorflow/core/common_runtime/device_mgr.h"
#include "tensorflow/core/common_runtime/dma_helper.h" #include "tensorflow/core/common_runtime/dma_helper.h"
@ -58,7 +59,7 @@ class RpcRecvTensorCall : public BaseRecvTensorCall {
public: public:
RpcRecvTensorCall() : wi_(nullptr), dst_device_(nullptr) {} RpcRecvTensorCall() : wi_(nullptr), dst_device_(nullptr) {}
void Init(WorkerInterface* wi, int64 step_id, StringPiece key, void Init(WorkerInterface* wi, int64 step_id, absl::string_view key,
AllocatorAttributes alloc_attrs, Device* dst_device, AllocatorAttributes alloc_attrs, Device* dst_device,
const Rendezvous::Args& recv_args, Rendezvous::DoneCallback done) { const Rendezvous::Args& recv_args, Rendezvous::DoneCallback done) {
wi_ = wi; wi_ = wi;

View File

@ -17,6 +17,7 @@ limitations under the License.
#include "google/protobuf/any.pb.h" #include "google/protobuf/any.pb.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/common_runtime/device.h"
#include "tensorflow/core/framework/tensor.pb.h" #include "tensorflow/core/framework/tensor.pb.h"
#include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/framework/tensor_shape.pb.h"
@ -196,7 +197,7 @@ bool TensorResponse::ParseTensorSubmessage(
seen_tensor_content = true; seen_tensor_content = true;
TensorShape shape(tensor_meta->tensor_shape()); TensorShape shape(tensor_meta->tensor_shape());
Tensor t(allocator_, tensor_meta->dtype(), shape); Tensor t(allocator_, tensor_meta->dtype(), shape);
StringPiece buf = t.tensor_data(); absl::string_view buf = t.tensor_data();
if (static_cast<size_t>(num_bytes) != buf.size()) return false; if (static_cast<size_t>(num_bytes) != buf.size()) return false;
// TODO(jeff,sanjay): Figure out a way to avoid this copy if // TODO(jeff,sanjay): Figure out a way to avoid this copy if
// the underlying ZeroCopyInputStream data is properly aligned // the underlying ZeroCopyInputStream data is properly aligned

View File

@ -104,9 +104,9 @@ limitations under the License.
#include <type_traits> #include <type_traits>
#include "absl/base/macros.h" #include "absl/base/macros.h"
#include "absl/strings/string_view.h"
#include "tensorflow/core/example/example.pb.h" #include "tensorflow/core/example/example.pb.h"
#include "tensorflow/core/example/feature.pb.h" #include "tensorflow/core/example/feature.pb.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/platform/types.h" #include "tensorflow/core/platform/types.h"
@ -170,7 +170,7 @@ template <>
struct is_string<string> : std::true_type {}; struct is_string<string> : std::true_type {};
template <> template <>
struct is_string<::tensorflow::StringPiece> : std::true_type {}; struct is_string<::absl::string_view> : std::true_type {};
template <typename ValueType> template <typename ValueType>
struct FeatureTrait< struct FeatureTrait<

View File

@ -18,13 +18,13 @@ limitations under the License.
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/framework/attr_value.pb_text.h" #include "tensorflow/core/framework/attr_value.pb_text.h"
#include "tensorflow/core/framework/tensor.pb_text.h" #include "tensorflow/core/framework/tensor.pb_text.h"
#include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/framework/tensor_shape.pb.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/framework/types.pb_text.h" #include "tensorflow/core/framework/types.pb_text.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/hash/hash.h"
#include "tensorflow/core/lib/strings/proto_serialization.h" #include "tensorflow/core/lib/strings/proto_serialization.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"
@ -187,8 +187,8 @@ string SummarizeString(const string& str) {
// If the string is long, replace the middle with ellipses. // If the string is long, replace the middle with ellipses.
constexpr int kMaxStringSummarySize = 80; constexpr int kMaxStringSummarySize = 80;
if (escaped.size() >= kMaxStringSummarySize) { if (escaped.size() >= kMaxStringSummarySize) {
StringPiece prefix(escaped); absl::string_view prefix(escaped);
StringPiece suffix = prefix; absl::string_view suffix = prefix;
prefix.remove_suffix(escaped.size() - 10); prefix.remove_suffix(escaped.size() - 10);
suffix.remove_prefix(escaped.size() - 10); suffix.remove_prefix(escaped.size() - 10);
return strings::StrCat("\"", prefix, "...", suffix, "\""); return strings::StrCat("\"", prefix, "...", suffix, "\"");
@ -288,7 +288,7 @@ string SummarizeAttrValue(const AttrValue& attr_value) {
return "<Unknown AttrValue type>"; // Prevent missing return warning return "<Unknown AttrValue type>"; // Prevent missing return warning
} }
Status AttrValueHasType(const AttrValue& attr_value, StringPiece type) { Status AttrValueHasType(const AttrValue& attr_value, absl::string_view type) {
int num_set = 0; int num_set = 0;
#define VALIDATE_FIELD(name, type_string, oneof_case) \ #define VALIDATE_FIELD(name, type_string, oneof_case) \
@ -386,7 +386,8 @@ Status AttrValueHasType(const AttrValue& attr_value, StringPiece type) {
return Status::OK(); return Status::OK();
} }
bool ParseAttrValue(StringPiece type, StringPiece text, AttrValue* out) { bool ParseAttrValue(absl::string_view type, absl::string_view text,
AttrValue* out) {
// Parse type. // Parse type.
string field_name; string field_name;
bool is_list = str_util::ConsumePrefix(&type, "list("); bool is_list = str_util::ConsumePrefix(&type, "list(");
@ -420,7 +421,7 @@ bool ParseAttrValue(StringPiece type, StringPiece text, AttrValue* out) {
if (is_list) { if (is_list) {
// TextFormat parser considers "i: 7" to be the same as "i: [7]", // TextFormat parser considers "i: 7" to be the same as "i: [7]",
// but we only want to allow list values with []. // but we only want to allow list values with [].
StringPiece cleaned = text; absl::string_view cleaned = text;
str_util::RemoveLeadingWhitespace(&cleaned); str_util::RemoveLeadingWhitespace(&cleaned);
str_util::RemoveTrailingWhitespace(&cleaned); str_util::RemoveTrailingWhitespace(&cleaned);
if (cleaned.size() < 2 || cleaned[0] != '[' || if (cleaned.size() < 2 || cleaned[0] != '[' ||
@ -473,11 +474,12 @@ DEFINE_SET_ATTR_VALUE_LIST(const std::vector<bool>&, b)
DEFINE_SET_ATTR_VALUE_LIST(std::initializer_list<bool>, b) DEFINE_SET_ATTR_VALUE_LIST(std::initializer_list<bool>, b)
DEFINE_SET_ATTR_VALUE_BOTH(DataType, type) DEFINE_SET_ATTR_VALUE_BOTH(DataType, type)
void SetAttrValue(StringPiece value, AttrValue* out) { void SetAttrValue(absl::string_view value, AttrValue* out) {
out->set_s(value.data(), value.size()); out->set_s(value.data(), value.size());
} }
void SetAttrValue(const gtl::ArraySlice<StringPiece> value, AttrValue* out) { void SetAttrValue(const gtl::ArraySlice<absl::string_view> value,
AttrValue* out) {
out->mutable_list()->Clear(); // Create list() even if value empty. out->mutable_list()->Clear(); // Create list() even if value empty.
for (const auto& v : value) { for (const auto& v : value) {
out->mutable_list()->add_s(v.data(), v.size()); out->mutable_list()->add_s(v.data(), v.size());

View File

@ -20,12 +20,12 @@ limitations under the License.
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/string_view.h"
#include "tensorflow/core/framework/partial_tensor_shape.h" #include "tensorflow/core/framework/partial_tensor_shape.h"
#include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h" #include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/lib/gtl/array_slice.h"
namespace tensorflow { namespace tensorflow {
@ -39,7 +39,7 @@ class NameAttrList;
string SummarizeAttrValue(const AttrValue& attr_value); string SummarizeAttrValue(const AttrValue& attr_value);
// Generates an error if attr_value doesn't have the indicated attr type. // Generates an error if attr_value doesn't have the indicated attr type.
Status AttrValueHasType(const AttrValue& attr_value, StringPiece type); Status AttrValueHasType(const AttrValue& attr_value, absl::string_view type);
// Converts a text proto value from "text" into the field of *out // Converts a text proto value from "text" into the field of *out
// indicated by "type" (e.g. from the type field of an AttrDef). // indicated by "type" (e.g. from the type field of an AttrDef).
@ -48,12 +48,13 @@ Status AttrValueHasType(const AttrValue& attr_value, StringPiece type);
// * If type:"list(string)" and text:"['foo', 'bar']", // * If type:"list(string)" and text:"['foo', 'bar']",
// then *out is set to "list { s: ['foo', 'bar'] }" // then *out is set to "list { s: ['foo', 'bar'] }"
// Returns true on success. // Returns true on success.
bool ParseAttrValue(StringPiece type, StringPiece text, AttrValue* out); bool ParseAttrValue(absl::string_view type, absl::string_view text,
AttrValue* out);
// Sets *out based on the type of value. // Sets *out based on the type of value.
void SetAttrValue(const string& value, AttrValue* out); void SetAttrValue(const string& value, AttrValue* out);
void SetAttrValue(const char* value, AttrValue* out); void SetAttrValue(const char* value, AttrValue* out);
void SetAttrValue(StringPiece value, AttrValue* out); void SetAttrValue(absl::string_view value, AttrValue* out);
void SetAttrValue(int64 value, AttrValue* out); void SetAttrValue(int64 value, AttrValue* out);
void SetAttrValue(int32 value, AttrValue* out); void SetAttrValue(int32 value, AttrValue* out);
void SetAttrValue(float value, AttrValue* out); void SetAttrValue(float value, AttrValue* out);
@ -69,7 +70,7 @@ void SetAttrValue(const NameAttrList& value, AttrValue* out);
void SetAttrValue(gtl::ArraySlice<string> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<string> value, AttrValue* out);
void SetAttrValue(gtl::ArraySlice<const char*> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<const char*> value, AttrValue* out);
void SetAttrValue(gtl::ArraySlice<StringPiece> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<absl::string_view> value, AttrValue* out);
void SetAttrValue(gtl::ArraySlice<int64> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<int64> value, AttrValue* out);
void SetAttrValue(gtl::ArraySlice<int32> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<int32> value, AttrValue* out);
void SetAttrValue(gtl::ArraySlice<float> value, AttrValue* out); void SetAttrValue(gtl::ArraySlice<float> value, AttrValue* out);

Some files were not shown because too many files have changed in this diff Show More