tensorflow/compiler/xla/tests/test_utils.cc
// Given an instruction and operand number, replace the given operand with
// a Literal Constant Zero. Handle the case of a fusion instruction by
// replacing the fusion's parent's parameter with a Literal Constant Zero,
// unless the fusion's parent is itself a fusion.
Given an instruction and operand number, replace the given operand with
a Literal Constant Zero. Handle the case of a fusion instruction by
replacing the fusion's parent's parameter with a Literal Constant Zero,
unless the fusion's parent is itself a fusion.
Given an instruction and operand number replace the given operand with a Literal Constant Zero . Handle the case of a fusion instruction by replacing the fusion ' s parent ' s parameter with a Literal Constant Zero unless the fusion ' s parent is itself a fusion .
Status MaybeReplaceParameterInputWithZero(HloInstruction* const instruction,
                                          const int64 operand_number) {
  CHECK_LT(operand_number, instruction->operand_count());
  if (instruction->operand(operand_number)->opcode() != HloOpcode::kParameter) {
    return Status::OK();
  }
  HloComputation* const computation = instruction->parent();
  std::unique_ptr<HloInstruction> zero = HloInstruction::CreateConstant(
      MakeUnique<Literal>(Literal::Zero(instruction->shape().element_type())));
  if (computation->IsFusionComputation()) {
    HloInstruction* const fusion_instruction = computation->FusionInstruction();
    if (fusion_instruction->IsFused()) {
      return Unimplemented(
          "Unable to replace fused parameter of fusion instruction");
    }
    TF_RETURN_IF_ERROR(fusion_instruction->ReplaceOperandWith(
        instruction->operand(operand_number)->parameter_number(),
        fusion_instruction->parent()->AddInstruction(std::move(zero))));
  } else {
    TF_RETURN_IF_ERROR(instruction->ReplaceOperandWith(
        operand_number, computation->AddInstruction(std::move(zero))));
  }
  return Status::OK();
}
Status MaybeReplaceParameterInputWithZero ( HloInstruction * const instruction , const int64 operand_number ) { CHECK_LT ( operand_number , instruction -> operand_count ( ) ) ; if ( instruction -> operand ( operand_number ) -> opcode ( ) != HloOpcode :: kParameter ) { return Status :: OK ( ) ; } HloComputation * const computation = instruction -> parent ( ) ; std :: unique_ptr < HloInstruction > zero = HloInstruction :: CreateConstant ( MakeUnique < Literal > ( Literal :: Zero ( instruction -> shape ( ) . element_type ( ) ) ) ) ; if ( computation -> IsFusionComputation ( ) ) { HloInstruction * const fusion_instruction = computation -> FusionInstruction ( ) ; if ( fusion_instruction -> IsFused ( ) ) { return Unimplemented ( " " ) ; } TF_RETURN_IF_ERROR ( fusion_instruction -> ReplaceOperandWith ( instruction -> operand ( operand_number ) -> parameter_number ( ) , fusion_instruction -> parent ( ) -> AddInstruction ( std :: move ( zero ) ) ) ) ; } else { TF_RETURN_IF_ERROR ( instruction -> ReplaceOperandWith ( operand_number , computation -> AddInstruction ( std :: move ( zero ) ) ) ) ; } return Status :: OK ( ) ; }
Given an instruction and operand number, replace the given operand with
a Literal Constant Zero.
Given an instruction and operand number replace the given operand with a Literal Constant Zero .