Skip to content

[mlir] mlir::arith::getIdentityValueAttr crashed with assertion failure "cast<Ty>() argument of incompatible type!" #64068

Closed

Description

@Colloportus0

MLIR built at commit 585cbe3
Reproduced with:
mlir-opt --lower-affine temp.mlir

temp.mlir:

module { 
  func.func @func2() {
    %cst = arith.constant 5.158400e+04 : f16 
    %c1 = arith.constant 1 : index
    %c2 = arith.constant 2 : index  
    %71 = affine.if affine_set<(d0, d1, d2) : (d2 ceildiv 16 >= 0)>(%c1, %c2, %c2) -> f16 {
      %128 = affine.parallel (%arg2, %arg3) = (0, 0) to (8, 7) reduce ("maxf") -> (memref<8x7xf32>) {
        %alloc_33 = memref.alloc() : memref<8x7xf32>
        affine.yield %alloc_33 : memref<8x7xf32>
      } 
      vector.warp_execute_on_lane_0(%c1)[32] {
        memref.assume_alignment %128, 8 : memref<8x7xf32>
      }
      affine.yield %cst : f16
    } else {
      affine.yield %cst : f16
    } 
    return
  }
}

trace:

Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h, line 572.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: mlir-opt --lower-affine temp.mlir
 #0 0x0000000102a18f18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workspacebin/mlir-opt+0x1002f8f18)
 #1 0x0000000102a171b4 llvm::sys::RunSignalHandlers() (/workspacebin/mlir-opt+0x1002f71b4)
 #2 0x0000000102a195c4 SignalHandler(int) (/workspacebin/mlir-opt+0x1002f95c4)
 #3 0x00000001be7894c4 (/usr/lib/system/libsystem_platform.dylib+0x1803414c4)
 #4 0x00000001be771ee0 (/usr/lib/system/libsystem_pthread.dylib+0x180329ee0)
 #5 0x00000001be6ac340 (/usr/lib/system/libsystem_c.dylib+0x180264340)
 #6 0x00000001be6ab754 (/usr/lib/system/libsystem_c.dylib+0x180263754)
 #7 0x0000000106864790 mlir::arith::getIdentityValueAttr(mlir::arith::AtomicRMWKind, mlir::Type, mlir::OpBuilder&, mlir::Location) (.cold.4) (/workspacebin/mlir-opt+0x104144790)
 #8 0x0000000102ba66ac mlir::arith::getIdentityValueAttr(mlir::arith::AtomicRMWKind, mlir::Type, mlir::OpBuilder&, mlir::Location) (/workspacebin/mlir-opt+0x1004866ac)
 #9 0x0000000102ba6910 mlir::arith::getIdentityValue(mlir::arith::AtomicRMWKind, mlir::Type, mlir::OpBuilder&, mlir::Location) (/workspacebin/mlir-opt+0x100486910)
#10 0x0000000104831534 (anonymous namespace)::AffineParallelLowering::matchAndRewrite(mlir::affine::AffineParallelOp, mlir::PatternRewriter&) const (/workspacebin/mlir-opt+0x102111534)
#11 0x000000010669b0f0 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>)::$_2::operator()() const (/workspacebin/mlir-opt+0x103f7b0f0)
#12 0x00000001066983ec mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) (/workspacebin/mlir-opt+0x103f783ec)
#13 0x00000001050b8c5c (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) (/workspacebin/mlir-opt+0x102998c5c)
#14 0x00000001050b115c (anonymous namespace)::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>, llvm::function_ref<void (mlir::Diagnostic&)>) (/workspacebin/mlir-opt+0x10299115c)
#15 0x00000001050b32a4 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget&, mlir::FrozenRewritePatternSet const&, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>*) (/workspacebin/mlir-opt+0x1029932a4)
#16 0x0000000104836cf4 (anonymous namespace)::LowerAffinePass::runOnOperation() (/workspacebin/mlir-opt+0x102116cf4)
#17 0x00000001050682a8 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/workspacebin/mlir-opt+0x1029482a8)
#18 0x0000000105068998 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/workspacebin/mlir-opt+0x102948998)
#19 0x000000010506a82c mlir::PassManager::run(mlir::Operation*) (/workspacebin/mlir-opt+0x10294a82c)
#20 0x0000000105062d14 performActions(llvm::raw_ostream&, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) (/workspacebin/mlir-opt+0x102942d14)
#21 0x0000000105062368 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_1>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) (/workspacebin/mlir-opt+0x102942368)
#22 0x00000001050e034c mlir::splitAndProcessBuffer(std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/workspacebin/mlir-opt+0x1029c034c)
#23 0x000000010505cd1c mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/workspacebin/mlir-opt+0x10293cd1c)
#24 0x000000010505d18c mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/workspacebin/mlir-opt+0x10293d18c)
#25 0x0000000102723510 main (/workspacebin/mlir-opt+0x100003510)
#26 0x000000010e0a9088 

Activity

  1. added
    crashPrefer [crash-on-valid] or [crash-on-invalid]
    and removed on Jul 24, 2023
  2. llvmbot commented on Jul 24, 2023

    @llvmbot
    Member

    @llvm/issue-subscribers-mlir-affine

  3. 9Tempest commented on Aug 15, 2023

    @9Tempest
    Contributor

    The crash occurs when using the reduce op as maxf. It's expecting a float type result, but it's given memref<8x7xf32>. This type mismatch causes the problem when the function arith::getIdentityValueAttr tries to convert memref<8x7xf32> into a mlir::FloatType, resulting in a failure and eventually leading the program to crash.

    Solution: Update the verifier of affine::parallel to enforce each result type to match each reduction op. Currently working on this.

  4. 9Tempest commented on Aug 15, 2023

    @9Tempest
    Contributor

    Please take a look at this patch for potential solution.
    Another solution as mentioned in the link would be checking whether each result type matches its related reduction attribute in AffineParallelLowering. If not matched, notify a match failure instead of aborting the program.

  5. rikhuijzer commented on Oct 1, 2023

    @rikhuijzer
    Member

    Hi Luke (@9Tempest), I am not an expert at MLIR and would therefore not be able to approve your patch, but as far as I can see it looks good! It seems that the timing with your patch has been unfortunate with the migration from Phabricator to GitHub pull requests. Since Phabricator is now in read-only mode, I would resubmit the patch here at GitHub.

    I verified that the issue above still exist on current main and your patch still works. Only difference is thatmaxf is now called maximumf (see #66135 for details).

  6. added a commit that references this issue on Feb 19, 2024
    9580468
  7. added a commit that references this issue on Oct 7, 2026
    e23371e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashPrefer [crash-on-valid] or [crash-on-invalid]mlir:affine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions