Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Colloportus0 opened this issue Jul 24, 2023 · 4 comments
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir:affine

Comments

@Colloportus0
Copy link

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 
@EugeneZelenko EugeneZelenko added mlir:affine crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Jul 24, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 24, 2023

@llvm/issue-subscribers-mlir-affine

@9Tempest
Copy link
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.

@9Tempest
Copy link
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.

@rikhuijzer
Copy link
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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir:affine
Projects
None yet
Development

No branches or pull requests

5 participants