[TorchToTosa] Lower bool bitwise ops to logical ops#4490
[TorchToTosa] Lower bool bitwise ops to logical ops#4490
Conversation
TOSA bitwise_* ops do not accept i1 tensors. When aten.bitwise_* is applied to bool tensors, lower to tosa.logical_and/or/xor instead. Add a conversion test for bool bitwise_and. Signed-off-by: Cathal Corbett <cathal.corbett@arm.com> Change-Id: I98e0ae72f69c926abe97c036489bf2e39ba6f88f
| auto lhsBool = | ||
| tosa::tosaCastTensorToType(rewriter, lhs, resultTy).value(); | ||
| auto rhsBool = | ||
| tosa::tosaCastTensorToType(rewriter, rhsTensor, resultTy).value(); |
There was a problem hiding this comment.
Are these casts necessary? Won't the operand types already be same as the result type for the ops under consideration?
There was a problem hiding this comment.
I traced the lowering in ConvertAtenCompareOp: resultTy comes from the type converter, but lhs/rhsTensor are still the original operands at that point, before any promotion. So I don't believe we can prove operands are already i1 when resultTy is i1. The casts are therefore defensive to guarantee i1 for Logical*Op.
There was a problem hiding this comment.
@catcor01 Can you please clarify this question? Thanks!
There was a problem hiding this comment.
@sahas3 apologies, I did not realize my comment has been pending since yesterday.
Change-Id: If46ca296d3d4fbd27ed5f39ed88a17825a23aa4f Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
Change-Id: I8770a509a395145fae78cbcc93320279a4c25de9 Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
983e5b0 to
8911a85
Compare
Change-Id: I0c4e3b06d550efa0995fe5e4d5170a6852c2c948 Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
Change-Id: Ib55aaccd05bb09e8815dd2c68eb235c37504f3f4 Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
| auto lhsBool = | ||
| tosa::tosaCastTensorToType(rewriter, lhs, resultTy).value(); | ||
| auto rhsBool = | ||
| tosa::tosaCastTensorToType(rewriter, rhsTensor, resultTy).value(); |
There was a problem hiding this comment.
These casts can be done before the isBitwiseOp check instead of 753-756.
Change-Id: I79424d7fa61f0788a5d9ef055312971ca5d98fbd Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
Change-Id: Ided255c7522625eeda323f9ffd4febe8478873d5 Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
TOSA bitwise_* ops do not accept i1 tensors. When aten.bitwise_* is applied to bool tensors, lower to tosa.logical_and/or/xor instead. Add a conversion test for bool bitwise_and.
Change-Id: I98e0ae72f69c926abe97c036489bf2e39ba6f88f