[Mlir-commits] [mlir] [BugFix] : Crash in getPackOpResultTypeShape for tensor.pack/unpack ops. (PR #90641)
Sayan Saha
llvmlistbot at llvm.org
Tue Apr 30 11:05:52 PDT 2024
https://github.com/sahas3 created https://github.com/llvm/llvm-project/pull/90641
Windows build of `mlir` with Visual Studio (19.36.32538 for x64) using with the following command:
`cmake.exe -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=mlir -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=1 -DLLVM_TARGETS_TO_BUILD=host llvm`
is leading to a crash when calling canonicalization on `tensor.pack`/`tensor.unpack` ops `mlir-opt --canonicalize input.mlir` where the `input.mlir` is as follows (this is taken from one of the filecheck tests for `tensor.pack`):
```
func.func @pack_unpack(%arg0: tensor<128x256xf32>) -> tensor<128x256xf32> {
%pack_dest = tensor.empty() : tensor<8x16x8x32xf32>
%unpack_dest = tensor.empty() : tensor<128x256xf32>
%tp = tensor.pack %arg0 outer_dims_perm = [1, 0] inner_dims_pos = [0, 1] inner_tiles = [8, 32] into %pack_dest : tensor<128x256xf32> -> tensor<8x16x8x32xf32>
%tup = tensor.unpack %tp outer_dims_perm = [1, 0] inner_dims_pos = [0, 1] inner_tiles = [8, 32] into %unpack_dest : tensor<8x16x8x32xf32> -> tensor<128x256xf32>
return %tup : tensor<128x256xf32>
}
```
The crash is seemingly coming from accessing `innerDimsPos` within `getPackOpResultTypeShape`.
This crash is also causing the following tests to fail:
>From 7bff313abcf96b32643ed91d62d5c4a0de7e80e0 Mon Sep 17 00:00:00 2001
From: Sayan Saha <sayans at mathworks.com>
Date: Tue, 30 Apr 2024 11:01:42 -0400
Subject: [PATCH] [BugFix] : Crash in getPackOpResultTypeShape for
tensor.pack/unpack ops.
---
mlir/lib/Dialect/Tensor/IR/TensorOps.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index 5029ed4aa0387a..425ebbe7f56017 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -3880,7 +3880,7 @@ static SmallVector<int64_t> getPackOpResultTypeShape(
ArrayRef<int64_t> sourceShape, ArrayRef<int64_t> innerTileSizes,
ArrayRef<int64_t> innerDimsPos, ArrayRef<int64_t> outerDimsPerm) {
SmallVector<int64_t> resultShape = llvm::to_vector(sourceShape);
- for (auto tiledDim : llvm::enumerate(innerDimsPos)) {
+ for (auto tiledDim : llvm::enumerate(llvm::to_vector(innerDimsPos))) {
if (ShapedType::isDynamic(resultShape[tiledDim.value()]))
continue;
if (ShapedType::isDynamic(innerTileSizes[tiledDim.index()])) {
@@ -3909,7 +3909,7 @@ SmallVector<OpFoldResult> PackOp::getResultShape(
AffineExpr s0, s1;
bindSymbols(builder.getContext(), s0, s1);
AffineExpr ceilDivExpr = s0.ceilDiv(s1);
- for (auto tiledDim : llvm::enumerate(innerDimsPos)) {
+ for (auto tiledDim : llvm::enumerate(llvm::to_vector(innerDimsPos))) {
resultDims[tiledDim.value()] = affine::makeComposedFoldedAffineApply(
builder, loc, ceilDivExpr,
{resultDims[tiledDim.value()], innerTileSizes[tiledDim.index()]});
More information about the Mlir-commits
mailing list