Skip to content

Commit c5e67b8

Browse files
authored
[mlir] [tensor] Crash in getPackOpResultTypeShape for tensor.pack/unpack ops. (llvm#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 invalid memory access during iterating over `innerDimsPos` within `getPackOpResultTypeShape`. This crash is also causing the following tests to fail: ``` MLIR :: Dialect/Linalg/canonicalize.mlir MLIR :: Dialect/Linalg/data-layout-propagation.mlir MLIR :: Dialect/Linalg/generalize-tensor-pack-tile.mlir MLIR :: Dialect/Linalg/generalize-tensor-pack.mlir MLIR :: Dialect/Linalg/generalize-tensor-unpack-tile.mlir MLIR :: Dialect/Linalg/generalize-tensor-unpack.mlir MLIR :: Dialect/Linalg/transform-lower-pack.mlir MLIR :: Dialect/Linalg/transform-op-fuse.mlir MLIR :: Dialect/Linalg/transform-op-pack.mlir MLIR :: Dialect/Linalg/transform-pack-greedily.mlir MLIR :: Dialect/Tensor/canonicalize.mlir MLIR :: Dialect/Tensor/fold-into-pack-and-unpack.mlir MLIR :: Dialect/Tensor/invalid.mlir MLIR :: Dialect/Tensor/ops.mlir MLIR :: Dialect/Tensor/simplify-pack-unpack.mlir MLIR :: Dialect/Tensor/tiling.mlir ```
1 parent 561c42d commit c5e67b8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mlir/lib/Dialect/Tensor/IR/TensorOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,7 +3963,7 @@ static SmallVector<int64_t> getPackOpResultTypeShape(
39633963
ArrayRef<int64_t> sourceShape, ArrayRef<int64_t> innerTileSizes,
39643964
ArrayRef<int64_t> innerDimsPos, ArrayRef<int64_t> outerDimsPerm) {
39653965
SmallVector<int64_t> resultShape = llvm::to_vector(sourceShape);
3966-
for (auto tiledDim : llvm::enumerate(innerDimsPos)) {
3966+
for (auto tiledDim : llvm::enumerate(llvm::to_vector(innerDimsPos))) {
39673967
if (ShapedType::isDynamic(resultShape[tiledDim.value()]))
39683968
continue;
39693969
if (ShapedType::isDynamic(innerTileSizes[tiledDim.index()])) {
@@ -3992,7 +3992,7 @@ SmallVector<OpFoldResult> PackOp::getResultShape(
39923992
AffineExpr s0, s1;
39933993
bindSymbols(builder.getContext(), s0, s1);
39943994
AffineExpr ceilDivExpr = s0.ceilDiv(s1);
3995-
for (auto tiledDim : llvm::enumerate(innerDimsPos)) {
3995+
for (auto tiledDim : llvm::enumerate(llvm::to_vector(innerDimsPos))) {
39963996
resultDims[tiledDim.value()] = affine::makeComposedFoldedAffineApply(
39973997
builder, loc, ceilDivExpr,
39983998
{resultDims[tiledDim.value()], innerTileSizes[tiledDim.index()]});

0 commit comments

Comments
 (0)