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

Method HandleRemainder

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

Source from the content-addressed store, hash-verified

3009} // namespace
3010
3011Status AlgebraicSimplifierVisitor::HandleRemainder(HloInstruction* remainder) {
3012 HloInstruction *a, *b;
3013 CHECK(Match(remainder, m::Remainder(m::Op(&a), m::Op(&b))));
3014
3015 // (A % B) % B == A % B.
3016 if (Match(a, m::Remainder(m::Op(), m::Op().Is(b)))) {
3017 return ReplaceInstruction(remainder, a);
3018 }
3019
3020 // A % B => A & (B - 1) if B is a power of 2.
3021 switch (remainder->shape().element_type()) {
3022 case S8:
3023 if (std::unique_ptr<HloInstruction> shift =
3024 TryRemainderToAnd<int8>(remainder, computation_, simplifier_)) {
3025 return ReplaceWithNewInstruction(remainder, std::move(shift));
3026 }
3027 break;
3028 case S16:
3029 if (std::unique_ptr<HloInstruction> shift =
3030 TryRemainderToAnd<int16>(remainder, computation_, simplifier_)) {
3031 return ReplaceWithNewInstruction(remainder, std::move(shift));
3032 }
3033 break;
3034 case S32:
3035 if (std::unique_ptr<HloInstruction> shift =
3036 TryRemainderToAnd<int32>(remainder, computation_, simplifier_)) {
3037 return ReplaceWithNewInstruction(remainder, std::move(shift));
3038 }
3039 break;
3040 case S64:
3041 if (std::unique_ptr<HloInstruction> shift =
3042 TryRemainderToAnd<int64>(remainder, computation_, simplifier_)) {
3043 return ReplaceWithNewInstruction(remainder, std::move(shift));
3044 }
3045 break;
3046 case U8:
3047 if (std::unique_ptr<HloInstruction> shift =
3048 TryRemainderToAnd<uint8>(remainder, computation_, simplifier_)) {
3049 return ReplaceWithNewInstruction(remainder, std::move(shift));
3050 }
3051 break;
3052 case U16:
3053 if (std::unique_ptr<HloInstruction> shift =
3054 TryRemainderToAnd<uint16>(remainder, computation_, simplifier_)) {
3055 return ReplaceWithNewInstruction(remainder, std::move(shift));
3056 }
3057 break;
3058 case U32:
3059 if (std::unique_ptr<HloInstruction> shift =
3060 TryRemainderToAnd<uint32>(remainder, computation_, simplifier_)) {
3061 return ReplaceWithNewInstruction(remainder, std::move(shift));
3062 }
3063 break;
3064 case U64:
3065 if (std::unique_ptr<HloInstruction> shift =
3066 TryRemainderToAnd<uint64>(remainder, computation_, simplifier_)) {
3067 return ReplaceWithNewInstruction(remainder, std::move(shift));
3068 }

Callers 1

VisitMethod · 0.45

Calls 15

RemainderClass · 0.85
BroadcastFunction · 0.85
ConstantEffectiveScalarFunction · 0.85
OverflowSafeAddFunction · 0.85
FitsInIntegralTypeFunction · 0.85
IsMethod · 0.80
iota_dimensionMethod · 0.80
GetIntegralAsS64Method · 0.80
dimensions_sizeMethod · 0.80
MatchFunction · 0.70
OpFunction · 0.70
IotaFunction · 0.50

Tested by

no test coverage detected