MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / HandleCompare

Method HandleCompare

tensorflow/compiler/xla/service/algebraic_simplifier.cc:2580–2612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2578}
2579
2580Status AlgebraicSimplifierVisitor::HandleCompare(HloInstruction* compare) {
2581 HloInstruction* lhs;
2582 HloInstruction* rhs;
2583 CHECK(Match(compare, m::Compare(m::Op(&lhs), m::Op(&rhs))));
2584
2585 if (compare->comparison_direction() == ComparisonDirection::kLt &&
2586 lhs->opcode() == HloOpcode::kIota && IsAll(rhs, 0)) {
2587 return ReplaceInstruction(compare, MakeScalarLike(compare, false));
2588 } else if (compare->comparison_direction() == ComparisonDirection::kGt &&
2589 IsAll(lhs, 0) && rhs->opcode() == HloOpcode::kIota) {
2590 return ReplaceInstruction(compare, MakeScalarLike(compare, false));
2591 } else if (compare->comparison_direction() == ComparisonDirection::kGe &&
2592 lhs->opcode() == HloOpcode::kIota && IsAll(rhs, 0)) {
2593 return ReplaceInstruction(compare, MakeScalarLike(compare, true));
2594 } else if (compare->comparison_direction() == ComparisonDirection::kLe &&
2595 IsAll(lhs, 0) && rhs->opcode() == HloOpcode::kIota) {
2596 return ReplaceInstruction(compare, MakeScalarLike(compare, true));
2597 }
2598 if (lhs == rhs &&
2599 primitive_util::IsIntegralType(lhs->shape().element_type())) {
2600 switch (compare->comparison_direction()) {
2601 case ComparisonDirection::kGt:
2602 case ComparisonDirection::kLt:
2603 case ComparisonDirection::kNe:
2604 return ReplaceInstruction(compare, MakeScalarLike(compare, false));
2605 case ComparisonDirection::kEq:
2606 case ComparisonDirection::kGe:
2607 case ComparisonDirection::kLe:
2608 return ReplaceInstruction(compare, MakeScalarLike(compare, true));
2609 }
2610 }
2611 return Status::OK();
2612}
2613
2614Status AlgebraicSimplifierVisitor::HandleConvert(HloInstruction* convert) {
2615 PrimitiveType src_type = convert->operand(0)->shape().element_type();

Callers

nothing calls this directly

Calls 10

MakeScalarLikeFunction · 0.85
IsIntegralTypeFunction · 0.85
comparison_directionMethod · 0.80
opcodeMethod · 0.80
MatchFunction · 0.70
CompareFunction · 0.70
OpFunction · 0.70
IsAllFunction · 0.70
element_typeMethod · 0.45
shapeMethod · 0.45

Tested by

no test coverage detected