diff options
author | Max Galkin <maxgalkin@google.com> | 2017-12-14 14:20:28 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-12-14 14:23:32 -0800 |
commit | 2d95be8795e4d8ac3d1547cebffcd12f6bb73563 (patch) | |
tree | d31eb279e9a51bfa167cae1d8ada4d11c673d0d3 /tensorflow/core/grappler/costs/cost_estimator.h | |
parent | 3b195ebccb54c85c7fc2121b9f50eb9ab0a46989 (diff) |
Add a utility struct for MilliSeconds time unit.
PiperOrigin-RevId: 179096409
Diffstat (limited to 'tensorflow/core/grappler/costs/cost_estimator.h')
-rw-r--r-- | tensorflow/core/grappler/costs/cost_estimator.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/tensorflow/core/grappler/costs/cost_estimator.h b/tensorflow/core/grappler/costs/cost_estimator.h index cf9fa4fdaf..852e69737b 100644 --- a/tensorflow/core/grappler/costs/cost_estimator.h +++ b/tensorflow/core/grappler/costs/cost_estimator.h @@ -40,6 +40,16 @@ struct Costs { // Builds a Costs structure with all zero values, rather than unknowns. static inline Costs ZeroCosts(); + struct MilliSeconds : std::chrono::milliseconds { + MilliSeconds() : std::chrono::milliseconds(0) {} + MilliSeconds(double d) : std::chrono::milliseconds(static_cast<int64>(d)) {} + MilliSeconds(const std::chrono::milliseconds& d) + : std::chrono::milliseconds(d) {} + MilliSeconds& operator=(const std::chrono::milliseconds& d) { + std::chrono::milliseconds::operator=(d); + return *this; + } + }; struct MicroSeconds : std::chrono::microseconds { MicroSeconds() : std::chrono::microseconds(0) {} MicroSeconds(double d) : std::chrono::microseconds(static_cast<int64>(d)) {} @@ -49,6 +59,9 @@ struct Costs { std::chrono::microseconds::operator=(d); return *this; } + MilliSeconds asMilliSeconds() const { + return std::chrono::duration_cast<std::chrono::milliseconds>(*this); + } }; struct NanoSeconds : std::chrono::nanoseconds { NanoSeconds() : std::chrono::nanoseconds(0) {} @@ -60,9 +73,10 @@ struct Costs { return *this; } MicroSeconds asMicroSeconds() const { - std::chrono::microseconds us = - std::chrono::duration_cast<std::chrono::microseconds>(*this); - return MicroSeconds(us); + return std::chrono::duration_cast<std::chrono::microseconds>(*this); + } + MilliSeconds asMilliSeconds() const { + return std::chrono::duration_cast<std::chrono::milliseconds>(*this); } }; @@ -100,6 +114,10 @@ struct Costs { std::unordered_map<string, uint64> estimated_max_memory_per_device; }; +inline std::ostream& operator<<(std::ostream& os, const Costs::MilliSeconds d) { + os << d.count() << "ms"; + return os; +} inline std::ostream& operator<<(std::ostream& os, const Costs::MicroSeconds d) { os << d.count() << "us"; return os; |