Skip to content

Commit 5a7f861

Browse files
shay-klShay Kleiman
authored andcommitted
[mlir][tosa] Fix indexing in TosaToTensor (llvm#140906)
Changed the indexing used in the extractOp from one that is intended for 0d tensors to one that is intended for 1d tensors. --------- Co-authored-by: Shay Kleiman <[email protected]>
1 parent 9677bfc commit 5a7f861

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ class PadConverter : public OpConversionPattern<tosa::PadOp> {
362362
// Setup the default constantAttr.
363363

364364
Value padConstant = rewriter.createOrFold<tensor::ExtractOp>(
365-
loc, padOp.getPadConst(), ValueRange({}));
365+
loc, padOp.getPadConst(),
366+
ValueRange({rewriter.create<arith::ConstantIndexOp>(loc, 0)}));
366367

367368
if (!padConstant) {
368369
return rewriter.notifyMatchFailure(

mlir/test/Conversion/TosaToTensor/tosa-to-tensor.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,25 @@ func.func @concat_non_axis_dyn_mixed(%arg0: tensor<?x1xf32>, %arg1: tensor<?x1xf
700700
%0 = "tosa.concat"(%arg0, %arg1, %arg2) <{axis = 1 : i32}> : (tensor<?x1xf32>, tensor<?x1xf32>, tensor<?x1xf32>) -> tensor<5x3xf32>
701701
return
702702
}
703+
704+
// -----
705+
706+
// CHECK-LABEL: func @pad_variable_pad_const
707+
// CHECK-SAME: (%[[ARG0_SSA:.*]]: tensor<2x2xi32>, %[[PAD_INPUT_TENSOR_SSA:.*]]: tensor<1xi32>)
708+
func.func @pad_variable_pad_const(%arg0: tensor<2x2xi32>, %pad_input_tensor: tensor<1xi32>) -> tensor<4x5xi32> {
709+
// CHECK-DAG: %[[C0_INDEX:.*]] = arith.constant 0 : index
710+
// CHECK-DAG: %[[EXTRACTED_PAD_VAL:.*]] = tensor.extract %[[PAD_INPUT_TENSOR_SSA]][%[[C0_INDEX]]] : tensor<1xi32>
711+
712+
// CHECK: %[[C_PAD_LOW_0:.*]] = arith.constant 1 : index
713+
// CHECK: %[[C_PAD_HIGH_0:.*]] = arith.constant 1 : index
714+
// CHECK: %[[C_PAD_LOW_1:.*]] = arith.constant 0 : index
715+
// CHECK: %[[C_PAD_HIGH_1:.*]] = arith.constant 3 : index
716+
717+
// CHECK: %{{.*}} = tensor.pad %[[ARG0_SSA]] low[%[[C_PAD_LOW_0]], %[[C_PAD_LOW_1]]] high[%[[C_PAD_HIGH_0]], %[[C_PAD_HIGH_1]]] {
718+
// CHECK: tensor.yield %[[EXTRACTED_PAD_VAL]] : i32
719+
// CHECK: } : tensor<2x2xi32> to tensor<4x5xi32>
720+
721+
%padding_indices = tosa.const_shape {values = dense<[1, 1, 0, 3]> : tensor<4xindex>} : () -> !tosa.shape<4>
722+
%result = "tosa.pad"(%arg0, %padding_indices, %pad_input_tensor) : (tensor<2x2xi32>, !tosa.shape<4>, tensor<1xi32>) -> tensor<4x5xi32>
723+
return %result : tensor<4x5xi32>
724+
}

0 commit comments

Comments
 (0)