From cea9ef6f548ef38fbc368be23f7262c662be6c67 Mon Sep 17 00:00:00 2001 From: horance Date: Thu, 27 Jul 2017 14:00:05 +0800 Subject: [PATCH] Refactoring device name utils (#11797) * remove duplicated code for full_name and legacy_name for DeviceNameUtils * replace tabs * Real->Device --- tensorflow/core/util/device_name_utils.cc | 25 ++++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tensorflow/core/util/device_name_utils.cc b/tensorflow/core/util/device_name_utils.cc index 1773ac00b7a..530a1737e5a 100644 --- a/tensorflow/core/util/device_name_utils.cc +++ b/tensorflow/core/util/device_name_utils.cc @@ -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) {