[Mlir-commits] [mlir] 6375a85 - [mlir][tosa] Fix indexing in TosaToTensor (#140906)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu May 22 07:08:09 PDT 2025
Author: Shay Kleiman
Date: 2025-05-22T17:08:05+03:00
New Revision: 6375a8508e836a49ffcee306b57166a39a950afe
URL: https://github.com/llvm/llvm-project/commit/6375a8508e836a49ffcee306b57166a39a950afe
DIFF: https://github.com/llvm/llvm-project/commit/6375a8508e836a49ffcee306b57166a39a950afe.diff
LOG: [mlir][tosa] Fix indexing in TosaToTensor (#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 <shay.kleiman at mobileye.com>
Added:
Modified:
mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
mlir/test/Conversion/TosaToTensor/tosa-to-tensor.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp b/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
index 5f23a33049f87..615c7ca1cfd15 100644
--- a/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
+++ b/mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp
@@ -362,7 +362,8 @@ class PadConverter : public OpConversionPattern<tosa::PadOp> {
// Setup the default constantAttr.
Value padConstant = rewriter.createOrFold<tensor::ExtractOp>(
- loc, padOp.getPadConst(), ValueRange({}));
+ loc, padOp.getPadConst(),
+ ValueRange({rewriter.create<arith::ConstantIndexOp>(loc, 0)}));
if (!padConstant) {
return rewriter.notifyMatchFailure(
diff --git a/mlir/test/Conversion/TosaToTensor/tosa-to-tensor.mlir b/mlir/test/Conversion/TosaToTensor/tosa-to-tensor.mlir
index b19cd2115891c..0a276e2a5c3d2 100644
--- a/mlir/test/Conversion/TosaToTensor/tosa-to-tensor.mlir
+++ b/mlir/test/Conversion/TosaToTensor/tosa-to-tensor.mlir
@@ -700,3 +700,25 @@ func.func @concat_non_axis_dyn_mixed(%arg0: tensor<?x1xf32>, %arg1: tensor<?x1xf
%0 = "tosa.concat"(%arg0, %arg1, %arg2) <{axis = 1 : i32}> : (tensor<?x1xf32>, tensor<?x1xf32>, tensor<?x1xf32>) -> tensor<5x3xf32>
return
}
+
+// -----
+
+// CHECK-LABEL: func @pad_variable_pad_const
+// CHECK-SAME: (%[[ARG0_SSA:.*]]: tensor<2x2xi32>, %[[PAD_INPUT_TENSOR_SSA:.*]]: tensor<1xi32>)
+func.func @pad_variable_pad_const(%arg0: tensor<2x2xi32>, %pad_input_tensor: tensor<1xi32>) -> tensor<4x5xi32> {
+ // CHECK-DAG: %[[C0_INDEX:.*]] = arith.constant 0 : index
+ // CHECK-DAG: %[[EXTRACTED_PAD_VAL:.*]] = tensor.extract %[[PAD_INPUT_TENSOR_SSA]][%[[C0_INDEX]]] : tensor<1xi32>
+
+ // CHECK: %[[C_PAD_LOW_0:.*]] = arith.constant 1 : index
+ // CHECK: %[[C_PAD_HIGH_0:.*]] = arith.constant 1 : index
+ // CHECK: %[[C_PAD_LOW_1:.*]] = arith.constant 0 : index
+ // CHECK: %[[C_PAD_HIGH_1:.*]] = arith.constant 3 : index
+
+ // CHECK: %{{.*}} = tensor.pad %[[ARG0_SSA]] low[%[[C_PAD_LOW_0]], %[[C_PAD_LOW_1]]] high[%[[C_PAD_HIGH_0]], %[[C_PAD_HIGH_1]]] {
+ // CHECK: tensor.yield %[[EXTRACTED_PAD_VAL]] : i32
+ // CHECK: } : tensor<2x2xi32> to tensor<4x5xi32>
+
+ %padding_indices = tosa.const_shape {values = dense<[1, 1, 0, 3]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %result = "tosa.pad"(%arg0, %padding_indices, %pad_input_tensor) : (tensor<2x2xi32>, !tosa.shape<4>, tensor<1xi32>) -> tensor<4x5xi32>
+ return %result : tensor<4x5xi32>
+}
More information about the Mlir-commits
mailing list