[XLA:CPU] Fusion: Only check for reuse on expensive instructions

The reuse condition walks over all instructions in the fusion, the fusion pass
walks over all instructions, making this essentially quadratic. Moving the
is_expensive check up doesn't completely avoid this behavior, but makes it much
more unlikely.

PiperOrigin-RevId: 317063582
Change-Id: I22459aa922e6d65c6c639ed81208d1d441a132bc
This commit is contained in:
Benjamin Kramer 2020-06-18 02:38:26 -07:00 committed by TensorFlower Gardener
parent d230ccaa55
commit dd49e65c5b

View File

@ -94,9 +94,8 @@ bool CpuInstructionFusion::ShouldFuse(HloInstruction* consumer,
// Cost condition: not fuse (simple, expensive producers) and (consumers who // Cost condition: not fuse (simple, expensive producers) and (consumers who
// reuse operand elements). // reuse operand elements).
if (producer->opcode() != HloOpcode::kFusion && if (producer->opcode() != HloOpcode::kFusion && is_expensive(*producer) &&
consumer->ReusesOperandElements(operand_index) && consumer->ReusesOperandElements(operand_index)) {
is_expensive(*producer)) {
VLOG(2) << "Fusion is not profitable."; VLOG(2) << "Fusion is not profitable.";
return false; return false;
} }