From 977ea14361f7bceeeda2046f3073ea888806be02 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Mon, 29 Feb 2016 08:17:58 -0800 Subject: Added more streamlined interfaces for converting rendezvous ids to/from strings and used these in the rendezvous code. Improves performance for ptb_word_lm slightly (saves several allocations and an sscanf per CPU <-> GPU transfer). Change: 115852277 --- tensorflow/core/lib/strings/numbers.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tensorflow/core/lib/strings/numbers.cc') diff --git a/tensorflow/core/lib/strings/numbers.cc b/tensorflow/core/lib/strings/numbers.cc index 778545b44b..a60de543cc 100644 --- a/tensorflow/core/lib/strings/numbers.cc +++ b/tensorflow/core/lib/strings/numbers.cc @@ -15,6 +15,7 @@ limitations under the License. #include "tensorflow/core/lib/strings/numbers.h" +#include #include #include #include @@ -237,6 +238,38 @@ bool StringToFp(const string& s, Fprint* fp) { } } +StringPiece Uint64ToHexString(uint64 v, char* buf) { + static const char* hexdigits = "0123456789abcdef"; + const int num_byte = 16; + buf[num_byte] = '\0'; + for (int i = num_byte - 1; i >= 0; i--) { + buf[i] = hexdigits[v & 0xf]; + v >>= 4; + } + return StringPiece(buf, num_byte); +} + +bool HexStringToUint64(const StringPiece& s, uint64* result) { + uint64 v = 0; + if (s.empty()) { + return false; + } + for (int i = 0; i < s.size(); i++) { + char c = s[i]; + if (c >= '0' && c <= '9') { + v = (v << 4) + (c - '0'); + } else if (c >= 'a' && c <= 'f') { + v = (v << 4) + 10 + (c - 'a'); + } else if (c >= 'A' && c <= 'F') { + v = (v << 4) + 10 + (c - 'A'); + } else { + return false; + } + } + *result = v; + return true; +} + string HumanReadableNumBytes(int64 num_bytes) { if (num_bytes == kint64min) { // Special case for number with not representable negation. -- cgit v1.2.3