Skip to content

Conversation

@SwapnilGhanshyala
Copy link

No description provided.

@bondhugula
Copy link

Please use an appropriate commit title: instead of "Solved ...", use "[MLIR][Affine] Fix crash with an invalid unroll factor", etc.
The commit is still missing a commit summary.

@SwapnilGhanshyala SwapnilGhanshyala removed the request for review from kingshukmajumder October 3, 2023 13:00
@SwapnilGhanshyala SwapnilGhanshyala changed the title Solved for Issue #64321: handle user passing unroll-factor <=0 [MLIR][Affine] Fix crash with invalid unroll factor. Oct 3, 2023
@SwapnilGhanshyala
Copy link
Author

Updated the commit message and the commit summary.

SwapnilGhanshyala pushed a commit that referenced this pull request Oct 4, 2023
…fine.parallel verifier

This patch updates AffineParallelOp::verify() to check each result type matches
its corresponding reduction op (i.e, the result type must be a `FloatType` if
the reduction attribute is `addf`)

affine.parallel will crash on --lower-affine if the corresponding result type
cannot match the reduction attribute.

```
      %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>
      }
```
This will crash and report a type conversion issue when we run `mlir-opt --lower-affine`

```
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)
...
```

Fixes llvm#64068

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D157985
Copy link

@bondhugula bondhugula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit titles shouldn't have full stops - please drop it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this include I think - it's transitively covered.

Comment on lines 1019 to 1025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert is fine. The utility shouldn't typically emit a message in this situation. The 0 unroll factor should be checked by the user of this utility, which would be the pass, given the crash issue you are addressing. Please put the check and emit message in the pass.

Updated LoopUnroll pass to check if unrollFactor passed by the user is invalid, i.e., less than or equal to
zero. If so, emit appropriate message and signal pass failure.
Reporting Issue is llvm#64321
@SwapnilGhanshyala
Copy link
Author

SwapnilGhanshyala commented Oct 26, 2023

Changes Addressed:

  1. check user error in pass itself
  2. Updated commit title and message:
    [MLIR][Affine] Fix crash with invalid unroll factor (Issue # 64321)

Updated LoopUnroll pass to check if unrollFactor passed by the user is invalid, i.e., less than or equal to
zero. If so, emit appropriate message and signal pass failure.

Reporting Issue is llvm#64321

@SwapnilGhanshyala SwapnilGhanshyala changed the title [MLIR][Affine] Fix crash with invalid unroll factor. [MLIR][Affine] Fix crash with invalid unroll factor (Issue #64321) Oct 26, 2023
SwapnilGhanshyala pushed a commit that referenced this pull request Jan 22, 2024
…8055)

This fixes a crash where `path::parent_path` causes an invalid access on
a string upon receiving a path that consists of a single colon.

On Windows machine, with runtime checks enabled build, upon `clang -I:
test.cc` produces:
```
Assertion failed: Index < Length && "Invalid index!", file llvm\include\llvm/ADT/StringRef.h, line 232
...
 #6 0x00007ff7816201eb `anonymous namespace'::parent_path_end llvm\lib\Support\Path.cpp:144:0
 #7 0x00007ff781620135 llvm::sys::path::parent_path(class llvm::StringRef, enum llvm::sys::path::Style) llvm\lib\Support\Path.cpp:470:0
```

Ideally, we can look for the last colon starting from the last
character, but we can instead start from second to last, and handle
empty paths by abusing `0 - 1 == npos`.
if (func.isExternal())
return;

if (unrollFactor <= 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unsigned. == 0 would be the right check.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix message accordingly as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants