Skip to content

Commit e4a48da

Browse files
abatterytensorflower-gardener
authored andcommitted
Add new pattern matching rules for TFL Broadcastable ops, which have high dimenion inputs.
- Low dimensions <= 4, for example, should avoid adding BroadcastTo op as usual, which means we need to lower broadcast-able ops as before without BroadcastTo op and lower the BroadcastTo op to the hardware accelerator supported ops as well. - This explicit BroadcastTo op needs to be inserted only when a higher dimension is needed, which will unlock the new opportunity. - There are the broadcast-able 20 TFLite ops (about 15 % of TFLite op set) as the followings: Comparison: LessEqual, GreaterEqual, NotEqual, Greater, Less, Equal (up to four dim.) Activation: PRelu (up to four dim.) Arithmetic: Add, Mul, Div, Sub, FloorDiv, FloorMod, Pow, Maximum, Minimum, SquaredDifference (up to four or five dim.) Dimension: SelectV2 (up to four dim.), BroadcastTo (supported via lowering) PiperOrigin-RevId: 322763761 Change-Id: I637e12f05ac8d4b9e61c1355d3bc00dc8ffe4756
1 parent bd6b557 commit e4a48da

6 files changed

Lines changed: 380 additions & 43 deletions

File tree

‎tensorflow/compiler/mlir/lite/ir/tfl_ops.cc‎

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,10 @@ bool IsI64Type(Type element_type) {
147147
bool VerifyAddOpShapeConstraints(AddOp op) {
148148
auto element_type = getElementTypeOrSelf(op.output().getType());
149149

150-
// Allows F32, QI8, and QUI8 outputs when the operands have valid shapes,
150+
// Allows F32, QI8, QUI8 and I32 outputs when the operands have valid shapes,
151151
// which are broadcastable shapes up to five dimension or have same shapes.
152152
if (element_type.isF32() || IsQI8Type(element_type) ||
153-
IsQUI8Type(element_type)) {
154-
return VerifyOperandsHaveSameShapesOrBroadcastableShape(
155-
/*op=*/op.getOperation(), /*indices=*/ArrayRef<unsigned>{0, 1},
156-
/*max_bcast_rank=*/5);
157-
}
158-
159-
// Allows I32 output when the operands have valid shapes, which are
160-
// broadcastable shapes up to four dimension or have same shapes.
161-
if (IsI32Type(element_type)) {
153+
IsQUI8Type(element_type) || IsI32Type(element_type)) {
162154
return VerifyOperandsHaveSameShapesOrBroadcastableShape(
163155
/*op=*/op.getOperation(), /*indices=*/ArrayRef<unsigned>{0, 1},
164156
/*max_bcast_rank=*/4);
@@ -210,20 +202,13 @@ bool VerifyMulOpShapeConstraints(MulOp op) {
210202
}
211203
return VerifyOperandsHaveSameShapesOrBroadcastableShape(
212204
/*op=*/op.getOperation(), /*indices=*/ArrayRef<unsigned>{0, 1},
213-
/*max_bcast_rank=*/5);
214-
}
215-
216-
// Allows F32 output when the operands have valid shapes, which are
217-
// broadcastable shapes up to five dimension or have same shapes.
218-
if (element_type.isF32()) {
219-
return VerifyOperandsHaveSameShapesOrBroadcastableShape(
220-
/*op=*/op.getOperation(), /*indices=*/ArrayRef<unsigned>{0, 1},
221-
/*max_bcast_rank=*/5);
205+
/*max_bcast_rank=*/4);
222206
}
223207

224-
// Allows I32 and QI16 outputs when the operands have valid shapes, which are
225-
// broadcastable shapes up to four dimension or have same shapes.
226-
if (IsI32Type(element_type) || IsQI16Type(element_type)) {
208+
// Allows I32, QI16 and F32 outputs when the operands have valid shapes, which
209+
// are broadcastable shapes up to four dimension or have same shapes.
210+
if (IsI32Type(element_type) || IsQI16Type(element_type) ||
211+
element_type.isF32()) {
227212
return VerifyOperandsHaveSameShapesOrBroadcastableShape(
228213
/*op=*/op.getOperation(), /*indices=*/ArrayRef<unsigned>{0, 1},
229214
/*max_bcast_rank=*/4);

‎tensorflow/compiler/mlir/lite/tests/legalize-tf.mlir‎

Lines changed: 173 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ func @testAddHighDimsHaveSameShape(%arg0: tensor<1x2x3x4x5x6x7x8xi32>, %arg1: te
2525
return %0 : tensor<1x2x3x4x5x6x7x8xi32>
2626
}
2727

28-
// CHECK-LABEL: testAddTooHighBroadcastableDims
29-
func @testAddTooHighBroadcastableDims(%arg0: tensor<1x2x3x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
30-
// expected-error @+1 {{'tfl.add' op failed to verify that operand #0 and operand #1 have the same shape or broadcastable shapes within the rank 4}}
31-
%0 = "tf.Add"(%arg0, %arg1) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
32-
return %0 : tensor<1x2x3x4x5x6xi32>
33-
}
34-
3528
func @LeakyRelu(%arg0: tensor<1xf32>) -> tensor<1xf32> {
3629
%2 = "tf.LeakyRelu"(%arg0) {alpha = 0.1 : f32} : (tensor<1xf32>) -> tensor<1xf32>
3730
return %2: tensor<1xf32>
@@ -1530,7 +1523,11 @@ func @select_v2_with_6d_broadcasting(%arg0: tensor<1x1x1x1x3x1xi1>, %arg1 : tens
15301523
%0 = "tf.SelectV2"(%arg0, %arg1, %arg2): (tensor<1x1x1x1x3x1xi1>, tensor<1x1x1x1x1x4xf32>, tensor<1x1x1x2x1x1xf32>) -> tensor<1x1x1x2x3x4xf32>
15311524
return %0 : tensor<1x1x1x2x3x4xf32>
15321525
// CHECK-LABEL: select_v2_with_6d_broadcasting
1533-
// CHECK: "tf.SelectV2"(%arg0, %arg1, %arg2)
1526+
// CHECK: [[CST:%.*]] = constant dense<[1, 1, 1, 2, 3, 4]> : tensor<6xi64>
1527+
// CHECK: [[BCT:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1528+
// CHECK: [[BCT_0:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1529+
// CHECK: [[BCT_1:%.*]] = "tfl.broadcast_to"(%arg2, [[CST]])
1530+
// CHECK: "tfl.select"([[BCT]], [[BCT_0]], [[BCT_1]])
15341531
}
15351532

15361533
// -----
@@ -1540,7 +1537,9 @@ func @maximum_with_6d_broadcasting(%arg0: tensor<1x1x1x1x8x16xf32>, %arg1: tenso
15401537
return %0 : tensor<1x1x1x1x8x16xf32>
15411538

15421539
// CHECK-LABEL: maximum_with_6d_broadcasting
1543-
// CHECK: "tf.Maximum"(%arg0, %arg1)
1540+
// CHECK: [[CST:%.*]] = constant dense<[1, 1, 1, 1, 8, 16]> : tensor<6xi64>
1541+
// CHECK: [[BCT:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1542+
// CHECK: "tfl.maximum"(%arg0, [[BCT]])
15441543
}
15451544

15461545
// -----
@@ -1549,5 +1548,169 @@ func @add_with_int32_5d_inputs(%arg0: tensor<1x1x1x3x1xi32>, %arg1 : tensor<1x1x
15491548
%0 = "tf.Add"(%arg0, %arg1): (tensor<1x1x1x3x1xi32>, tensor<1x1x1x1x4xi32>) -> tensor<1x1x1x3x4xi32>
15501549
return %0 : tensor<1x1x1x3x4xi32>
15511550
// CHECK-LABEL: add_with_int32_5d_inputs
1552-
// CHECK: "tf.Add"(%arg0, %arg1)
1551+
// CHECK: [[CST:%.*]] = constant dense<[1, 1, 1, 3, 4]> : tensor<5xi64>
1552+
// CHECK: [[BCT:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1553+
// CHECK: [[BCT_0:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1554+
// CHECK: tfl.add [[BCT]], [[BCT_0]]
1555+
}
1556+
1557+
// CHECK-LABEL: testAddWithBroadcastToOps
1558+
func @testAddWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1559+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1560+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1561+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1562+
// CHECK: tfl.add [[BCAST]], [[BCAST_1]] {fused_activation_function = "NONE"} : tensor<1x2x3x4x5x6xi32>
1563+
%0 = "tf.Add"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1564+
return %0 : tensor<1x2x3x4x5x6xi32>
1565+
}
1566+
1567+
// CHECK-LABEL: testSubWithBroadcastToOps
1568+
func @testSubWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1569+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1570+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1571+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1572+
// CHECK: tfl.sub [[BCAST]], [[BCAST_1]] {fused_activation_function = "NONE"} : tensor<1x2x3x4x5x6xi32>
1573+
%0 = "tf.Sub"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1574+
return %0 : tensor<1x2x3x4x5x6xi32>
1575+
}
1576+
1577+
// CHECK-LABEL: testMulWithBroadcastToOps
1578+
func @testMulWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1579+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1580+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1581+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1582+
// CHECK: tfl.mul [[BCAST]], [[BCAST_1]] {fused_activation_function = "NONE"} : tensor<1x2x3x4x5x6xi32>
1583+
%0 = "tf.Mul"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1584+
return %0 : tensor<1x2x3x4x5x6xi32>
1585+
}
1586+
1587+
// CHECK-LABEL: testDivWithBroadcastToOps
1588+
func @testDivWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1589+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1590+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1591+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1592+
// CHECK: tfl.div [[BCAST]], [[BCAST_1]] {fused_activation_function = "NONE"} : tensor<1x2x3x4x5x6xi32>
1593+
%0 = "tf.Div"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1594+
return %0 : tensor<1x2x3x4x5x6xi32>
1595+
}
1596+
1597+
// CHECK-LABEL: testFloorDivWithBroadcastToOps
1598+
func @testFloorDivWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1599+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1600+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1601+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1602+
// CHECK: tfl.floor_div [[BCAST]], [[BCAST_1]] : tensor<1x2x3x4x5x6xi32>
1603+
%0 = "tf.FloorDiv"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1604+
return %0 : tensor<1x2x3x4x5x6xi32>
1605+
}
1606+
1607+
// CHECK-LABEL: testFloorModWithBroadcastToOps
1608+
func @testFloorModWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1609+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1610+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1611+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1612+
// CHECK: "tfl.floor_mod"([[BCAST]], [[BCAST_1]]) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x6xi32>) -> tensor<1x2x3x4x5x6xi32>
1613+
%0 = "tf.FloorMod"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1614+
return %0 : tensor<1x2x3x4x5x6xi32>
1615+
}
1616+
1617+
// CHECK-LABEL: testPowWithBroadcastToOps
1618+
func @testPowWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1619+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1620+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1621+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1622+
// CHECK: tfl.pow [[BCAST]], [[BCAST_1]] : tensor<1x2x3x4x5x6xi32>
1623+
%0 = "tf.Pow"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1624+
return %0 : tensor<1x2x3x4x5x6xi32>
1625+
}
1626+
1627+
// CHECK-LABEL: testMaximumWithBroadcastToOps
1628+
func @testMaximumWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1629+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1630+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1631+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1632+
// CHECK: "tfl.maximum"([[BCAST]], [[BCAST_1]]) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x6xi32>) -> tensor<1x2x3x4x5x6xi32>
1633+
%0 = "tf.Maximum"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1634+
return %0 : tensor<1x2x3x4x5x6xi32>
1635+
}
1636+
1637+
// CHECK-LABEL: testMinimumWithBroadcastToOps
1638+
func @testMinimumWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1639+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1640+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1641+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1642+
// CHECK: "tfl.minimum"([[BCAST]], [[BCAST_1]]) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x6xi32>) -> tensor<1x2x3x4x5x6xi32>
1643+
%0 = "tf.Minimum"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1644+
return %0 : tensor<1x2x3x4x5x6xi32>
1645+
}
1646+
1647+
// CHECK-LABEL: testSelectV2WithBroadcastToOps
1648+
func @testSelectV2WithBroadcastToOps(%arg0: tensor<1x2x1x4x1x6xi1>, %arg1: tensor<1x2x3x4x1x1xi32>, %arg2: tensor<1x2x1x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32> {
1649+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1650+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1651+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1652+
// CHECK: [[BCAST_2:%.*]] = "tfl.broadcast_to"(%arg2, [[CST]])
1653+
// CHECK: "tfl.select"([[BCAST]], [[BCAST_1]], [[BCAST_2]])
1654+
%0 = "tf.SelectV2"(%arg0, %arg1, %arg2) : (tensor<1x2x1x4x1x6xi1>, tensor<1x2x3x4x1x1xi32>, tensor<1x2x1x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi32>
1655+
return %0 : tensor<1x2x3x4x5x6xi32>
1656+
}
1657+
1658+
// CHECK-LABEL: testLessEqualWithBroadcastToOps
1659+
func @testLessEqualWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1> {
1660+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1661+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1662+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1663+
// CHECK: "tfl.less_equal"([[BCAST]], [[BCAST_1]]) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x6xi32>) -> tensor<1x2x3x4x5x6xi1>
1664+
%0 = "tf.LessEqual"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1>
1665+
return %0 : tensor<1x2x3x4x5x6xi1>
1666+
}
1667+
1668+
// CHECK-LABEL: testGreaterEqualWithBroadcastToOps
1669+
func @testGreaterEqualWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1> {
1670+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1671+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1672+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1673+
// CHECK: "tfl.greater_equal"([[BCAST]], [[BCAST_1]]) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x6xi32>) -> tensor<1x2x3x4x5x6xi1>
1674+
%0 = "tf.GreaterEqual"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1>
1675+
return %0 : tensor<1x2x3x4x5x6xi1>
1676+
}
1677+
1678+
// CHECK-LABEL: testEqualWithBroadcastToOps
1679+
func @testEqualWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1> {
1680+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1681+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1682+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1683+
// CHECK: "tfl.equal"([[BCAST]], [[BCAST_1]]) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x6xi32>) -> tensor<1x2x3x4x5x6xi1>
1684+
%0 = "tf.Equal"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1>
1685+
return %0 : tensor<1x2x3x4x5x6xi1>
1686+
}
1687+
1688+
// CHECK-LABEL: testNotEqualWithBroadcastToOps
1689+
func @testNotEqualWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1> {
1690+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1691+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1692+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1693+
// CHECK: "tfl.not_equal"([[BCAST]], [[BCAST_1]]) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x6xi32>) -> tensor<1x2x3x4x5x6xi1>
1694+
%0 = "tf.NotEqual"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1>
1695+
return %0 : tensor<1x2x3x4x5x6xi1>
1696+
}
1697+
1698+
// CHECK-LABEL: testLessWithBroadcastToOps
1699+
func @testLessWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1> {
1700+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1701+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1702+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1703+
// CHECK: "tfl.less"([[BCAST]], [[BCAST_1]]) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x6xi32>) -> tensor<1x2x3x4x5x6xi1>
1704+
%0 = "tf.Less"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1>
1705+
return %0 : tensor<1x2x3x4x5x6xi1>
1706+
}
1707+
1708+
// CHECK-LABEL: testGreaterWithBroadcastToOps
1709+
func @testGreaterWithBroadcastToOps(%arg0: tensor<1x2x1x4x5x6xi32>, %arg1: tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1> {
1710+
// CHECK: [[CST:%.*]] = constant dense<[1, 2, 3, 4, 5, 6]> : tensor<6xi64>
1711+
// CHECK: [[BCAST:%.*]] = "tfl.broadcast_to"(%arg0, [[CST]])
1712+
// CHECK: [[BCAST_1:%.*]] = "tfl.broadcast_to"(%arg1, [[CST]])
1713+
// CHECK: "tfl.greater"([[BCAST]], [[BCAST_1]]) : (tensor<1x2x3x4x5x6xi32>, tensor<1x2x3x4x5x6xi32>) -> tensor<1x2x3x4x5x6xi1>
1714+
%0 = "tf.Greater"(%arg0, %arg1) : (tensor<1x2x1x4x5x6xi32>, tensor<1x2x3x4x5x1xi32>) -> tensor<1x2x3x4x5x6xi1>
1715+
return %0 : tensor<1x2x3x4x5x6xi1>
15531716
}

‎tensorflow/compiler/mlir/lite/transforms/legalize_patterns.td‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def LegalizeAddv2 : Pat<(TF_AddV2Op $lhs, $rhs),
256256
(TFL_AddOp $lhs, $rhs, TFL_AF_None)>;
257257
def LegalizeBiasAdd : Pat<
258258
(TF_BiasAddOp F32Tensor:$l, F32Tensor:$r, IsDataFormatNHWC:$data_format),
259-
(TFL_AddOp $l, $r, TFL_AF_None)>;
259+
(TF_AddV2Op $l, $r)>;
260260
def LegalizeSub : Pat<(TF_SubOp $lhs, $rhs),
261261
(TFL_SubOp $lhs, $rhs, TFL_AF_None)>;
262262
def LegalizeMul : Pat<(TF_MulOp $lhs, $rhs),

0 commit comments

Comments
 (0)