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

Method HandleDivide

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

Source from the content-addressed store, hash-verified

1086} // namespace
1087
1088Status AlgebraicSimplifierVisitor::HandleDivide(HloInstruction* divide) {
1089 HloInstruction *a, *b, *c, *d;
1090 CHECK(Match(divide, m::Divide(m::Op(&a), m::Op(&b))));
1091 // A/1 => A
1092 VLOG(10) << "trying transform [A/1 => A]: " << divide->ToString();
1093 if (IsAll(b, 1) && ReplaceInstructionIfSameShape(divide, a)) {
1094 return Status::OK();
1095 }
1096
1097 // A / B => A >> log2(B) if B is a power of 2.
1098 switch (divide->shape().element_type()) {
1099 case S8:
1100 if (std::unique_ptr<HloInstruction> shift =
1101 TryDivideToShift<int8>(divide, computation_, simplifier_)) {
1102 return ReplaceWithNewInstruction(divide, std::move(shift));
1103 }
1104 break;
1105 case S16:
1106 if (std::unique_ptr<HloInstruction> shift =
1107 TryDivideToShift<int16>(divide, computation_, simplifier_)) {
1108 return ReplaceWithNewInstruction(divide, std::move(shift));
1109 }
1110 break;
1111 case S32:
1112 if (std::unique_ptr<HloInstruction> shift =
1113 TryDivideToShift<int32>(divide, computation_, simplifier_)) {
1114 return ReplaceWithNewInstruction(divide, std::move(shift));
1115 }
1116 break;
1117 case S64:
1118 if (std::unique_ptr<HloInstruction> shift =
1119 TryDivideToShift<int64>(divide, computation_, simplifier_)) {
1120 return ReplaceWithNewInstruction(divide, std::move(shift));
1121 }
1122 break;
1123 case U8:
1124 if (std::unique_ptr<HloInstruction> shift =
1125 TryDivideToShift<uint8>(divide, computation_, simplifier_)) {
1126 return ReplaceWithNewInstruction(divide, std::move(shift));
1127 }
1128 break;
1129 case U16:
1130 if (std::unique_ptr<HloInstruction> shift =
1131 TryDivideToShift<uint16>(divide, computation_, simplifier_)) {
1132 return ReplaceWithNewInstruction(divide, std::move(shift));
1133 }
1134 break;
1135 case U32:
1136 if (std::unique_ptr<HloInstruction> shift =
1137 TryDivideToShift<uint32>(divide, computation_, simplifier_)) {
1138 return ReplaceWithNewInstruction(divide, std::move(shift));
1139 }
1140 break;
1141 case U64:
1142 if (std::unique_ptr<HloInstruction> shift =
1143 TryDivideToShift<uint64>(divide, computation_, simplifier_)) {
1144 return ReplaceWithNewInstruction(divide, std::move(shift));
1145 }

Callers 1

VisitMethod · 0.45

Calls 15

PowerClass · 0.85
NonConstantFunction · 0.85
BroadcastFunction · 0.85
WithShapeMethod · 0.80
MatchFunction · 0.70
OpFunction · 0.70
IsAllFunction · 0.70
ShapeFunction · 0.70
ExpClass · 0.50
SqrtClass · 0.50
RsqrtFunction · 0.50

Tested by

no test coverage detected