diff options
author | 2018-09-02 16:10:07 -0700 | |
---|---|---|
committer | 2018-09-02 16:18:04 -0700 | |
commit | 655b2afc50a0ee07e80a7e28363e853d2fac97cc (patch) | |
tree | 95b57d4826a921a1d89df7c6c39ba1c2bc6ecde2 /tensorflow/core/grappler | |
parent | caf4645b1e73e3e1111fb72342a5ade835ac1bf1 (diff) |
Rollforward of rollback:
Reinstate the use of integral-exponent power function MathUtil::IPow, but make sure to use a floating point base, so as to compute the result using floating point arithmetic. This behaviour is equivalent to, but faster than, std::pow.
Note that care must be taken to convert the base to double, which we effect by providing an explicit template type argument for MathUtil::IPow.
PiperOrigin-RevId: 211290304
Diffstat (limited to 'tensorflow/core/grappler')
-rw-r--r-- | tensorflow/core/grappler/optimizers/memory_optimizer.cc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tensorflow/core/grappler/optimizers/memory_optimizer.cc b/tensorflow/core/grappler/optimizers/memory_optimizer.cc index 2d1a34f2dd..c775a26914 100644 --- a/tensorflow/core/grappler/optimizers/memory_optimizer.cc +++ b/tensorflow/core/grappler/optimizers/memory_optimizer.cc @@ -37,6 +37,7 @@ limitations under the License. #include "tensorflow/core/grappler/utils.h" #include "tensorflow/core/grappler/utils/topological_sort.h" #include "tensorflow/core/grappler/utils/traversal.h" +#include "tensorflow/core/lib/math/math_util.h" #include "tensorflow/core/protobuf/rewriter_config.pb.h" namespace tensorflow { @@ -1070,9 +1071,13 @@ static bool IdentifySwappingCandidates( // ensure that swapping the tensor back in won't recreate the memory // bottleneck. Last but not least, we want the tensor to have as few // remaining uses as possible. - mem_info.fitness = std::pow((earliest_use - peak_time).count(), 2); - mem_info.fitness /= std::pow(mem_info.uses_left.size(), 2); - mem_info.fitness += std::pow((allocation_time - peak_time).count(), 2); + // + // Note that we must perform the arithmetic inexactly as "double", since + // the values do not fit into any integral type. + mem_info.fitness = + MathUtil::IPow<double>((earliest_use - peak_time).count(), 2) / + MathUtil::IPow<double>(mem_info.uses_left.size(), 2) + + MathUtil::IPow<double>((allocation_time - peak_time).count(), 2); mem_info.fitness = -mem_info.fitness; mem_state.push_back(mem_info); } |