Skip to content

Commit 4ef1770

Browse files
committed
[mlir][tosa] Table did not apply offset before extract on i8 input
Lowering to table was incorrect as it did not apply a 128 offset before extracting the value from the table. Fixed and correct tensor length on input table. Reviewed By: NatashaKnk Differential Revision: https://reviews.llvm.org/D108436
1 parent a9cff97 commit 4ef1770

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,9 @@ class TableConverter : public OpRewritePattern<tosa::TableOp> {
24362436
resultElementTy.isInteger(8)) {
24372437
Value index = rewriter.create<IndexCastOp>(loc, rewriter.getIndexType(),
24382438
inputValue);
2439+
Value offset = rewriter.create<ConstantIndexOp>(loc, 128);
2440+
index = rewriter.create<AddIOp>(loc, rewriter.getIndexType(), index,
2441+
offset);
24392442
Value extract =
24402443
rewriter.create<tensor::ExtractOp>(loc, table, ValueRange{index});
24412444
rewriter.create<linalg::YieldOp>(loc, extract);

mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,17 +1101,21 @@ func @gather_int(%arg0: tensor<2x3x2xi32>, %arg1: tensor<2x3xi32>) -> () {
11011101
// -----
11021102

11031103
// CHECK-LABEL: @table8
1104-
func @table8(%arg0: tensor<6xi8>, %arg1: tensor<513xi8>) -> () {
1104+
func @table8(%arg0: tensor<6xi8>, %arg1: tensor<512xi8>) -> () {
11051105
// CHECK: %[[INIT:.+]] = linalg.init_tensor [6]
11061106
// CHECK: %[[GENERIC:.+]] = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel"]} ins(%arg0 : tensor<6xi8>) outs(%[[INIT]] : tensor<6xi8>)
11071107
// CHECK: ^bb0(%[[ARG_IN:.+]]: i8, %[[ARG_INIT:.+]]: i8)
11081108
// CHECK: %[[CAST:.+]] = index_cast %[[ARG_IN]]
1109-
// CHECK: %[[EXTRACT:.+]] = tensor.extract %arg1[%[[CAST]]]
1109+
// CHECK: %[[OFFSET:.+]] = constant 128
1110+
// CHECK: %[[ADD:.+]] = addi %[[CAST]], %[[OFFSET]]
1111+
// CHECK: %[[EXTRACT:.+]] = tensor.extract %arg1[%[[ADD]]]
11101112
// CHECK: linalg.yield %[[EXTRACT]]
1111-
%0 = "tosa.table"(%arg0, %arg1) : (tensor<6xi8>, tensor<513xi8>) -> (tensor<6xi8>)
1113+
%0 = "tosa.table"(%arg0, %arg1) : (tensor<6xi8>, tensor<512xi8>) -> (tensor<6xi8>)
11121114
return
11131115
}
11141116

1117+
// -----
1118+
11151119
// CHECK-LABEL: @table16
11161120
func @table16(%arg0: tensor<6xi16>, %arg1: tensor<513xi16>) -> () {
11171121
// CHECK: %[[INIT:.+]] = linalg.init_tensor [6]

0 commit comments

Comments
 (0)