From dd49e65c5b68c4b8113dfe5aadb988fdeb2abd57 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 18 Jun 2020 02:38:26 -0700 Subject: [PATCH] [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 --- .../compiler/xla/service/cpu/cpu_instruction_fusion.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tensorflow/compiler/xla/service/cpu/cpu_instruction_fusion.cc b/tensorflow/compiler/xla/service/cpu/cpu_instruction_fusion.cc index 97e0a518499..9460cc55e10 100644 --- a/tensorflow/compiler/xla/service/cpu/cpu_instruction_fusion.cc +++ b/tensorflow/compiler/xla/service/cpu/cpu_instruction_fusion.cc @@ -94,9 +94,8 @@ bool CpuInstructionFusion::ShouldFuse(HloInstruction* consumer, // Cost condition: not fuse (simple, expensive producers) and (consumers who // reuse operand elements). - if (producer->opcode() != HloOpcode::kFusion && - consumer->ReusesOperandElements(operand_index) && - is_expensive(*producer)) { + if (producer->opcode() != HloOpcode::kFusion && is_expensive(*producer) && + consumer->ReusesOperandElements(operand_index)) { VLOG(2) << "Fusion is not profitable."; return false; }