Refactoring device name utils (#11797)
* remove duplicated code for full_name and legacy_name for DeviceNameUtils * replace tabs * Real->Device
This commit is contained in:
parent
1f7c0f917e
commit
cea9ef6f54
@ -85,28 +85,29 @@ static bool ConsumeNumber(StringPiece* in, int* val) {
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
string DeviceNameUtils::FullName(const string& job, int replica, int task,
|
||||
const string& type, int id) {
|
||||
// Returns a fully qualified device name given the parameters.
|
||||
static string DeviceName(const string& job, int replica, int task,
|
||||
const string& device_prefix, const string& device_type,
|
||||
int id) {
|
||||
CHECK(IsJobName(job)) << job;
|
||||
CHECK_LE(0, replica);
|
||||
CHECK_LE(0, task);
|
||||
CHECK(!type.empty());
|
||||
CHECK(!device_type.empty());
|
||||
CHECK_LE(0, id);
|
||||
return strings::StrCat("/job:", job, "/replica:", replica, "/task:", task,
|
||||
"/device:", type, ":", id);
|
||||
device_prefix, device_type, ":", id);
|
||||
}
|
||||
|
||||
/* static */
|
||||
string DeviceNameUtils::FullName(const string& job, int replica, int task,
|
||||
const string& type, int id) {
|
||||
return DeviceName(job, replica, task, "/device:", type, id);
|
||||
}
|
||||
|
||||
/* static */
|
||||
string DeviceNameUtils::LegacyName(const string& job, int replica, int task,
|
||||
const string& type, int id) {
|
||||
CHECK(IsJobName(job)) << job;
|
||||
CHECK_LE(0, replica);
|
||||
CHECK_LE(0, task);
|
||||
CHECK(!type.empty());
|
||||
CHECK_LE(0, id);
|
||||
return strings::StrCat("/job:", job, "/replica:", replica, "/task:", task,
|
||||
"/", str_util::Lowercase(type), ":", id);
|
||||
return DeviceName(job, replica, task, "/", str_util::Lowercase(type), id);
|
||||
}
|
||||
|
||||
bool DeviceNameUtils::ParseFullName(StringPiece fullname, ParsedName* p) {
|
||||
|
Loading…
Reference in New Issue
Block a user