aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/lib/strings/numbers.cc
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <nobody@tensorflow.org>2016-02-29 08:17:58 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-02-29 10:48:41 -0800
commit977ea14361f7bceeeda2046f3073ea888806be02 (patch)
treeaadc117fa50c0e0df9b1bf4c1ac7cf4a7066b03d /tensorflow/core/lib/strings/numbers.cc
parentdb828ab20399697bb97c218ca6c435ee59b2a029 (diff)
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
Diffstat (limited to 'tensorflow/core/lib/strings/numbers.cc')
-rw-r--r--tensorflow/core/lib/strings/numbers.cc33
1 files changed, 33 insertions, 0 deletions
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 <ctype.h>
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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.