llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.25k stars 11.67k forks source link

[mlir][transform] transform.structured.tile_using_for crashes on invalid number of results #93693

Open Groverkss opened 4 months ago

Groverkss commented 4 months ago

transform.structured.tile_using_for crashes when the number of results does not match the number of loops produced. This should instead produce an error message and exit gracefully.

Reproducer:

func.func @fold_extract_slice(
  %arg0 : tensor<?x128xf32>, %arg1 : tensor<?x42xf32>, %arg2 : tensor<?x42x?xf32>) -> tensor<?x42xf32> {

  %c0 = arith.constant 0 : index

  %0 = tensor.dim %arg1, %c0 : tensor<?x42xf32>
  %1 = tensor.extract_slice %arg0[3, 4] [%0, 42] [1, 1] : tensor<?x128xf32> to tensor<?x42xf32>

  %2 = linalg.generic
    {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1)>,
                      affine_map<(d0, d1, d2) -> (d0, d1, d2)>,
                      affine_map<(d0, d1, d2) -> (d0, d1)>],
     iterator_types = ["parallel", "parallel", "parallel"]}
    ins(%1, %arg2 : tensor<?x42xf32>, tensor<?x42x?xf32>)
    outs(%arg1 : tensor<?x42xf32>) {
    ^bb0(%arg3 : f32, %arg4: f32, %arg5: f32):
      %5 = arith.addf %arg3, %arg5 : f32
      linalg.yield %5 : f32
    } -> tensor<?x42xf32>
  return %2 : tensor<?x42xf32>
}

module attributes {transform.with_named_sequence} {
  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
    %0 = transform.structured.match ops{["linalg.generic"]} in %arg1 : (!transform.any_op) -> !transform.any_op
    %1, %loops:2 = transform.structured.tile_using_for %0 tile_sizes [2, 3, 4] : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op)
    transform.yield
  }
}
mlir-opt -transform-interpreter %s

Crash Report:

mlir-opt: /home/kunwar/llvm-project/llvm/include/llvm/ADT/SmallVector.h:304: llvm::SmallVectorTemplateCommon::reference llvm::SmallVectorTemplateCommon<llvm::SmallVector<mlir::Operation *, 4>>::operator[](llvm::SmallVectorTemplateCommon::size_type) [T = llvm::SmallVector<mlir::Operation *, 4>]: Assertion `idx < size()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: ./bin/mlir-opt -transform-interpreter t.mlir
 #0 0x000063035b085b5d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/kunwar/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11
 #1 0x000063035b08604b PrintStackTraceSignalHandler(void*) /home/kunwar/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x000063035b084076 llvm::sys::RunSignalHandlers() /home/kunwar/llvm-project/llvm/lib/Support/Signals.cpp:105:5
 #3 0x000063035b086865 SignalHandler(int) /home/kunwar/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007925efc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007925efc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #6 0x00007925efc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #7 0x00007925efc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #8 0x00007925efc2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #9 0x00007925efc39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x000063035c9ab109 llvm::SmallVectorTemplateCommon<llvm::SmallVector<mlir::Operation*, 4u>, void>::operator[](unsigned long) /home/kunwar/llvm-project/llvm/include/llvm/ADT/SmallVector.h:0:5
#11 0x000063035c93258a mlir::transform::TileUsingForOp::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp:2801:7
#12 0x000063035c8ab721 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::TileUsingForOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:477:56
#13 0x0000630364b08a4e mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:61:14
#14 0x0000630364b0822f mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:954:48
#15 0x000063035f34d8a1 applySequenceBlock(mlir::Block&, mlir::transform::FailurePropagationMode, mlir::transform::TransformState&, mlir::transform::TransformResults&) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:1722:15
#16 0x000063035f35040b mlir::transform::NamedSequenceOp::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:2087:10
#17 0x000063035f2e08a1 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::NamedSequenceOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:477:56
#18 0x0000630364b08a4e mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:61:14
#19 0x0000630364b0822f mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:954:48
#20 0x0000630364b0ee4d mlir::transform::applyTransforms(mlir::Operation*, mlir::transform::TransformOpInterface, mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>> const&, mlir::transform::TransformOptions const&, bool) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:2005:42
#21 0x000063035f3e6d4e mlir::transform::applyTransformNamedSequence(mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>>, mlir::transform::TransformOpInterface, mlir::ModuleOp, mlir::transform::TransformOptions const&) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp:234:10
#22 0x000063035f3dda5c (anonymous namespace)::InterpreterPass::runOnOperation() /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Transforms/InterpreterPass.cpp:147:16
#23 0x0000630360bdcddb mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7::operator()() const /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:0:17
#24 0x0000630360bdcd75 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7>(long) /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#25 0x000063035af9db69 llvm::function_ref<void ()>::operator()() const /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#26 0x0000630360bdff1d void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /home/kunwar/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#27 0x0000630360bd82a3 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:533:17
#28 0x0000630360bd8854 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:593:16
#29 0x0000630360bda33c mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:904:10
#30 0x0000630360bda25f mlir::PassManager::run(mlir::Operation*) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:884:60
#31 0x0000630360bce1e2 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:409:17
#32 0x0000630360bcde19 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:474:12
#33 0x0000630360bcdc0b mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_3::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:549:12
#34 0x0000630360bcdb8d mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_3>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#35 0x0000630360d704c9 llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#36 0x0000630360d6fa70 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) /home/kunwar/llvm-project/mlir/lib/Support/ToolUtilities.cpp:28:12
#37 0x0000630360bca0d3 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:552:10
#38 0x0000630360bca441 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:590:14
#39 0x0000630360bca618 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:606:10
#40 0x000063035aefa051 main /home/kunwar/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:309:33
#41 0x00007925efc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#42 0x00007925efc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#43 0x000063035aef9ca5 _start (./bin/mlir-opt+0x8502ca5)
[1]    99805 IOT instruction (core dumped)  ./bin/mlir-opt -transform-interpreter t.mlir
llvmbot commented 4 months ago

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor has already been assigned to this issue. If you believe that no one is actually working on it despite an assignment, ping the person. After one week without a response, the assignee may be changed.
  2. In the comments of this issue, request for it to be assigned to you, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

llvmbot commented 4 months ago

@llvm/issue-subscribers-good-first-issue

Author: Kunwar Grover (Groverkss)

transform.structured.tile_using_for crashes when the number of results does not match the number of loops produced. This should instead produce an error message and exit gracefully. Reproducer: ```mlir func.func @fold_extract_slice( %arg0 : tensor<?x128xf32>, %arg1 : tensor<?x42xf32>, %arg2 : tensor<?x42x?xf32>) -> tensor<?x42xf32> { %c0 = arith.constant 0 : index %0 = tensor.dim %arg1, %c0 : tensor<?x42xf32> %1 = tensor.extract_slice %arg0[3, 4] [%0, 42] [1, 1] : tensor<?x128xf32> to tensor<?x42xf32> %2 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "parallel"]} ins(%1, %arg2 : tensor<?x42xf32>, tensor<?x42x?xf32>) outs(%arg1 : tensor<?x42xf32>) { ^bb0(%arg3 : f32, %arg4: f32, %arg5: f32): %5 = arith.addf %arg3, %arg5 : f32 linalg.yield %5 : f32 } -> tensor<?x42xf32> return %2 : tensor<?x42xf32> } module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { %0 = transform.structured.match ops{["linalg.generic"]} in %arg1 : (!transform.any_op) -> !transform.any_op %1, %loops:2 = transform.structured.tile_using_for %0 tile_sizes [2, 3, 4] : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op) transform.yield } } ``` ``` mlir-opt -transform-interpreter %s ``` Crash Report: ``` mlir-opt: /home/kunwar/llvm-project/llvm/include/llvm/ADT/SmallVector.h:304: llvm::SmallVectorTemplateCommon::reference llvm::SmallVectorTemplateCommon<llvm::SmallVector<mlir::Operation *, 4>>::operator[](llvm::SmallVectorTemplateCommon::size_type) [T = llvm::SmallVector<mlir::Operation *, 4>]: Assertion `idx < size()' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: ./bin/mlir-opt -transform-interpreter t.mlir #0 0x000063035b085b5d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/kunwar/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11 #1 0x000063035b08604b PrintStackTraceSignalHandler(void*) /home/kunwar/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1 #2 0x000063035b084076 llvm::sys::RunSignalHandlers() /home/kunwar/llvm-project/llvm/lib/Support/Signals.cpp:105:5 #3 0x000063035b086865 SignalHandler(int) /home/kunwar/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1 #4 0x00007925efc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #5 0x00007925efc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #6 0x00007925efc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #7 0x00007925efc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #8 0x00007925efc2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #9 0x00007925efc39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #10 0x000063035c9ab109 llvm::SmallVectorTemplateCommon<llvm::SmallVector<mlir::Operation*, 4u>, void>::operator[](unsigned long) /home/kunwar/llvm-project/llvm/include/llvm/ADT/SmallVector.h:0:5 #11 0x000063035c93258a mlir::transform::TileUsingForOp::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp:2801:7 #12 0x000063035c8ab721 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::TileUsingForOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:477:56 #13 0x0000630364b08a4e mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:61:14 #14 0x0000630364b0822f mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:954:48 #15 0x000063035f34d8a1 applySequenceBlock(mlir::Block&, mlir::transform::FailurePropagationMode, mlir::transform::TransformState&, mlir::transform::TransformResults&) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:1722:15 #16 0x000063035f35040b mlir::transform::NamedSequenceOp::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:2087:10 #17 0x000063035f2e08a1 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::NamedSequenceOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:477:56 #18 0x0000630364b08a4e mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:61:14 #19 0x0000630364b0822f mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:954:48 #20 0x0000630364b0ee4d mlir::transform::applyTransforms(mlir::Operation*, mlir::transform::TransformOpInterface, mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>> const&, mlir::transform::TransformOptions const&, bool) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:2005:42 #21 0x000063035f3e6d4e mlir::transform::applyTransformNamedSequence(mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>>, mlir::transform::TransformOpInterface, mlir::ModuleOp, mlir::transform::TransformOptions const&) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp:234:10 #22 0x000063035f3dda5c (anonymous namespace)::InterpreterPass::runOnOperation() /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Transforms/InterpreterPass.cpp:147:16 #23 0x0000630360bdcddb mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7::operator()() const /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:0:17 #24 0x0000630360bdcd75 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7>(long) /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5 #25 0x000063035af9db69 llvm::function_ref<void ()>::operator()() const /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5 #26 0x0000630360bdff1d void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /home/kunwar/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3 #27 0x0000630360bd82a3 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:533:17 #28 0x0000630360bd8854 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:593:16 #29 0x0000630360bda33c mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:904:10 #30 0x0000630360bda25f mlir::PassManager::run(mlir::Operation*) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:884:60 #31 0x0000630360bce1e2 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:409:17 #32 0x0000630360bcde19 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:474:12 #33 0x0000630360bcdc0b mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_3::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:549:12 #34 0x0000630360bcdb8d mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_3>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12 #35 0x0000630360d704c9 llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12 #36 0x0000630360d6fa70 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) /home/kunwar/llvm-project/mlir/lib/Support/ToolUtilities.cpp:28:12 #37 0x0000630360bca0d3 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:552:10 #38 0x0000630360bca441 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:590:14 #39 0x0000630360bca618 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:606:10 #40 0x000063035aefa051 main /home/kunwar/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:309:33 #41 0x00007925efc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #42 0x00007925efc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #43 0x000063035aef9ca5 _start (./bin/mlir-opt+0x8502ca5) [1] 99805 IOT instruction (core dumped) ./bin/mlir-opt -transform-interpreter t.mlir ```
Groverkss commented 4 months ago

@EugeneZelenko Why was the mlir label removed? This issue is related to mlir.

llvmbot commented 4 months ago

@llvm/issue-subscribers-mlir

Author: Kunwar Grover (Groverkss)

transform.structured.tile_using_for crashes when the number of results does not match the number of loops produced. This should instead produce an error message and exit gracefully. Reproducer: ```mlir func.func @fold_extract_slice( %arg0 : tensor<?x128xf32>, %arg1 : tensor<?x42xf32>, %arg2 : tensor<?x42x?xf32>) -> tensor<?x42xf32> { %c0 = arith.constant 0 : index %0 = tensor.dim %arg1, %c0 : tensor<?x42xf32> %1 = tensor.extract_slice %arg0[3, 4] [%0, 42] [1, 1] : tensor<?x128xf32> to tensor<?x42xf32> %2 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>], iterator_types = ["parallel", "parallel", "parallel"]} ins(%1, %arg2 : tensor<?x42xf32>, tensor<?x42x?xf32>) outs(%arg1 : tensor<?x42xf32>) { ^bb0(%arg3 : f32, %arg4: f32, %arg5: f32): %5 = arith.addf %arg3, %arg5 : f32 linalg.yield %5 : f32 } -> tensor<?x42xf32> return %2 : tensor<?x42xf32> } module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) { %0 = transform.structured.match ops{["linalg.generic"]} in %arg1 : (!transform.any_op) -> !transform.any_op %1, %loops:2 = transform.structured.tile_using_for %0 tile_sizes [2, 3, 4] : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op) transform.yield } } ``` ``` mlir-opt -transform-interpreter %s ``` Crash Report: ``` mlir-opt: /home/kunwar/llvm-project/llvm/include/llvm/ADT/SmallVector.h:304: llvm::SmallVectorTemplateCommon::reference llvm::SmallVectorTemplateCommon<llvm::SmallVector<mlir::Operation *, 4>>::operator[](llvm::SmallVectorTemplateCommon::size_type) [T = llvm::SmallVector<mlir::Operation *, 4>]: Assertion `idx < size()' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: ./bin/mlir-opt -transform-interpreter t.mlir #0 0x000063035b085b5d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/kunwar/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11 #1 0x000063035b08604b PrintStackTraceSignalHandler(void*) /home/kunwar/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1 #2 0x000063035b084076 llvm::sys::RunSignalHandlers() /home/kunwar/llvm-project/llvm/lib/Support/Signals.cpp:105:5 #3 0x000063035b086865 SignalHandler(int) /home/kunwar/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1 #4 0x00007925efc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #5 0x00007925efc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #6 0x00007925efc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #7 0x00007925efc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #8 0x00007925efc2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #9 0x00007925efc39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #10 0x000063035c9ab109 llvm::SmallVectorTemplateCommon<llvm::SmallVector<mlir::Operation*, 4u>, void>::operator[](unsigned long) /home/kunwar/llvm-project/llvm/include/llvm/ADT/SmallVector.h:0:5 #11 0x000063035c93258a mlir::transform::TileUsingForOp::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp:2801:7 #12 0x000063035c8ab721 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::TileUsingForOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:477:56 #13 0x0000630364b08a4e mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:61:14 #14 0x0000630364b0822f mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:954:48 #15 0x000063035f34d8a1 applySequenceBlock(mlir::Block&, mlir::transform::FailurePropagationMode, mlir::transform::TransformState&, mlir::transform::TransformResults&) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:1722:15 #16 0x000063035f35040b mlir::transform::NamedSequenceOp::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:2087:10 #17 0x000063035f2e08a1 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::NamedSequenceOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:477:56 #18 0x0000630364b08a4e mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/kunwar/llvm-project/build/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:61:14 #19 0x0000630364b0822f mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:954:48 #20 0x0000630364b0ee4d mlir::transform::applyTransforms(mlir::Operation*, mlir::transform::TransformOpInterface, mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>> const&, mlir::transform::TransformOptions const&, bool) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:2005:42 #21 0x000063035f3e6d4e mlir::transform::applyTransformNamedSequence(mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>>, mlir::transform::TransformOpInterface, mlir::ModuleOp, mlir::transform::TransformOptions const&) /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp:234:10 #22 0x000063035f3dda5c (anonymous namespace)::InterpreterPass::runOnOperation() /home/kunwar/llvm-project/mlir/lib/Dialect/Transform/Transforms/InterpreterPass.cpp:147:16 #23 0x0000630360bdcddb mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7::operator()() const /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:0:17 #24 0x0000630360bdcd75 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7>(long) /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5 #25 0x000063035af9db69 llvm::function_ref<void ()>::operator()() const /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5 #26 0x0000630360bdff1d void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /home/kunwar/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3 #27 0x0000630360bd82a3 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:533:17 #28 0x0000630360bd8854 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:593:16 #29 0x0000630360bda33c mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:904:10 #30 0x0000630360bda25f mlir::PassManager::run(mlir::Operation*) /home/kunwar/llvm-project/mlir/lib/Pass/Pass.cpp:884:60 #31 0x0000630360bce1e2 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:409:17 #32 0x0000630360bcde19 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:474:12 #33 0x0000630360bcdc0b mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_3::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:549:12 #34 0x0000630360bcdb8d mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_3>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12 #35 0x0000630360d704c9 llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/kunwar/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12 #36 0x0000630360d6fa70 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) /home/kunwar/llvm-project/mlir/lib/Support/ToolUtilities.cpp:28:12 #37 0x0000630360bca0d3 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:552:10 #38 0x0000630360bca441 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:590:14 #39 0x0000630360bca618 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /home/kunwar/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:606:10 #40 0x000063035aefa051 main /home/kunwar/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:309:33 #41 0x00007925efc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #42 0x00007925efc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #43 0x000063035aef9ca5 _start (./bin/mlir-opt+0x8502ca5) [1] 99805 IOT instruction (core dumped) ./bin/mlir-opt -transform-interpreter t.mlir ```
EugeneZelenko commented 4 months ago

@EugeneZelenko Why was the mlir label removed? This issue is related to mlir.

You added more specific label already. Generic labels should be used only if no more specific ones exist or added.

Groverkss commented 4 months ago

@EugeneZelenko Why was the mlir label removed? This issue is related to mlir.

You added more specific label already. Generic labels should be used only if no more specific ones exist or added.

Thanks, I removed it. I was not aware of this.

cjkenn commented 4 months ago

I'd like to take a look at this issue. I just finished building mlir the other day and I'm looking for spots to dive in now, so it might take me a few days to get my bearings!

huang-me commented 4 months ago

Is this issue still exist in tag: llvmorg-18.1.6? I tested the input and end with error gracefully.

ps. input should be modified as follow due to syntax change

func.func @fold_extract_slice(
  %arg0 : tensor<?x128xf32>, %arg1 : tensor<?x42xf32>, %arg2 : tensor<?x42x?xf32>) -> tensor<?x42xf32> {

  %c0 = arith.constant 0 : index

  %0 = tensor.dim %arg1, %c0 : tensor<?x42xf32>
  %1 = tensor.extract_slice %arg0[3, 4] [%0, 42] [1, 1] : tensor<?x128xf32> to tensor<?x42xf32>

  %2 = linalg.generic
    {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1)>,
                      affine_map<(d0, d1, d2) -> (d0, d1, d2)>,
                      affine_map<(d0, d1, d2) -> (d0, d1)>],
     iterator_types = ["parallel", "parallel", "parallel"]}
    ins(%1, %arg2 : tensor<?x42xf32>, tensor<?x42x?xf32>)
    outs(%arg1 : tensor<?x42xf32>) {
    ^bb0(%arg3 : f32, %arg4: f32, %arg5: f32):
      %5 = arith.addf %arg3, %arg5 : f32
      linalg.yield %5 : f32
    } -> tensor<?x42xf32>
  return %2 : tensor<?x42xf32>
}

module attributes {transform.with_named_sequence} {
  transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
    %0 = transform.structured.match ops{["linalg.generic"]} in %arg1 : (!transform.any_op) -> !transform.any_op
    %1, %loops:2 = transform.structured.tile_using_for %0 tile_sizes [2, 3, 4] : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op)
    transform.yield
  }
}
cjkenn commented 4 months ago

Indeed, in 18.1.6 it looks like this was fixed in https://github.com/llvm/llvm-project/pull/66007 @Groverkss is that pr sufficient enough to close this issue?