Qualify uses of std::string

PiperOrigin-RevId: 302086438
Change-Id: Idf09a24e44bda8f986f437f3dab4181042969796
This commit is contained in:
A. Unique TensorFlower 2020-03-20 13:14:36 -07:00 committed by TensorFlower Gardener
parent f023e26d90
commit 16b5232a80
24 changed files with 177 additions and 165 deletions

View File

@ -173,7 +173,8 @@ class Env {
/// \brief Returns true if the path matches the given pattern. The wildcards /// \brief Returns true if the path matches the given pattern. The wildcards
/// allowed in pattern are described in FileSystem::GetMatchingPaths. /// allowed in pattern are described in FileSystem::GetMatchingPaths.
virtual bool MatchPath(const string& path, const string& pattern) = 0; virtual bool MatchPath(const std::string& path,
const std::string& pattern) = 0;
/// \brief Given a pattern, stores in *results the set of paths that matches /// \brief Given a pattern, stores in *results the set of paths that matches
/// that pattern. *results is cleared. /// that pattern. *results is cleared.
@ -264,18 +265,18 @@ class Env {
/// \brief Returns the absolute path of the current executable. It resolves /// \brief Returns the absolute path of the current executable. It resolves
/// symlinks if there is any. /// symlinks if there is any.
string GetExecutablePath(); std::string GetExecutablePath();
/// Creates a local unique temporary file name. Returns true if success. /// Creates a local unique temporary file name. Returns true if success.
bool LocalTempFilename(string* filename); bool LocalTempFilename(std::string* filename);
/// Creates a local unique file name that starts with |prefix| and ends with /// Creates a local unique file name that starts with |prefix| and ends with
/// |suffix|. Returns true if success. /// |suffix|. Returns true if success.
bool CreateUniqueFileName(string* prefix, const string& suffix); bool CreateUniqueFileName(std::string* prefix, const std::string& suffix);
/// \brief Return the runfiles directory if running under bazel. Returns /// \brief Return the runfiles directory if running under bazel. Returns
/// the directory the executable is located in if not running under bazel. /// the directory the executable is located in if not running under bazel.
virtual string GetRunfilesDir() = 0; virtual std::string GetRunfilesDir() = 0;
// TODO(jeff,sanjay): Add back thread/thread-pool support if needed. // TODO(jeff,sanjay): Add back thread/thread-pool support if needed.
// TODO(jeff,sanjay): if needed, tighten spec so relative to epoch, or // TODO(jeff,sanjay): if needed, tighten spec so relative to epoch, or
@ -299,7 +300,7 @@ class Env {
/// Caller takes ownership of the result and must delete it eventually /// Caller takes ownership of the result and must delete it eventually
/// (the deletion will block until fn() stops running). /// (the deletion will block until fn() stops running).
virtual Thread* StartThread(const ThreadOptions& thread_options, virtual Thread* StartThread(const ThreadOptions& thread_options,
const string& name, const std::string& name,
std::function<void()> fn) TF_MUST_USE_RESULT = 0; std::function<void()> fn) TF_MUST_USE_RESULT = 0;
// Returns the thread id of calling thread. // Returns the thread id of calling thread.
@ -309,7 +310,7 @@ class Env {
virtual int32 GetCurrentThreadId() = 0; virtual int32 GetCurrentThreadId() = 0;
// Copies current thread name to "name". Returns true if success. // Copies current thread name to "name". Returns true if success.
virtual bool GetCurrentThreadName(string* name) = 0; virtual bool GetCurrentThreadName(std::string* name) = 0;
// \brief Schedules the given closure on a thread-pool. // \brief Schedules the given closure on a thread-pool.
// //
@ -349,8 +350,8 @@ class Env {
// "name" should be name of the library. // "name" should be name of the library.
// "version" should be the version of the library or NULL // "version" should be the version of the library or NULL
// returns the name that LoadLibrary() can use // returns the name that LoadLibrary() can use
virtual string FormatLibraryFileName(const string& name, virtual std::string FormatLibraryFileName(const std::string& name,
const string& version) = 0; const std::string& version) = 0;
// Returns a possible list of local temporary directories. // Returns a possible list of local temporary directories.
virtual void GetLocalTempDirectories(std::vector<string>* list) = 0; virtual void GetLocalTempDirectories(std::vector<string>* list) = 0;
@ -387,7 +388,7 @@ class EnvWrapper : public Env {
return target_->RegisterFileSystem(scheme, factory); return target_->RegisterFileSystem(scheme, factory);
} }
bool MatchPath(const string& path, const string& pattern) override { bool MatchPath(const std::string& path, const std::string& pattern) override {
return target_->MatchPath(path, pattern); return target_->MatchPath(path, pattern);
} }
@ -395,12 +396,13 @@ class EnvWrapper : public Env {
void SleepForMicroseconds(int64 micros) override { void SleepForMicroseconds(int64 micros) override {
target_->SleepForMicroseconds(micros); target_->SleepForMicroseconds(micros);
} }
Thread* StartThread(const ThreadOptions& thread_options, const string& name, Thread* StartThread(const ThreadOptions& thread_options,
const std::string& name,
std::function<void()> fn) override { std::function<void()> fn) override {
return target_->StartThread(thread_options, name, fn); return target_->StartThread(thread_options, name, fn);
} }
int32 GetCurrentThreadId() override { return target_->GetCurrentThreadId(); } int32 GetCurrentThreadId() override { return target_->GetCurrentThreadId(); }
bool GetCurrentThreadName(string* name) override { bool GetCurrentThreadName(std::string* name) override {
return target_->GetCurrentThreadName(name); return target_->GetCurrentThreadName(name);
} }
void SchedClosure(std::function<void()> closure) override { void SchedClosure(std::function<void()> closure) override {
@ -416,12 +418,12 @@ class EnvWrapper : public Env {
void** symbol) override { void** symbol) override {
return target_->GetSymbolFromLibrary(handle, symbol_name, symbol); return target_->GetSymbolFromLibrary(handle, symbol_name, symbol);
} }
string FormatLibraryFileName(const string& name, std::string FormatLibraryFileName(const std::string& name,
const string& version) override { const std::string& version) override {
return target_->FormatLibraryFileName(name, version); return target_->FormatLibraryFileName(name, version);
} }
string GetRunfilesDir() override { return target_->GetRunfilesDir(); } std::string GetRunfilesDir() override { return target_->GetRunfilesDir(); }
private: private:
void GetLocalTempDirectories(std::vector<string>* list) override { void GetLocalTempDirectories(std::vector<string>* list) override {
@ -520,7 +522,7 @@ namespace register_file_system {
template <typename Factory> template <typename Factory>
struct Register { struct Register {
Register(Env* env, const string& scheme) { Register(Env* env, const std::string& scheme) {
// TODO(b/32704451): Don't just ignore the ::tensorflow::Status object! // TODO(b/32704451): Don't just ignore the ::tensorflow::Status object!
env->RegisterFileSystem(scheme, []() -> FileSystem* { return new Factory; }) env->RegisterFileSystem(scheme, []() -> FileSystem* { return new Factory; })
.IgnoreError(); .IgnoreError();

View File

@ -45,7 +45,7 @@ namespace internal {
// able to completely remove PrepareForStrCat(). // able to completely remove PrepareForStrCat().
template <typename T> template <typename T>
typename std::enable_if<!std::is_constructible<strings::AlphaNum, T>::value, typename std::enable_if<!std::is_constructible<strings::AlphaNum, T>::value,
string>::type std::string>::type
PrepareForStrCat(const T& t) { PrepareForStrCat(const T& t) {
std::stringstream ss; std::stringstream ss;
ss << t; ss << t;
@ -126,29 +126,32 @@ DECLARE_ERROR(Unauthenticated, UNAUTHENTICATED)
// Note: The pattern below determines the regex _NODEDEF_NAME_RE in the file // Note: The pattern below determines the regex _NODEDEF_NAME_RE in the file
// tensorflow/python/client/session.py // tensorflow/python/client/session.py
// LINT.IfChange // LINT.IfChange
inline string FormatNodeNameForError(const string& name) { inline std::string FormatNodeNameForError(const std::string& name) {
return strings::StrCat("{{node ", name, "}}"); return strings::StrCat("{{node ", name, "}}");
} }
// LINT.ThenChange(//tensorflow/python/client/session.py) // LINT.ThenChange(//tensorflow/python/client/session.py)
template <typename T> template <typename T>
string FormatNodeNamesForError(const T& names) { std::string FormatNodeNamesForError(const T& names) {
return absl::StrJoin(names, ", ", [](string* output, const string& s) { return absl::StrJoin(
names, ", ", [](std::string* output, const std::string& s) {
::tensorflow::strings::StrAppend(output, FormatNodeNameForError(s)); ::tensorflow::strings::StrAppend(output, FormatNodeNameForError(s));
}); });
} }
// LINT.IfChange // LINT.IfChange
inline string FormatColocationNodeForError(const string& name) { inline std::string FormatColocationNodeForError(const std::string& name) {
return strings::StrCat("{{colocation_node ", name, "}}"); return strings::StrCat("{{colocation_node ", name, "}}");
} }
// LINT.ThenChange(//tensorflow/python/framework/error_interpolation.py) // LINT.ThenChange(//tensorflow/python/framework/error_interpolation.py)
template <typename T> template <typename T>
string FormatColocationNodeForError(const T& names) { std::string FormatColocationNodeForError(const T& names) {
return absl::StrJoin(names, ", ", [](string* output, const string& s) { return absl::StrJoin(names, ", ",
::tensorflow::strings::StrAppend(output, FormatColocationNodeForError(s)); [](std::string* output, const std::string& s) {
::tensorflow::strings::StrAppend(
output, FormatColocationNodeForError(s));
}); });
} }
inline string FormatFunctionForError(const string& name) { inline std::string FormatFunctionForError(const std::string& name) {
return strings::StrCat("{{function_node ", name, "}}"); return strings::StrCat("{{function_node ", name, "}}");
} }

View File

@ -151,7 +151,7 @@ class FileSystem {
/// This function provides the equivalent of posix fnmatch, however it is /// This function provides the equivalent of posix fnmatch, however it is
/// implemented without fnmatch to ensure that this can be used for cloud /// implemented without fnmatch to ensure that this can be used for cloud
/// filesystems on windows. For windows filesystems, it uses PathMatchSpec. /// filesystems on windows. For windows filesystems, it uses PathMatchSpec.
virtual bool Match(const string& filename, const string& pattern); virtual bool Match(const std::string& filename, const std::string& pattern);
/// \brief Obtains statistics for the given path. /// \brief Obtains statistics for the given path.
virtual tensorflow::Status Stat(const string& fname, virtual tensorflow::Status Stat(const string& fname,
@ -225,7 +225,7 @@ class FileSystem {
/// invoke any system calls (getcwd(2)) in order to resolve relative /// invoke any system calls (getcwd(2)) in order to resolve relative
/// paths with respect to the actual working directory. That is, this is /// paths with respect to the actual working directory. That is, this is
/// purely string manipulation, completely independent of process state. /// purely string manipulation, completely independent of process state.
virtual string TranslateName(const string& name) const; virtual std::string TranslateName(const std::string& name) const;
/// \brief Returns whether the given path is a directory or not. /// \brief Returns whether the given path is a directory or not.
/// ///
@ -288,16 +288,16 @@ class FileSystem {
/// invoke any system calls (getcwd(2)) in order to resolve relative /// invoke any system calls (getcwd(2)) in order to resolve relative
/// paths with respect to the actual working directory. That is, this is /// paths with respect to the actual working directory. That is, this is
/// purely string manipulation, completely independent of process state. /// purely string manipulation, completely independent of process state.
string CleanPath(StringPiece path) const; std::string CleanPath(StringPiece path) const;
/// \brief Creates a URI from a scheme, host, and path. /// \brief Creates a URI from a scheme, host, and path.
/// ///
/// If the scheme is empty, we just return the path. /// If the scheme is empty, we just return the path.
string CreateURI(StringPiece scheme, StringPiece host, std::string CreateURI(StringPiece scheme, StringPiece host,
StringPiece path) const; StringPiece path) const;
/// \brief Creates a temporary file name with an extension. /// \brief Creates a temporary file name with an extension.
string GetTempFilename(const string& extension) const; std::string GetTempFilename(const std::string& extension) const;
/// \brief Return true if path is absolute. /// \brief Return true if path is absolute.
bool IsAbsolutePath(tensorflow::StringPiece path) const; bool IsAbsolutePath(tensorflow::StringPiece path) const;
@ -319,12 +319,13 @@ class FileSystem {
/// string path = io::JoinPath(FLAGS_test_srcdir, filename); /// string path = io::JoinPath(FLAGS_test_srcdir, filename);
/// string path = io::JoinPath("/full", "path", "to", "filename"); /// string path = io::JoinPath("/full", "path", "to", "filename");
template <typename... T> template <typename... T>
string JoinPath(const T&... args) { std::string JoinPath(const T&... args) {
return JoinPathImpl({args...}); return JoinPathImpl({args...});
} }
#endif /* SWIG */ #endif /* SWIG */
string JoinPathImpl(std::initializer_list<tensorflow::StringPiece> paths); std::string JoinPathImpl(
std::initializer_list<tensorflow::StringPiece> paths);
/// \brief Populates the scheme, host, and path from a URI. /// \brief Populates the scheme, host, and path from a URI.
/// ///

View File

@ -33,7 +33,7 @@ namespace internal {
// Emit "message" as a log message to the log for the specified // Emit "message" as a log message to the log for the specified
// "severity" as if it came from a LOG call at "fname:line" // "severity" as if it came from a LOG call at "fname:line"
void LogString(const char* fname, int line, int severity, void LogString(const char* fname, int line, int severity,
const string& message); const std::string& message);
} // namespace internal } // namespace internal
} // namespace tensorflow } // namespace tensorflow

View File

@ -74,12 +74,12 @@ size_t DoubleToBuffer(double value, char* buffer);
size_t FloatToBuffer(float value, char* buffer); size_t FloatToBuffer(float value, char* buffer);
// Convert a 64-bit fingerprint value to an ASCII representation. // Convert a 64-bit fingerprint value to an ASCII representation.
string FpToString(Fprint fp); std::string FpToString(Fprint fp);
// Attempt to parse a fingerprint in the form encoded by FpToString. If // Attempt to parse a fingerprint in the form encoded by FpToString. If
// successful, stores the fingerprint in *fp and returns true. Otherwise, // successful, stores the fingerprint in *fp and returns true. Otherwise,
// returns false. // returns false.
bool StringToFp(const string& s, Fprint* fp); bool StringToFp(const std::string& s, Fprint* fp);
// Convert a 64-bit fingerprint value to an ASCII representation that // Convert a 64-bit fingerprint value to an ASCII representation that
// is terminated by a '\0'. // is terminated by a '\0'.
@ -157,12 +157,12 @@ bool SafeStringToNumeric(StringPiece s, T* value) {
// Converts from an int64 to a human readable string representing the // Converts from an int64 to a human readable string representing the
// same number, using decimal powers. e.g. 1200000 -> "1.20M". // same number, using decimal powers. e.g. 1200000 -> "1.20M".
string HumanReadableNum(int64 value); std::string HumanReadableNum(int64 value);
// Converts from an int64 representing a number of bytes to a // Converts from an int64 representing a number of bytes to a
// human readable string representing the same number. // human readable string representing the same number.
// e.g. 12345678 -> "11.77MiB". // e.g. 12345678 -> "11.77MiB".
string HumanReadableNumBytes(int64 num_bytes); std::string HumanReadableNumBytes(int64 num_bytes);
// Converts a time interval as double to a human readable // Converts a time interval as double to a human readable
// string. For example: // string. For example:
@ -171,7 +171,7 @@ string HumanReadableNumBytes(int64 num_bytes);
// 933120.0 -> "10.8 days" // 933120.0 -> "10.8 days"
// 39420000.0 -> "1.25 years" // 39420000.0 -> "1.25 years"
// -10 -> "-10 s" // -10 -> "-10 s"
string HumanReadableElapsedTime(double seconds); std::string HumanReadableElapsedTime(double seconds);
} // namespace strings } // namespace strings
} // namespace tensorflow } // namespace tensorflow

View File

@ -55,7 +55,7 @@ extern const char* kProtobufUint64Typename;
// this function has no size restrictions on the total size of the encoded // this function has no size restrictions on the total size of the encoded
// protocol buffer. // protocol buffer.
bool ParseProtoUnlimited(protobuf::MessageLite* proto, bool ParseProtoUnlimited(protobuf::MessageLite* proto,
const string& serialized); const std::string& serialized);
bool ParseProtoUnlimited(protobuf::MessageLite* proto, const void* serialized, bool ParseProtoUnlimited(protobuf::MessageLite* proto, const void* serialized,
size_t size); size_t size);
inline bool ParseProtoUnlimited(protobuf::MessageLite* proto, inline bool ParseProtoUnlimited(protobuf::MessageLite* proto,
@ -64,11 +64,13 @@ inline bool ParseProtoUnlimited(protobuf::MessageLite* proto,
} }
// Returns the string value for the value of a string or bytes protobuf field. // Returns the string value for the value of a string or bytes protobuf field.
inline const string& ProtobufStringToString(const string& s) { return s; } inline const std::string& ProtobufStringToString(const std::string& s) {
return s;
}
// Set <dest> to <src>. Swapping is allowed, as <src> does not need to be // Set <dest> to <src>. Swapping is allowed, as <src> does not need to be
// preserved. // preserved.
inline void SetProtobufStringSwapAllowed(string* src, string* dest) { inline void SetProtobufStringSwapAllowed(std::string* src, std::string* dest) {
*dest = std::move(*src); *dest = std::move(*src);
} }
@ -77,8 +79,10 @@ inline void SetProtobufStringSwapAllowed(string* src, string* dest) {
// tools/proto_text's generated code. They have the same name as the versions // tools/proto_text's generated code. They have the same name as the versions
// in core/platform/protobuf.h, so the generation code doesn't need to determine // in core/platform/protobuf.h, so the generation code doesn't need to determine
// if the type is Cord or string at generation time. // if the type is Cord or string at generation time.
inline string ProtobufStringToString(const Cord& s) { return s.ToString(); } inline std::string ProtobufStringToString(const Cord& s) {
inline void SetProtobufStringSwapAllowed(string* src, Cord* dest) { return s.ToString();
}
inline void SetProtobufStringSwapAllowed(std::string* src, Cord* dest) {
dest->CopyFrom(*src); dest->CopyFrom(*src);
} }
#endif // defined(TENSORFLOW_PROTOBUF_USES_CORD) #endif // defined(TENSORFLOW_PROTOBUF_USES_CORD)

View File

@ -62,7 +62,7 @@ class Status {
return ok() ? tensorflow::error::OK : state_->code; return ok() ? tensorflow::error::OK : state_->code;
} }
const string& error_message() const { const std::string& error_message() const {
return ok() ? empty_string() : state_->msg; return ok() ? empty_string() : state_->msg;
} }
@ -82,7 +82,7 @@ class Status {
/// \brief Return a string representation of this status suitable for /// \brief Return a string representation of this status suitable for
/// printing. Returns the string `"OK"` for success. /// printing. Returns the string `"OK"` for success.
string ToString() const; std::string ToString() const;
// Ignores any errors. This method does nothing except potentially suppress // Ignores any errors. This method does nothing except potentially suppress
// complaints from any tools that are checking that errors are not dropped on // complaints from any tools that are checking that errors are not dropped on
@ -90,10 +90,10 @@ class Status {
void IgnoreError() const; void IgnoreError() const;
private: private:
static const string& empty_string(); static const std::string& empty_string();
struct State { struct State {
tensorflow::error::Code code; tensorflow::error::Code code;
string msg; std::string msg;
}; };
// OK status has a `NULL` state_. Otherwise, `state_` points to // OK status has a `NULL` state_. Otherwise, `state_` points to
// a `State` structure containing the error code and message(s) // a `State` structure containing the error code and message(s)

View File

@ -31,7 +31,7 @@ namespace str_util {
// Returns a version of 'src' where unprintable characters have been // Returns a version of 'src' where unprintable characters have been
// escaped using C-style escape sequences. // escaped using C-style escape sequences.
string CEscape(StringPiece src); std::string CEscape(StringPiece src);
// Copies "source" to "dest", rewriting C-style escape sequences -- // Copies "source" to "dest", rewriting C-style escape sequences --
// '\n', '\r', '\\', '\ooo', etc -- to their ASCII equivalents. // '\n', '\r', '\\', '\ooo', etc -- to their ASCII equivalents.
@ -40,10 +40,10 @@ string CEscape(StringPiece src);
// 'error'. To disable error reporting, set 'error' to NULL. // 'error'. To disable error reporting, set 'error' to NULL.
// //
// NOTE: Does not support \u or \U! // NOTE: Does not support \u or \U!
bool CUnescape(StringPiece source, string* dest, string* error); bool CUnescape(StringPiece source, std::string* dest, std::string* error);
// Removes any trailing whitespace from "*s". // Removes any trailing whitespace from "*s".
void StripTrailingWhitespace(string* s); void StripTrailingWhitespace(std::string* s);
// Removes leading ascii_isspace() characters. // Removes leading ascii_isspace() characters.
// Returns number of characters removed. // Returns number of characters removed.
@ -87,23 +87,23 @@ TF_MUST_USE_RESULT StringPiece StripPrefix(StringPiece s, StringPiece expected);
TF_MUST_USE_RESULT StringPiece StripSuffix(StringPiece s, StringPiece expected); TF_MUST_USE_RESULT StringPiece StripSuffix(StringPiece s, StringPiece expected);
// Return lower-cased version of s. // Return lower-cased version of s.
string Lowercase(StringPiece s); std::string Lowercase(StringPiece s);
// Return upper-cased version of s. // Return upper-cased version of s.
string Uppercase(StringPiece s); std::string Uppercase(StringPiece s);
// Capitalize first character of each word in "*s". "delimiters" is a // Capitalize first character of each word in "*s". "delimiters" is a
// set of characters that can be used as word boundaries. // set of characters that can be used as word boundaries.
void TitlecaseString(string* s, StringPiece delimiters); void TitlecaseString(std::string* s, StringPiece delimiters);
// Replaces the first occurrence (if replace_all is false) or all occurrences // Replaces the first occurrence (if replace_all is false) or all occurrences
// (if replace_all is true) of oldsub in s with newsub. // (if replace_all is true) of oldsub in s with newsub.
string StringReplace(StringPiece s, StringPiece oldsub, StringPiece newsub, std::string StringReplace(StringPiece s, StringPiece oldsub, StringPiece newsub,
bool replace_all); bool replace_all);
// Join functionality // Join functionality
template <typename T> template <typename T>
string Join(const T& s, const char* sep) { std::string Join(const T& s, const char* sep) {
return absl::StrJoin(s, sep); return absl::StrJoin(s, sep);
} }
@ -111,7 +111,7 @@ string Join(const T& s, const char* sep) {
// is invoked (f is often constructed with a lambda of the form: // is invoked (f is often constructed with a lambda of the form:
// [](string* result, ElemType elem) // [](string* result, ElemType elem)
template <typename T, typename Formatter> template <typename T, typename Formatter>
string Join(const T& s, const char* sep, Formatter f) { std::string Join(const T& s, const char* sep, Formatter f) {
return absl::StrJoin(s, sep, f); return absl::StrJoin(s, sep, f);
} }
@ -179,7 +179,7 @@ size_t Strnlen(const char* str, const size_t string_max_len);
// This method is useful for producing strings matching "[a-z][a-z0-9_]*" // This method is useful for producing strings matching "[a-z][a-z0-9_]*"
// as required by OpDef.ArgDef.name. The resulting string is either empty or // as required by OpDef.ArgDef.name. The resulting string is either empty or
// matches this regex. // matches this regex.
string ArgDefCase(StringPiece s); std::string ArgDefCase(StringPiece s);
} // namespace str_util } // namespace str_util
} // namespace tensorflow } // namespace tensorflow

View File

@ -168,29 +168,29 @@ class AlphaNum {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// For performance reasons, we have specializations for <= 4 args. // For performance reasons, we have specializations for <= 4 args.
string StrCat(const AlphaNum &a) TF_MUST_USE_RESULT; std::string StrCat(const AlphaNum &a) TF_MUST_USE_RESULT;
string StrCat(const AlphaNum &a, const AlphaNum &b) TF_MUST_USE_RESULT; std::string StrCat(const AlphaNum &a, const AlphaNum &b) TF_MUST_USE_RESULT;
string StrCat(const AlphaNum &a, const AlphaNum &b, std::string StrCat(const AlphaNum &a, const AlphaNum &b,
const AlphaNum &c) TF_MUST_USE_RESULT; const AlphaNum &c) TF_MUST_USE_RESULT;
string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c,
const AlphaNum &d) TF_MUST_USE_RESULT; const AlphaNum &d) TF_MUST_USE_RESULT;
namespace internal { namespace internal {
// Do not call directly - this is not part of the public API. // Do not call directly - this is not part of the public API.
string CatPieces(std::initializer_list<StringPiece> pieces); std::string CatPieces(std::initializer_list<StringPiece> pieces);
void AppendPieces(string *dest, std::initializer_list<StringPiece> pieces); void AppendPieces(std::string *dest, std::initializer_list<StringPiece> pieces);
} // namespace internal } // namespace internal
// Support 5 or more arguments // Support 5 or more arguments
template <typename... AV> template <typename... AV>
string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c,
const AlphaNum &d, const AlphaNum &e, const AlphaNum &d, const AlphaNum &e,
const AV &... args) TF_MUST_USE_RESULT; const AV &... args) TF_MUST_USE_RESULT;
template <typename... AV> template <typename... AV>
string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c,
const AlphaNum &d, const AlphaNum &e, const AV &... args) { const AlphaNum &d, const AlphaNum &e, const AV &... args) {
return internal::CatPieces({a.Piece(), b.Piece(), c.Piece(), d.Piece(), return internal::CatPieces({a.Piece(), b.Piece(), c.Piece(), d.Piece(),
e.Piece(), e.Piece(),
@ -218,16 +218,16 @@ string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c,
// worked around as consecutive calls to StrAppend are quite efficient. // worked around as consecutive calls to StrAppend are quite efficient.
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
void StrAppend(string *dest, const AlphaNum &a); void StrAppend(std::string *dest, const AlphaNum &a);
void StrAppend(string *dest, const AlphaNum &a, const AlphaNum &b); void StrAppend(std::string *dest, const AlphaNum &a, const AlphaNum &b);
void StrAppend(string *dest, const AlphaNum &a, const AlphaNum &b, void StrAppend(std::string *dest, const AlphaNum &a, const AlphaNum &b,
const AlphaNum &c); const AlphaNum &c);
void StrAppend(string *dest, const AlphaNum &a, const AlphaNum &b, void StrAppend(std::string *dest, const AlphaNum &a, const AlphaNum &b,
const AlphaNum &c, const AlphaNum &d); const AlphaNum &c, const AlphaNum &d);
// Support 5 or more arguments // Support 5 or more arguments
template <typename... AV> template <typename... AV>
inline void StrAppend(string *dest, const AlphaNum &a, const AlphaNum &b, inline void StrAppend(std::string *dest, const AlphaNum &a, const AlphaNum &b,
const AlphaNum &c, const AlphaNum &d, const AlphaNum &e, const AlphaNum &c, const AlphaNum &d, const AlphaNum &e,
const AV &... args) { const AV &... args) {
internal::AppendPieces(dest, internal::AppendPieces(dest,

View File

@ -31,31 +31,31 @@ namespace port {
// Store src contents in *out. If backing memory for src is shared with *out, // Store src contents in *out. If backing memory for src is shared with *out,
// will ref obj during the call and will arrange to unref obj when no // will ref obj during the call and will arrange to unref obj when no
// longer needed. // longer needed.
void AssignRefCounted(StringPiece src, core::RefCounted* obj, string* out); void AssignRefCounted(StringPiece src, core::RefCounted* obj, std::string* out);
// Copy contents of src to dst[0,src.size()-1]. // Copy contents of src to dst[0,src.size()-1].
inline void CopyToArray(const string& src, char* dst) { inline void CopyToArray(const std::string& src, char* dst) {
memcpy(dst, src.data(), src.size()); memcpy(dst, src.data(), src.size());
} }
// Copy subrange [pos:(pos + n)) from src to dst. If pos >= src.size() the // Copy subrange [pos:(pos + n)) from src to dst. If pos >= src.size() the
// result is empty. If pos + n > src.size() the subrange [pos, size()) is // result is empty. If pos + n > src.size() the subrange [pos, size()) is
// copied. // copied.
inline void CopySubrangeToArray(const string& src, size_t pos, size_t n, inline void CopySubrangeToArray(const std::string& src, size_t pos, size_t n,
char* dst) { char* dst) {
if (pos >= src.size()) return; if (pos >= src.size()) return;
memcpy(dst, src.data() + pos, std::min(n, src.size() - pos)); memcpy(dst, src.data() + pos, std::min(n, src.size() - pos));
} }
// Store encoding of strings[0..n-1] in *out. // Store encoding of strings[0..n-1] in *out.
void EncodeStringList(const tstring* strings, int64 n, string* out); void EncodeStringList(const tstring* strings, int64 n, std::string* out);
// Decode n strings from src and store in strings[0..n-1]. // Decode n strings from src and store in strings[0..n-1].
// Returns true if successful, false on parse error. // Returns true if successful, false on parse error.
bool DecodeStringList(const string& src, tstring* strings, int64 n); bool DecodeStringList(const std::string& src, tstring* strings, int64 n);
// Assigns base[0..bytes-1] to *s // Assigns base[0..bytes-1] to *s
void CopyFromArray(string* s, const char* base, size_t bytes); void CopyFromArray(std::string* s, const char* base, size_t bytes);
// Encodes sequences of strings and serialized protocol buffers into a string. // Encodes sequences of strings and serialized protocol buffers into a string.
// Normal usage consists of zero or more calls to Append() and a single call to // Normal usage consists of zero or more calls to Append() and a single call to
@ -68,7 +68,7 @@ class StringListEncoder {
virtual void Append(const protobuf::MessageLite& m) = 0; virtual void Append(const protobuf::MessageLite& m) = 0;
// Encodes the given string. This may not be called after Finalize(). // Encodes the given string. This may not be called after Finalize().
virtual void Append(const string& s) = 0; virtual void Append(const std::string& s) = 0;
// Signals end of the encoding process. No other calls are allowed after this. // Signals end of the encoding process. No other calls are allowed after this.
virtual void Finalize() = 0; virtual void Finalize() = 0;
@ -117,7 +117,7 @@ void EncodeStringList(const tstring* strings, int64 n, Cord* out);
// Decode n strings from src and store in strings[0..n-1]. // Decode n strings from src and store in strings[0..n-1].
// Returns true if successful, false on parse error. // Returns true if successful, false on parse error.
bool DecodeStringList(const Cord& src, string* strings, int64 n); bool DecodeStringList(const Cord& src, std::string* strings, int64 n);
bool DecodeStringList(const Cord& src, tstring* strings, int64 n); bool DecodeStringList(const Cord& src, tstring* strings, int64 n);
// Assigns base[0..bytes-1] to *c // Assigns base[0..bytes-1] to *c

View File

@ -74,7 +74,7 @@ namespace gpu {
PLUGIN_REGISTRY_DEFINE_PLUGIN_ID(kCuBlasPlugin); PLUGIN_REGISTRY_DEFINE_PLUGIN_ID(kCuBlasPlugin);
static string ToString(cublasStatus_t status) { static std::string ToString(cublasStatus_t status) {
switch (status) { switch (status) {
case CUBLAS_STATUS_SUCCESS: case CUBLAS_STATUS_SUCCESS:
return "CUBLAS_STATUS_SUCCESS"; return "CUBLAS_STATUS_SUCCESS";
@ -2803,7 +2803,7 @@ bool CUDABlas::DoBlasTrsm(Stream *stream, blas::Side side,
GpuComplex(GpuMemoryMutable(b)), ldb); GpuComplex(GpuMemoryMutable(b)), ldb);
} }
port::Status CUDABlas::GetVersion(string *version) { port::Status CUDABlas::GetVersion(std::string *version) {
absl::MutexLock lock(&mu_); absl::MutexLock lock(&mu_);
int v; int v;

View File

@ -53,12 +53,12 @@ limitations under the License.
namespace stream_executor { namespace stream_executor {
namespace cuda { namespace cuda {
string DriverVersionToString(DriverVersion version) { std::string DriverVersionToString(DriverVersion version) {
return absl::StrFormat("%d.%d.%d", std::get<0>(version), std::get<1>(version), return absl::StrFormat("%d.%d.%d", std::get<0>(version), std::get<1>(version),
std::get<2>(version)); std::get<2>(version));
} }
string DriverVersionStatusToString(port::StatusOr<DriverVersion> version) { std::string DriverVersionStatusToString(port::StatusOr<DriverVersion> version) {
if (!version.ok()) { if (!version.ok()) {
return version.status().ToString(); return version.status().ToString();
} }
@ -66,8 +66,8 @@ string DriverVersionStatusToString(port::StatusOr<DriverVersion> version) {
return DriverVersionToString(version.ValueOrDie()); return DriverVersionToString(version.ValueOrDie());
} }
port::StatusOr<DriverVersion> StringToDriverVersion(const string &value) { port::StatusOr<DriverVersion> StringToDriverVersion(const std::string &value) {
std::vector<string> pieces = absl::StrSplit(value, '.'); std::vector<std::string> pieces = absl::StrSplit(value, '.');
if (pieces.size() < 2 || pieces.size() > 4) { if (pieces.size() < 2 || pieces.size() > 4) {
return port::Status( return port::Status(
port::error::INVALID_ARGUMENT, port::error::INVALID_ARGUMENT,
@ -122,7 +122,7 @@ static const char *kDriverVersionPath = "/proc/driver/nvidia/version";
// -- class Diagnostician // -- class Diagnostician
string Diagnostician::GetDevNodePath(int dev_node_ordinal) { std::string Diagnostician::GetDevNodePath(int dev_node_ordinal) {
return absl::StrCat("/dev/nvidia", dev_node_ordinal); return absl::StrCat("/dev/nvidia", dev_node_ordinal);
} }
@ -177,10 +177,10 @@ void Diagnostician::LogDiagnosticInformation() {
#ifndef PLATFORM_WINDOWS #ifndef PLATFORM_WINDOWS
if (VLOG_IS_ON(1)) { if (VLOG_IS_ON(1)) {
const char *value = getenv("LD_LIBRARY_PATH"); const char *value = getenv("LD_LIBRARY_PATH");
string library_path = value == nullptr ? "" : value; std::string library_path = value == nullptr ? "" : value;
VLOG(1) << "LD_LIBRARY_PATH is: \"" << library_path << "\""; VLOG(1) << "LD_LIBRARY_PATH is: \"" << library_path << "\"";
std::vector<string> pieces = absl::StrSplit(library_path, ':'); std::vector<std::string> pieces = absl::StrSplit(library_path, ':');
for (const auto &piece : pieces) { for (const auto &piece : pieces) {
if (piece.empty()) { if (piece.empty()) {
continue; continue;
@ -264,11 +264,11 @@ port::StatusOr<DriverVersion> Diagnostician::FindDsoVersion() {
if (dot == nullptr) { if (dot == nullptr) {
return 0; return 0;
} }
string dso_version = dot + strlen(so_suffix); std::string dso_version = dot + strlen(so_suffix);
// TODO(b/22689637): Eliminate the explicit namespace if possible. // TODO(b/22689637): Eliminate the explicit namespace if possible.
auto stripped_dso_version = absl::StripSuffix(dso_version, ".ld64"); auto stripped_dso_version = absl::StripSuffix(dso_version, ".ld64");
auto result = static_cast<port::StatusOr<DriverVersion> *>(data); auto result = static_cast<port::StatusOr<DriverVersion> *>(data);
*result = cuda::StringToDriverVersion(string(stripped_dso_version)); *result = cuda::StringToDriverVersion(std::string(stripped_dso_version));
return 1; return 1;
} }
return 0; return 0;
@ -282,10 +282,10 @@ port::StatusOr<DriverVersion> Diagnostician::FindDsoVersion() {
} }
port::StatusOr<DriverVersion> Diagnostician::FindKernelModuleVersion( port::StatusOr<DriverVersion> Diagnostician::FindKernelModuleVersion(
const string &driver_version_file_contents) { const std::string &driver_version_file_contents) {
static const char *kDriverFilePrelude = "Kernel Module "; static const char *kDriverFilePrelude = "Kernel Module ";
size_t offset = driver_version_file_contents.find(kDriverFilePrelude); size_t offset = driver_version_file_contents.find(kDriverFilePrelude);
if (offset == string::npos) { if (offset == std::string::npos) {
return port::Status( return port::Status(
port::error::NOT_FOUND, port::error::NOT_FOUND,
absl::StrCat("could not find kernel module information in " absl::StrCat("could not find kernel module information in "
@ -293,13 +293,13 @@ port::StatusOr<DriverVersion> Diagnostician::FindKernelModuleVersion(
driver_version_file_contents, "\"")); driver_version_file_contents, "\""));
} }
string version_and_rest = driver_version_file_contents.substr( std::string version_and_rest = driver_version_file_contents.substr(
offset + strlen(kDriverFilePrelude), string::npos); offset + strlen(kDriverFilePrelude), std::string::npos);
size_t space_index = version_and_rest.find(" "); size_t space_index = version_and_rest.find(" ");
auto kernel_version = version_and_rest.substr(0, space_index); auto kernel_version = version_and_rest.substr(0, space_index);
// TODO(b/22689637): Eliminate the explicit namespace if possible. // TODO(b/22689637): Eliminate the explicit namespace if possible.
auto stripped_kernel_version = absl::StripSuffix(kernel_version, ".ld64"); auto stripped_kernel_version = absl::StripSuffix(kernel_version, ".ld64");
return cuda::StringToDriverVersion(string(stripped_kernel_version)); return cuda::StringToDriverVersion(std::string(stripped_kernel_version));
} }
void Diagnostician::WarnOnDsoKernelMismatch( void Diagnostician::WarnOnDsoKernelMismatch(

View File

@ -25,13 +25,13 @@ namespace cuda {
using DriverVersion = gpu::DriverVersion; using DriverVersion = gpu::DriverVersion;
// Converts a parsed driver version to string form. // Converts a parsed driver version to string form.
string DriverVersionToString(DriverVersion version); std::string DriverVersionToString(DriverVersion version);
// Converts a parsed driver version or status value to natural string form. // Converts a parsed driver version or status value to natural string form.
string DriverVersionStatusToString(port::StatusOr<DriverVersion> version); std::string DriverVersionStatusToString(port::StatusOr<DriverVersion> version);
// Converts a string of a form like "331.79" to a DriverVersion{331, 79}. // Converts a string of a form like "331.79" to a DriverVersion{331, 79}.
port::StatusOr<DriverVersion> StringToDriverVersion(const string& value); port::StatusOr<DriverVersion> StringToDriverVersion(const std::string& value);
using Diagnostician = gpu::Diagnostician; using Diagnostician = gpu::Diagnostician;

View File

@ -88,7 +88,7 @@ NarrowT CheckedNarrowing(const WideT& wide) {
return narrow; return narrow;
} }
string ToString(cudnnStatus_t status) { std::string ToString(cudnnStatus_t status) {
switch (status) { switch (status) {
case CUDNN_STATUS_SUCCESS: case CUDNN_STATUS_SUCCESS:
return "CUDNN_STATUS_SUCCESS"; return "CUDNN_STATUS_SUCCESS";
@ -307,7 +307,7 @@ port::Status CudnnSupport::Init() {
CudnnVersion loaded_version; CudnnVersion loaded_version;
TF_RETURN_IF_ERROR(GetLoadedCudnnVersion(&loaded_version)); TF_RETURN_IF_ERROR(GetLoadedCudnnVersion(&loaded_version));
if (!IsSourceCompatibleWithCudnnLibrary(source_version, loaded_version)) { if (!IsSourceCompatibleWithCudnnLibrary(source_version, loaded_version)) {
const string error = absl::StrCat( const std::string error = absl::StrCat(
"Loaded runtime CuDNN library: ", loaded_version.ToString(), "Loaded runtime CuDNN library: ", loaded_version.ToString(),
" but source was compiled with: ", source_version.ToString(), " but source was compiled with: ", source_version.ToString(),
". CuDNN library major and minor version needs to match or have " ". CuDNN library major and minor version needs to match or have "

View File

@ -127,7 +127,7 @@ class CreatedContexts {
/* static */ int64 CreatedContexts::next_id_ = 1; // 0 means "no context" /* static */ int64 CreatedContexts::next_id_ = 1; // 0 means "no context"
// Formats CUresult to output prettified values into a log stream. // Formats CUresult to output prettified values into a log stream.
string ToString(CUresult result) { std::string ToString(CUresult result) {
const char* error_name; const char* error_name;
if (cuGetErrorName(result, &error_name)) { if (cuGetErrorName(result, &error_name)) {
return absl::StrCat("UNKNOWN ERROR (", static_cast<int>(result), ")"); return absl::StrCat("UNKNOWN ERROR (", static_cast<int>(result), ")");
@ -167,7 +167,7 @@ port::ThreadPool* GetDriverExecutor() {
} // namespace } // namespace
string MemorySpaceString(MemorySpace memory_space) { std::string MemorySpaceString(MemorySpace memory_space) {
switch (memory_space) { switch (memory_space) {
case MemorySpace::kHost: case MemorySpace::kHost:
return "host"; return "host";
@ -252,7 +252,7 @@ namespace {
// Returns a stringified device number associated with pointer, primarily for // Returns a stringified device number associated with pointer, primarily for
// logging purposes. Returns "?" if the device could not be successfully // logging purposes. Returns "?" if the device could not be successfully
// queried. // queried.
string CUDAPointerToDeviceString(CUdeviceptr pointer) { std::string CUDAPointerToDeviceString(CUdeviceptr pointer) {
auto value = GpuDriver::GetPointerDevice(pointer); auto value = GpuDriver::GetPointerDevice(pointer);
if (value.ok()) { if (value.ok()) {
return absl::StrCat(value.ValueOrDie()); return absl::StrCat(value.ValueOrDie());
@ -264,7 +264,7 @@ string CUDAPointerToDeviceString(CUdeviceptr pointer) {
// Returns a stringified memory space associated with pointer, primarily for // Returns a stringified memory space associated with pointer, primarily for
// logging purposes. Returns "?" if the memory space could not be successfully // logging purposes. Returns "?" if the memory space could not be successfully
// queried. // queried.
string CUDAPointerToMemorySpaceString(CUdeviceptr pointer) { std::string CUDAPointerToMemorySpaceString(CUdeviceptr pointer) {
auto value = GpuDriver::GetPointerMemorySpace(pointer); auto value = GpuDriver::GetPointerMemorySpace(pointer);
if (value.ok()) { if (value.ok()) {
return MemorySpaceString(value.ValueOrDie()); return MemorySpaceString(value.ValueOrDie());
@ -277,7 +277,7 @@ string CUDAPointerToMemorySpaceString(CUdeviceptr pointer) {
// permitted between the "from" and "to" pointers' associated contexts, // permitted between the "from" and "to" pointers' associated contexts,
// primarily for logging purposes. Returns "error" if an error is encountered // primarily for logging purposes. Returns "error" if an error is encountered
// in the process of querying. // in the process of querying.
string CUDAPointersToCanAccessString(CUdeviceptr from, CUdeviceptr to) { std::string CUDAPointersToCanAccessString(CUdeviceptr from, CUdeviceptr to) {
auto from_context = GpuDriver::GetPointerContext(from); auto from_context = GpuDriver::GetPointerContext(from);
if (!from_context.ok()) { if (!from_context.ok()) {
LOG(ERROR) << "could not retrieve source pointer's context: " LOG(ERROR) << "could not retrieve source pointer's context: "
@ -335,7 +335,7 @@ static port::Status InternalInit() {
} }
/* static */ port::Status GpuDriver::GetDeviceName(CUdevice device, /* static */ port::Status GpuDriver::GetDeviceName(CUdevice device,
string* device_name) { std::string* device_name) {
static const size_t kCharLimit = 64; static const size_t kCharLimit = 64;
absl::InlinedVector<char, 4> chars(kCharLimit); absl::InlinedVector<char, 4> chars(kCharLimit);
RETURN_IF_CUDA_RES_ERROR( RETURN_IF_CUDA_RES_ERROR(
@ -434,7 +434,8 @@ bool DeviceOptionsToContextFlags(const DeviceOptions& device_options,
return port::Status::OK(); return port::Status::OK();
} }
string message = "failed call to cuDevicePrimaryCtxRetain: " + ToString(res); std::string message =
"failed call to cuDevicePrimaryCtxRetain: " + ToString(res);
if (res == CUDA_ERROR_OUT_OF_MEMORY) { if (res == CUDA_ERROR_OUT_OF_MEMORY) {
uint64 total_memory; uint64 total_memory;
if (GetDeviceTotalMemory(device, &total_memory)) { if (GetDeviceTotalMemory(device, &total_memory)) {
@ -1391,8 +1392,8 @@ static port::StatusOr<T> GetSimpleAttribute(CUdevice device,
return true; return true;
} }
/* static */ string GpuDriver::GetPCIBusID(CUdevice device) { /* static */ std::string GpuDriver::GetPCIBusID(CUdevice device) {
string pci_bus_id; std::string pci_bus_id;
static const int kBufferSize = 64; static const int kBufferSize = 64;
absl::InlinedVector<char, 4> chars(kBufferSize); absl::InlinedVector<char, 4> chars(kBufferSize);
chars[kBufferSize - 1] = '\0'; chars[kBufferSize - 1] = '\0';

View File

@ -81,7 +81,7 @@ namespace gpu {
// //
// As this is an implementation-detail workaround, the usage is to declare this // As this is an implementation-detail workaround, the usage is to declare this
// variable with extern linkage and populate it from another translation unit. // variable with extern linkage and populate it from another translation unit.
std::function<string(const string &)> g_cubinate; std::function<std::string(const std::string&)> g_cubinate;
static GpuEvent* AsGpuEvent(Event* event) { static GpuEvent* AsGpuEvent(Event* event) {
DCHECK(event != nullptr); DCHECK(event != nullptr);
@ -152,12 +152,12 @@ port::Status GpuExecutor::Init(int device_ordinal,
bool GpuExecutor::FindOnDiskForComputeCapability( bool GpuExecutor::FindOnDiskForComputeCapability(
absl::string_view filename, absl::string_view canonical_suffix, absl::string_view filename, absl::string_view canonical_suffix,
string* found_filename) const { std::string* found_filename) const {
if (cc_major_ == 0 && cc_minor_ == 0) { if (cc_major_ == 0 && cc_minor_ == 0) {
return false; return false;
} }
string cc_specific = std::string cc_specific =
absl::StrCat(filename, ".cc", cc_major_, cc_minor_, canonical_suffix); absl::StrCat(filename, ".cc", cc_major_, cc_minor_, canonical_suffix);
if (port::FileExists(cc_specific).ok()) { if (port::FileExists(cc_specific).ok()) {
VLOG(2) << "found compute-capability-specific file, using that: " VLOG(2) << "found compute-capability-specific file, using that: "
@ -168,8 +168,8 @@ bool GpuExecutor::FindOnDiskForComputeCapability(
VLOG(2) << "could not find compute-capability specific file at: " VLOG(2) << "could not find compute-capability specific file at: "
<< cc_specific; << cc_specific;
if (port::FileExists(string(filename)).ok()) { if (port::FileExists(std::string(filename)).ok()) {
*found_filename = string(filename); *found_filename = std::string(filename);
return true; return true;
} }
@ -178,7 +178,7 @@ bool GpuExecutor::FindOnDiskForComputeCapability(
bool GpuExecutor::FindOnDiskForISAVersion(absl::string_view filename, bool GpuExecutor::FindOnDiskForISAVersion(absl::string_view filename,
absl::string_view canonical_suffix, absl::string_view canonical_suffix,
string* found_filename) const { std::string* found_filename) const {
LOG(ERROR) LOG(ERROR)
<< "Feature not supported on CUDA platform (FindOnDiskForISAVersion)"; << "Feature not supported on CUDA platform (FindOnDiskForISAVersion)";
return false; return false;
@ -188,7 +188,7 @@ bool GpuExecutor::FindOnDiskForISAVersion(absl::string_view filename,
// Arg: strip_exe: if true, remove the name of the executable itself from the // Arg: strip_exe: if true, remove the name of the executable itself from the
// returned string. Example: calling this from /usr/bin/foo // returned string. Example: calling this from /usr/bin/foo
// would return /usr/bin. // would return /usr/bin.
static string GetBinaryDir(bool strip_exe) { static std::string GetBinaryDir(bool strip_exe) {
char exe_path[PATH_MAX] = {0}; char exe_path[PATH_MAX] = {0};
#if defined(__APPLE__) #if defined(__APPLE__)
uint32_t buffer_size = 0U; uint32_t buffer_size = 0U;
@ -209,8 +209,8 @@ static string GetBinaryDir(bool strip_exe) {
if (strip_exe) { if (strip_exe) {
// The exe is the last component of the path, so remove one component. // The exe is the last component of the path, so remove one component.
string ret = exe_path; std::string ret = exe_path;
std::vector<string> components = absl::StrSplit(exe_path, '/'); std::vector<std::string> components = absl::StrSplit(exe_path, '/');
components.pop_back(); components.pop_back();
return absl::StrJoin(components, "/"); return absl::StrJoin(components, "/");
} }
@ -264,7 +264,7 @@ port::Status GpuExecutor::GetKernel(const MultiKernelLoaderSpec& spec,
KernelBase* kernel) { KernelBase* kernel) {
GpuKernel* cuda_kernel = AsGpuKernel(kernel); GpuKernel* cuda_kernel = AsGpuKernel(kernel);
CUmodule module; CUmodule module;
const string *kernelname; const std::string* kernelname;
VLOG(3) << "GetKernel on kernel " << kernel << " : " << kernel->name(); VLOG(3) << "GetKernel on kernel " << kernel << " : " << kernel->name();
@ -857,7 +857,7 @@ bool GpuExecutor::DeviceMemoryUsage(int64* free, int64* total) const {
return GpuDriver::GetDeviceMemoryInfo(context_, free, total); return GpuDriver::GetDeviceMemoryInfo(context_, free, total);
} }
bool GpuExecutor::GetSymbol(const string& symbol_name, bool GpuExecutor::GetSymbol(const std::string& symbol_name,
ModuleHandle module_handle, void** mem, ModuleHandle module_handle, void** mem,
size_t* bytes) { size_t* bytes) {
auto lookup_in_module = [&](CUmodule module) { auto lookup_in_module = [&](CUmodule module) {
@ -937,7 +937,8 @@ GpuContext* GpuExecutor::gpu_context() { return context_; }
// //
// For anything more complicated/prod-focused than this, you'll likely want to // For anything more complicated/prod-focused than this, you'll likely want to
// turn to gsys' topology modeling. // turn to gsys' topology modeling.
static int TryToReadNumaNode(const string &pci_bus_id, int device_ordinal) { static int TryToReadNumaNode(const std::string& pci_bus_id,
int device_ordinal) {
#if defined(__APPLE__) #if defined(__APPLE__)
LOG(INFO) << "OS X does not support NUMA - returning NUMA node zero"; LOG(INFO) << "OS X does not support NUMA - returning NUMA node zero";
return 0; return 0;
@ -956,7 +957,7 @@ static int TryToReadNumaNode(const string &pci_bus_id, int device_ordinal) {
return kUnknownNumaNode; return kUnknownNumaNode;
} }
string filename = std::string filename =
absl::StrFormat("/sys/bus/pci/devices/%s/numa_node", pci_bus_id); absl::StrFormat("/sys/bus/pci/devices/%s/numa_node", pci_bus_id);
// We have to use fopen/fread here so that the device properties can be // We have to use fopen/fread here so that the device properties can be
@ -969,7 +970,7 @@ static int TryToReadNumaNode(const string &pci_bus_id, int device_ordinal) {
return kUnknownNumaNode; return kUnknownNumaNode;
} }
string content; std::string content;
char buf[32]; char buf[32];
size_t did_read = fread(buf, sizeof(buf[0]), sizeof(buf) - 1, file); size_t did_read = fread(buf, sizeof(buf[0]), sizeof(buf) - 1, file);
buf[did_read] = '\0'; buf[did_read] = '\0';
@ -1017,14 +1018,14 @@ GpuExecutor::CreateDeviceDescription(int device_ordinal) {
{ {
int driver_version = 0; int driver_version = 0;
(void)GpuDriver::GetDriverVersion(&driver_version); (void)GpuDriver::GetDriverVersion(&driver_version);
string augmented_driver_version = absl::StrFormat( std::string augmented_driver_version = absl::StrFormat(
"%d (%s)", driver_version, "%d (%s)", driver_version,
cuda::DriverVersionStatusToString(Diagnostician::FindDsoVersion())); cuda::DriverVersionStatusToString(Diagnostician::FindDsoVersion()));
builder.set_driver_version(augmented_driver_version); builder.set_driver_version(augmented_driver_version);
} }
{ {
string pci_bus_id = GpuDriver::GetPCIBusID(device); std::string pci_bus_id = GpuDriver::GetPCIBusID(device);
// Lower the hex characters to match sysfs. // Lower the hex characters to match sysfs.
pci_bus_id = absl::AsciiStrToLower(pci_bus_id); pci_bus_id = absl::AsciiStrToLower(pci_bus_id);
@ -1090,7 +1091,7 @@ GpuExecutor::CreateDeviceDescription(int device_ordinal) {
} }
{ {
string device_name; std::string device_name;
TF_RETURN_IF_ERROR(GpuDriver::GetDeviceName(device, &device_name)); TF_RETURN_IF_ERROR(GpuDriver::GetDeviceName(device, &device_name));
builder.set_name(device_name); builder.set_name(device_name);
} }

View File

@ -139,7 +139,7 @@ int CudaPlatform::VisibleDeviceCount() const {
return GpuDriver::GetDeviceCount(); return GpuDriver::GetDeviceCount();
} }
const string& CudaPlatform::Name() const { return name_; } const std::string& CudaPlatform::Name() const { return name_; }
port::StatusOr<std::unique_ptr<DeviceDescription>> port::StatusOr<std::unique_ptr<DeviceDescription>>
CudaPlatform::DescriptionForDevice(int ordinal) const { CudaPlatform::DescriptionForDevice(int ordinal) const {

View File

@ -62,7 +62,7 @@ class CudaPlatform : public Platform {
// Returns -1 as a sentinel on internal failure (and logs the error). // Returns -1 as a sentinel on internal failure (and logs the error).
int VisibleDeviceCount() const override; int VisibleDeviceCount() const override;
const string& Name() const override; const std::string& Name() const override;
port::StatusOr<std::unique_ptr<DeviceDescription>> DescriptionForDevice( port::StatusOr<std::unique_ptr<DeviceDescription>> DescriptionForDevice(
int ordinal) const override; int ordinal) const override;
@ -87,7 +87,7 @@ class CudaPlatform : public Platform {
void InspectNumaNodes(); void InspectNumaNodes();
// This platform's name. // This platform's name.
string name_; std::string name_;
// Cache of created executors. // Cache of created executors.
ExecutorCache executor_cache_; ExecutorCache executor_cache_;

View File

@ -55,10 +55,10 @@ port::StatusOr<absl::Span<const uint8>> CompileGpuAsmOrGetCached(
// ptxas_path. // ptxas_path.
// //
// Locks on entry. // Locks on entry.
static void WarnIfBadPtxasVersion(const string& ptxas_path) { static void WarnIfBadPtxasVersion(const std::string& ptxas_path) {
static tensorflow::mutex mu(tensorflow::LINKER_INITIALIZED); static tensorflow::mutex mu(tensorflow::LINKER_INITIALIZED);
static std::unordered_set<string>* seen_ptxas_paths TF_GUARDED_BY(mu) = static std::unordered_set<std::string>* seen_ptxas_paths TF_GUARDED_BY(mu) =
new std::unordered_set<string>(); new std::unordered_set<std::string>();
tensorflow::mutex_lock lock(mu); tensorflow::mutex_lock lock(mu);
if (!seen_ptxas_paths->insert(ptxas_path).second) { if (!seen_ptxas_paths->insert(ptxas_path).second) {
@ -74,7 +74,7 @@ static void WarnIfBadPtxasVersion(const string& ptxas_path) {
return; return;
} }
string out; std::string out;
int exit_code = ptxas.Communicate(/*stdin_input=*/nullptr, &out, int exit_code = ptxas.Communicate(/*stdin_input=*/nullptr, &out,
/*stderr_output=*/nullptr); /*stderr_output=*/nullptr);
if (exit_code != 0) { if (exit_code != 0) {
@ -84,7 +84,7 @@ static void WarnIfBadPtxasVersion(const string& ptxas_path) {
} }
int64 vmaj, vmin, vdot; int64 vmaj, vmin, vdot;
string vmaj_str, vmin_str, vdot_str; std::string vmaj_str, vmin_str, vdot_str;
if (!RE2::PartialMatch(out, R"(\bV(\d+)\.(\d+)\.(\d+)\b)", &vmaj_str, if (!RE2::PartialMatch(out, R"(\bV(\d+)\.(\d+)\.(\d+)\b)", &vmaj_str,
&vmin_str, &vdot_str) || &vmin_str, &vdot_str) ||
!absl::SimpleAtoi(vmaj_str, &vmaj) || !absl::SimpleAtoi(vmaj_str, &vmaj) ||
@ -161,9 +161,9 @@ port::StatusOr<std::vector<uint8>> CompileGpuAsm(int device_ordinal,
port::StatusOr<std::vector<uint8>> CompileGpuAsm(int cc_major, int cc_minor, port::StatusOr<std::vector<uint8>> CompileGpuAsm(int cc_major, int cc_minor,
const char* ptx_contents, const char* ptx_contents,
GpuAsmOpts options) { GpuAsmOpts options) {
string ptxas_path; std::string ptxas_path;
auto env = tensorflow::Env::Default(); auto env = tensorflow::Env::Default();
for (const string& cuda_root : for (const std::string& cuda_root :
tensorflow::CandidateCudaRoots(options.preferred_cuda_dir)) { tensorflow::CandidateCudaRoots(options.preferred_cuda_dir)) {
ptxas_path = tensorflow::io::JoinPath(cuda_root, "bin", "ptxas"); ptxas_path = tensorflow::io::JoinPath(cuda_root, "bin", "ptxas");
VLOG(2) << "Looking for ptxas at " << ptxas_path; VLOG(2) << "Looking for ptxas at " << ptxas_path;
@ -180,7 +180,7 @@ port::StatusOr<std::vector<uint8>> CompileGpuAsm(int cc_major, int cc_minor,
WarnIfBadPtxasVersion(ptxas_path); WarnIfBadPtxasVersion(ptxas_path);
// Write ptx into a temporary file. // Write ptx into a temporary file.
string ptx_path; std::string ptx_path;
if (!env->LocalTempFilename(&ptx_path)) { if (!env->LocalTempFilename(&ptx_path)) {
return port::InternalError("couldn't get temp PTX file name"); return port::InternalError("couldn't get temp PTX file name");
} }
@ -193,7 +193,7 @@ port::StatusOr<std::vector<uint8>> CompileGpuAsm(int cc_major, int cc_minor,
}); });
// Invoke ptxas and collect its output. // Invoke ptxas and collect its output.
string cubin_path; std::string cubin_path;
if (!env->LocalTempFilename(&cubin_path)) { if (!env->LocalTempFilename(&cubin_path)) {
return port::InternalError("couldn't get temp CUBIN file name"); return port::InternalError("couldn't get temp CUBIN file name");
} }
@ -203,7 +203,7 @@ port::StatusOr<std::vector<uint8>> CompileGpuAsm(int cc_major, int cc_minor,
tensorflow::Env::Default()->DeleteFile(cubin_path).IgnoreError(); tensorflow::Env::Default()->DeleteFile(cubin_path).IgnoreError();
}); });
tensorflow::SubProcess ptxas_info_dumper; tensorflow::SubProcess ptxas_info_dumper;
std::vector<string> ptxas_args = { std::vector<std::string> ptxas_args = {
ptxas_path, ptx_path, "-o", cubin_path, ptxas_path, ptx_path, "-o", cubin_path,
absl::StrCat("-arch=sm_", cc_major, cc_minor)}; absl::StrCat("-arch=sm_", cc_major, cc_minor)};
if (VLOG_IS_ON(2)) { if (VLOG_IS_ON(2)) {
@ -220,7 +220,7 @@ port::StatusOr<std::vector<uint8>> CompileGpuAsm(int cc_major, int cc_minor,
if (!ptxas_info_dumper.Start()) { if (!ptxas_info_dumper.Start()) {
return port::InternalError("Failed to launch ptxas"); return port::InternalError("Failed to launch ptxas");
} }
string stderr_output; std::string stderr_output;
int exit_status = ptxas_info_dumper.Communicate( int exit_status = ptxas_info_dumper.Communicate(
/*stdin_input=*/nullptr, /*stdout_output=*/nullptr, &stderr_output); /*stdin_input=*/nullptr, /*stdout_output=*/nullptr, &stderr_output);
if (exit_status != 0) { if (exit_status != 0) {
@ -230,7 +230,7 @@ port::StatusOr<std::vector<uint8>> CompileGpuAsm(int cc_major, int cc_minor,
} }
// Read in the result of compilation and return it as a byte vector. // Read in the result of compilation and return it as a byte vector.
string cubin; std::string cubin;
TF_RETURN_IF_ERROR(tensorflow::ReadFileToString(tensorflow::Env::Default(), TF_RETURN_IF_ERROR(tensorflow::ReadFileToString(tensorflow::Env::Default(),
cubin_path, &cubin)); cubin_path, &cubin));
std::vector<uint8> cubin_vector(cubin.begin(), cubin.end()); std::vector<uint8> cubin_vector(cubin.begin(), cubin.end());

View File

@ -60,7 +60,7 @@ class Diagnostician {
// This is solely used for more informative log messages when the user is // This is solely used for more informative log messages when the user is
// running on a machine that happens to have a libcuda/kernel driver mismatch. // running on a machine that happens to have a libcuda/kernel driver mismatch.
static port::StatusOr<DriverVersion> FindKernelModuleVersion( static port::StatusOr<DriverVersion> FindKernelModuleVersion(
const string& driver_version_file_contents); const std::string& driver_version_file_contents);
// Extracts the kernel driver version from the current host. // Extracts the kernel driver version from the current host.
static port::StatusOr<DriverVersion> FindKernelDriverVersion(); static port::StatusOr<DriverVersion> FindKernelDriverVersion();
@ -88,7 +88,7 @@ class Diagnostician {
// existence, permissions, accessibility from this uid/gid. // existence, permissions, accessibility from this uid/gid.
static void LogDevNodeDiagnosticInformation(); static void LogDevNodeDiagnosticInformation();
static string GetDevNodePath(int dev_node_ordinal); static std::string GetDevNodePath(int dev_node_ordinal);
SE_DISALLOW_COPY_AND_ASSIGN(Diagnostician); SE_DISALLOW_COPY_AND_ASSIGN(Diagnostician);
}; };

View File

@ -34,7 +34,7 @@ namespace gpu {
enum class MemorySpace { kHost, kDevice }; enum class MemorySpace { kHost, kDevice };
// Returns a casual string, such as "host" for the provided memory space. // Returns a casual string, such as "host" for the provided memory space.
string MemorySpaceString(MemorySpace memory_space); std::string MemorySpaceString(MemorySpace memory_space);
class GpuContext; class GpuContext;
@ -149,7 +149,7 @@ class GpuDriver {
// Given a device handle, returns the name reported by the driver for the // Given a device handle, returns the name reported by the driver for the
// device. // device.
static port::Status GetDeviceName(GpuDeviceHandle device, static port::Status GetDeviceName(GpuDeviceHandle device,
string* device_name); std::string* device_name);
// Given a device to create a context for, returns a context handle into the // Given a device to create a context for, returns a context handle into the
// context outparam, which must not be null. // context outparam, which must not be null.
@ -469,7 +469,7 @@ class GpuDriver {
// Returns a PCI bus id string for the device. // Returns a PCI bus id string for the device.
// [domain]:[bus]:[device].[function] // [domain]:[bus]:[device].[function]
// http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1g85295e7d9745ab8f0aa80dd1e172acfc // http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1g85295e7d9745ab8f0aa80dd1e172acfc
static string GetPCIBusID(GpuDeviceHandle device); static std::string GetPCIBusID(GpuDeviceHandle device);
// -- Context- and device-independent calls. // -- Context- and device-independent calls.

View File

@ -196,7 +196,7 @@ class GpuExecutor : public internal::StreamExecutorInterface {
// Search for the symbol and returns a device pointer and size. // Search for the symbol and returns a device pointer and size.
// Returns false if symbol does not exist. // Returns false if symbol does not exist.
bool GetSymbol(const string& symbol_name, ModuleHandle module_handle, bool GetSymbol(const std::string& symbol_name, ModuleHandle module_handle,
void** mem, size_t* bytes) override; void** mem, size_t* bytes) override;
port::StatusOr<std::unique_ptr<DeviceDescription>> CreateDeviceDescription() port::StatusOr<std::unique_ptr<DeviceDescription>> CreateDeviceDescription()
@ -245,7 +245,7 @@ class GpuExecutor : public internal::StreamExecutorInterface {
// (supported on CUDA only) // (supported on CUDA only)
bool FindOnDiskForComputeCapability(absl::string_view filename, bool FindOnDiskForComputeCapability(absl::string_view filename,
absl::string_view canonical_suffix, absl::string_view canonical_suffix,
string* found_filename) const; std::string* found_filename) const;
// Attempts to find a more specific version of the file indicated by // Attempts to find a more specific version of the file indicated by
// filename by looking for AMDGPU ISA-specific suffixed versions. // filename by looking for AMDGPU ISA-specific suffixed versions.
@ -253,7 +253,7 @@ class GpuExecutor : public internal::StreamExecutorInterface {
bool FindOnDiskForISAVersion(absl::string_view filename, bool FindOnDiskForISAVersion(absl::string_view filename,
absl::string_view canonical_suffix, absl::string_view canonical_suffix,
string* found_filename) const; std::string* found_filename) const;
// Host callback landing routine invoked by CUDA. // Host callback landing routine invoked by CUDA.
// data: User-provided callback provided to HostCallback() above, captured // data: User-provided callback provided to HostCallback() above, captured
@ -294,7 +294,7 @@ class GpuExecutor : public internal::StreamExecutorInterface {
// Multiple GPUFunctionHandle are usually obtained from a single // Multiple GPUFunctionHandle are usually obtained from a single
// GPUModuleHandle so we attempt to hit in this mapping first, before // GPUModuleHandle so we attempt to hit in this mapping first, before
// retrieving it. // retrieving it.
std::map<string, GpuModuleHandle> disk_modules_ std::map<std::string, GpuModuleHandle> disk_modules_
TF_GUARDED_BY(disk_modules_mu_); TF_GUARDED_BY(disk_modules_mu_);
// Guards the in-memory-module mapping. // Guards the in-memory-module mapping.

View File

@ -96,25 +96,25 @@ class GpuRng : public rng::RngSupport {
}; };
template <typename T> template <typename T>
string TypeString(); std::string TypeString();
template <> template <>
string TypeString<float>() { std::string TypeString<float>() {
return "float"; return "float";
} }
template <> template <>
string TypeString<double>() { std::string TypeString<double>() {
return "double"; return "double";
} }
template <> template <>
string TypeString<std::complex<float>>() { std::string TypeString<std::complex<float>>() {
return "std::complex<float>"; return "std::complex<float>";
} }
template <> template <>
string TypeString<std::complex<double>>() { std::string TypeString<std::complex<double>>() {
return "std::complex<double>"; return "std::complex<double>";
} }

View File

@ -77,7 +77,7 @@ class RedzoneAllocator : public ScratchAllocator {
std::string RedzoneFailureMsg() const; std::string RedzoneFailureMsg() const;
string buffer_name = {}; std::string buffer_name = {};
void* user_buffer_address = nullptr; void* user_buffer_address = nullptr;
int64 offset = 0; int64 offset = 0;
uint64 expected_value = 0; uint64 expected_value = 0;