Skip to content

Commit

Permalink
Rollforward of rollback:
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tensorflower-gardener committed Sep 2, 2018
1 parent caf4645 commit 655b2af
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tensorflow/core/grappler/optimizers/memory_optimizer.cc
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 655b2af

Please sign in to comment.