Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions tsl/platform/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,10 @@ cc_library(
hdrs = ["numbers.h"],
deps = [
":stringpiece",
":stringprintf",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@xla//xla/tsl/platform:logging",
"@xla//xla/tsl/platform:macros",
"@xla//xla/tsl/platform:types",
],
)

Expand All @@ -177,13 +174,15 @@ cc_library(
hdrs = ["path.h"],
deps = [
":mutex",
":platform",
":scanner",
":str_util",
":strcat",
":stringpiece",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/types:span",
"@xla//xla/tsl/platform:logging",
"@xla//xla/tsl/platform:types",
],
alwayslink = True,
)
Expand Down Expand Up @@ -770,7 +769,6 @@ cc_library(
"@com_google_absl//absl/strings",
"@xla//xla/tsl/platform:logging",
"@xla//xla/tsl/platform:macros",
"@xla//xla/tsl/platform:types",
],
)

Expand All @@ -781,11 +779,8 @@ cc_library(
":numbers",
":stringpiece",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/meta:type_traits",
"@com_google_absl//absl/strings",
"@xla//xla/tsl/platform:logging",
"@xla//xla/tsl/platform:macros",
"@xla//xla/tsl/platform:types",
],
)

Expand Down Expand Up @@ -1017,7 +1012,6 @@ cc_library(
deps = [
":platform",
":stringpiece",
"@xla//xla/tsl/platform:types",
] + tf_fingerprint_deps(),
)

Expand Down
1 change: 1 addition & 0 deletions tsl/platform/cuda_root_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
#ifndef TENSORFLOW_TSL_PLATFORM_CUDA_ROOT_PATH_H_
#define TENSORFLOW_TSL_PLATFORM_CUDA_ROOT_PATH_H_

#include <cstdlib>
#include <string>
#include <vector>

Expand Down
1 change: 0 additions & 1 deletion tsl/platform/fingerprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ limitations under the License.
#include <climits>
#include <cstdint>

#include "xla/tsl/platform/types.h"
#include "tsl/platform/platform.h"
#include "tsl/platform/stringpiece.h"

Expand Down
3 changes: 1 addition & 2 deletions tsl/platform/numbers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ limitations under the License.
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "xla/tsl/platform/logging.h"
#include "xla/tsl/platform/types.h"

namespace tsl {

Expand Down Expand Up @@ -177,7 +176,7 @@ strings_internal::AlphaNumBuffer LegacyPrecision(float f) {
return result;
}

std::string FpToString(Fprint fp) {
std::string FpToString(uint64_t fp) {
return absl::StrCat(absl::Hex(fp, absl::kZeroPad16));
}

Expand Down
3 changes: 1 addition & 2 deletions tsl/platform/numbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ limitations under the License.
#include "absl/base/macros.h"
#include "absl/strings/numbers.h"
#include "absl/strings/string_view.h"
#include "xla/tsl/platform/types.h"
#include "tsl/platform/stringpiece.h"

namespace tsl {
Expand Down Expand Up @@ -76,7 +75,7 @@ strings_internal::AlphaNumBuffer LegacyPrecision(float f);
strings_internal::AlphaNumBuffer LegacyPrecision(double d);

// Convert a 64-bit fingerprint value to an ASCII representation.
std::string FpToString(Fprint fp);
std::string FpToString(uint64_t fp);

// Attempt to parse a `uint64_t` in the form encoded by
// `absl::StrCat(absl::Hex(*result))`. If successful, stores the value in
Expand Down
43 changes: 23 additions & 20 deletions tsl/platform/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ limitations under the License.
#include <unistd.h>
#endif

#include <initializer_list>
#include <string>
#include <vector>

#include "absl/algorithm/container.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "xla/tsl/platform/logging.h"
#include "xla/tsl/platform/types.h"
#include "tsl/platform/mutex.h"
#include "tsl/platform/scanner.h"
#include "tsl/platform/str_util.h"
Expand All @@ -48,14 +50,14 @@ namespace {
const char kPathSep[] = "/";
} // namespace

string JoinPathImpl(std::initializer_list<absl::string_view> paths) {
string result;
std::string JoinPathImpl(std::initializer_list<absl::string_view> paths) {
std::string result;

for (absl::string_view path : paths) {
if (path.empty()) continue;

if (result.empty()) {
result = string(path);
result = std::string(path);
continue;
}

Expand Down Expand Up @@ -138,18 +140,18 @@ absl::string_view BasenamePrefix(absl::string_view path) {
return internal::SplitBasename(path).first;
}

string CleanPath(absl::string_view unclean_path) {
string path(unclean_path);
std::string CleanPath(absl::string_view unclean_path) {
std::string path(unclean_path);
const char* src = path.c_str();
string::iterator dst = path.begin();
std::string::iterator dst = path.begin();

// Check for absolute path and determine initial backtrack limit.
const bool is_absolute_path = *src == '/';
if (is_absolute_path) {
*dst++ = *src++;
while (*src == '/') ++src;
}
string::const_iterator backtrack_limit = dst;
std::string::const_iterator backtrack_limit = dst;

// Process all parts
while (*src) {
Expand Down Expand Up @@ -205,7 +207,7 @@ string CleanPath(absl::string_view unclean_path) {
}

// Calculate and check the length of the cleaned path.
string::difference_type path_length = dst - path.begin();
std::string::difference_type path_length = dst - path.begin();
if (path_length != 0) {
// Remove trailing '/' except if it is root path ("/" ==> path_length := 1)
if (path_length > 1 && path[path_length - 1] == '/') {
Expand Down Expand Up @@ -251,10 +253,10 @@ void ParseURI(absl::string_view uri, absl::string_view* scheme,
*path = uri;
}

string CreateURI(absl::string_view scheme, absl::string_view host,
absl::string_view path) {
std::string CreateURI(absl::string_view scheme, absl::string_view host,
absl::string_view path) {
if (scheme.empty()) {
return string(path);
return std::string(path);
}
return absl::StrCat(scheme, "://", host, path);
}
Expand All @@ -267,10 +269,11 @@ int64_t UniqueId() {
return ++id;
}

string CommonPathPrefix(absl::Span<const string> paths) {
std::string CommonPathPrefix(absl::Span<const std::string> paths) {
if (paths.empty()) return "";
size_t min_filename_size =
absl::c_min_element(paths, [](const string& a, const string& b) {
absl::c_min_element(paths, [](const std::string& a,
const std::string& b) {
return a.size() < b.size();
})->size();
if (min_filename_size == 0) return "";
Expand All @@ -296,7 +299,7 @@ string CommonPathPrefix(absl::Span<const string> paths) {
: std::string(absl::string_view(paths[0]).substr(0, rpos + 1));
}

string GetTempFilename(const string& extension) {
std::string GetTempFilename(const std::string& extension) {
#if defined(__ANDROID__)
LOG(FATAL) << "GetTempFilename is not implemented in this platform.";
#elif defined(PLATFORM_WINDOWS)
Expand All @@ -313,7 +316,7 @@ string GetTempFilename(const string& extension) {
LOG(FATAL) << "Cannot get a temporary file in: " << temp_dir;
}

string full_tmp_file_name(temp_file_name);
std::string full_tmp_file_name(temp_file_name);
full_tmp_file_name.append(extension);
return full_tmp_file_name;
#else
Expand All @@ -327,7 +330,7 @@ string GetTempFilename(const string& extension) {
// UniqueId is added here because mkstemps is not as thread safe as it
// looks. https://github.com/tensorflow/tensorflow/issues/5804 shows
// the problem.
string tmp_filepath;
std::string tmp_filepath;
int fd;
if (extension.length()) {
tmp_filepath =
Expand Down Expand Up @@ -365,7 +368,7 @@ bool StartsWithSegment(absl::string_view path, absl::string_view segment) {
}
} // namespace

bool GetTestWorkspaceDir(string* dir) {
bool GetTestWorkspaceDir(std::string* dir) {
const char* srcdir = getenv("TEST_SRCDIR");
if (srcdir == nullptr) {
return false;
Expand All @@ -380,7 +383,7 @@ bool GetTestWorkspaceDir(string* dir) {
return true;
}

bool GetTestUndeclaredOutputsDir(string* dir) {
bool GetTestUndeclaredOutputsDir(std::string* dir) {
const char* outputs_dir = getenv("TEST_UNDECLARED_OUTPUTS_DIR");
if (outputs_dir == nullptr) {
return false;
Expand All @@ -391,7 +394,7 @@ bool GetTestUndeclaredOutputsDir(string* dir) {
return true;
}

bool ResolveTestPrefixes(absl::string_view path, string& resolved_path) {
bool ResolveTestPrefixes(absl::string_view path, std::string& resolved_path) {
constexpr absl::string_view kTestWorkspaceSegment = "TEST_WORKSPACE";
constexpr absl::string_view kOutputDirSegment = "TEST_UNDECLARED_OUTPUTS_DIR";

Expand Down
3 changes: 2 additions & 1 deletion tsl/platform/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ limitations under the License.

#include <string>

#include "xla/tsl/platform/types.h"
#include "absl/types/span.h"
#include "tsl/platform/platform.h"
#include "tsl/platform/stringpiece.h"

namespace tsl {
Expand Down
17 changes: 9 additions & 8 deletions tsl/platform/str_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,24 @@ bool ConsumeNonWhitespace(absl::string_view* s, absl::string_view* val) {
}
}

void TitlecaseString(string* s, absl::string_view delimiters) {
void TitlecaseString(std::string* s, absl::string_view delimiters) {
bool upper = true;
for (string::iterator ss = s->begin(); ss != s->end(); ++ss) {
for (std::string::iterator ss = s->begin(); ss != s->end(); ++ss) {
if (upper) {
*ss = absl::ascii_toupper(*ss);
}
upper = absl::StrContains(delimiters, *ss);
}
}

string StringReplace(absl::string_view s, absl::string_view oldsub,
absl::string_view newsub, bool replace_all) {
std::string StringReplace(absl::string_view s, absl::string_view oldsub,
absl::string_view newsub, bool replace_all) {
// TODO(jlebar): We could avoid having to shift data around in the string if
// we had a StringPiece::find() overload that searched for a StringPiece.
string res(s);
std::string res(s);
size_t pos = 0;
while ((pos = res.find(oldsub.data(), pos, oldsub.size())) != string::npos) {
while ((pos = res.find(oldsub.data(), pos, oldsub.size())) !=
std::string::npos) {
res.replace(pos, oldsub.size(), newsub.data(), newsub.size());
pos += newsub.size();
if (oldsub.empty()) {
Expand All @@ -112,7 +113,7 @@ string StringReplace(absl::string_view s, absl::string_view oldsub,
return res;
}

string ArgDefCase(absl::string_view s) {
std::string ArgDefCase(absl::string_view s) {
const size_t n = s.size();

// Compute the size of resulting string.
Expand All @@ -139,7 +140,7 @@ string ArgDefCase(absl::string_view s) {

// Initialize result with all '_'s. There is no string
// constructor that does not initialize memory.
string result(n + extra_us - to_skip, '_');
std::string result(n + extra_us - to_skip, '_');
// i - index into s
// j - index into result
for (size_t i = to_skip, j = 0; i < n; ++i, ++j) {
Expand Down
24 changes: 13 additions & 11 deletions tsl/platform/str_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ limitations under the License.
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "xla/tsl/platform/macros.h"
#include "xla/tsl/platform/types.h"
#include "tsl/platform/stringpiece.h"

// Basic string utility routines
Expand Down Expand Up @@ -152,26 +151,29 @@ struct SkipWhitespace {

// Split strings using any of the supplied delimiters. For example:
// Split("a,b.c,d", ".,") would return {"a", "b", "c", "d"}.
inline std::vector<string> Split(absl::string_view text,
absl::string_view delims) {
return text.empty() ? std::vector<string>()
inline std::vector<std::string> Split(absl::string_view text,
absl::string_view delims) {
return text.empty() ? std::vector<std::string>()
: absl::StrSplit(text, absl::ByAnyChar(delims));
}

template <typename Predicate>
std::vector<string> Split(absl::string_view text, absl::string_view delims,
Predicate p) {
return text.empty() ? std::vector<string>()
std::vector<std::string> Split(absl::string_view text, absl::string_view delims,
Predicate p) {
return text.empty() ? std::vector<std::string>()
: absl::StrSplit(text, absl::ByAnyChar(delims), p);
}

inline std::vector<string> Split(absl::string_view text, char delim) {
return text.empty() ? std::vector<string>() : absl::StrSplit(text, delim);
inline std::vector<std::string> Split(absl::string_view text, char delim) {
return text.empty() ? std::vector<std::string>()
: absl::StrSplit(text, delim);
}

template <typename Predicate>
std::vector<string> Split(absl::string_view text, char delim, Predicate p) {
return text.empty() ? std::vector<string>() : absl::StrSplit(text, delim, p);
std::vector<std::string> Split(absl::string_view text, char delim,
Predicate p) {
return text.empty() ? std::vector<std::string>()
: absl::StrSplit(text, delim, p);
}

// StartsWith()
Expand Down
1 change: 0 additions & 1 deletion tsl/platform/strcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ limitations under the License.
#include "absl/base/macros.h"
#include "absl/strings/str_cat.h"
#include "xla/tsl/platform/macros.h"
#include "xla/tsl/platform/types.h"
#include "tsl/platform/numbers.h"
#include "tsl/platform/stringpiece.h"

Expand Down
Loading