Skip to content

Commit

Permalink
[WIP] making tridiag in MLIR correct. Currently it crashes in parsing…
Browse files Browse the repository at this point in the history
… a case somewhere.

==20217==ERROR: AddressSanitizer: SEGV on unknown address 0x00007a00001a (pc 0x7f7e1f6d9147 bp 0x000000000000 sp 0x7fffa7093fc0 T0)
==20217==The signal is caused by a WRITE memory access.
    #0 0x7f7e1f6d9147 in mlir::IROperand<mlir::OpOperand, mlir::detail::OpaqueValue>::insertIntoCurrent() /home/bollu/work/mlir/llvm-project/mlir/include/mlir/IR/UseDefLists.h:203
    #1 0x7f7e1f6d9147 in mlir::IROperand<mlir::OpOperand, mlir::detail::OpaqueValue>::IROperand(mlir::Operation*, mlir::detail::OpaqueValue) /home/bollu/work/mlir/llvm-project/mlir/include/mlir/IR/UseDefLists.h:117
    #2 0x7f7e1f6d9147 in mlir::OpOperand::OpOperand(mlir::Operation*, mlir::detail::OpaqueValue) /home/bollu/work/mlir/llvm-project/mlir/include/mlir/IR/UseDefLists.h:268
    #3 0x7f7e1f6d9147 in mlir::detail::OperandStorage::OperandStorage(mlir::Operation*, mlir::ValueRange) /home/bollu/work/mlir/llvm-project/mlir/lib/IR/OperationSupport.cpp:232
    #4 0x7f7e1f6cd689 in mlir::Operation::create(mlir::Location, mlir::OperationName, mlir::TypeRange, mlir::ValueRange, mlir::DictionaryAttr, mlir::BlockRange, unsigned int) /home/bollu/work/mlir/llvm-project/mlir/lib/IR/Operation.cpp:157
    #5 0x7f7e1f6cd800 in mlir::Operation::create(mlir::Location, mlir::OperationName, mlir::TypeRange, mlir::ValueRange, mlir::DictionaryAttr, mlir::BlockRange, mlir::RegionRange) /home/bollu/work/mlir/llvm-project/mlir/lib/IR/Operation.cpp:97
    #6 0x7f7e1f6cdb46 in mlir::Operation::create(mlir::OperationState const&) /home/bollu/work/mlir/llvm-project/mlir/lib/IR/Operation.cpp:87
    #7 0x7f7e1f65b59b in mlir::OpBuilder::createOperation(mlir::OperationState const&) /home/bollu/work/mlir/llvm-project/mlir/lib/IR/Builders.cpp:394
    #8 0x7f7e1f9a088f in parseCustomOperation /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:1680
    #9 0x7f7e1f9a088f in (anonymous namespace)::OperationParser::parseOperation() /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:693
    #10 0x7f7e1f9a299c in (anonymous namespace)::OperationParser::parseBlockBody(mlir::Block*) /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:1868
    #11 0x7f7e1f9a3509 in parseBlock /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:1835
    #12 0x7f7e1f9a3509 in (anonymous namespace)::OperationParser::parseRegion(mlir::Region&, llvm::ArrayRef<std::pair<(anonymous namespace)::OperationParser::SSAUseInfo, mlir::Type> >, bool) /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:1781
    #13 0x7f7e1f9a3696 in (anonymous namespace)::CustomOpAsmParser::parseRegion(mlir::Region&, llvm::ArrayRef<mlir::OpAsmParser::OperandType>, llvm::ArrayRef<mlir::Type>, bool) /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:1453
    #14 0x7f7e1f9a3a5e in (anonymous namespace)::CustomOpAsmParser::parseOptionalRegion(mlir::Region&, llvm::ArrayRef<mlir::OpAsmParser::OperandType>, llvm::ArrayRef<mlir::Type>, bool) /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:1465
    #15 0x7f7e1f6b8e01 in mlir::impl::parseFunctionLikeOp(mlir::OpAsmParser&, mlir::OperationState&, bool, llvm::function_ref<mlir::Type (mlir::Builder&, llvm::ArrayRef<mlir::Type>, llvm::ArrayRef<mlir::Type>, mlir::impl::VariadicFlag, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)>) /home/bollu/work/mlir/llvm-project/mlir/lib/IR/FunctionImplementation.cpp:213
    #16 0x7f7e1f66db56 in parseFuncOp /home/bollu/work/mlir/llvm-project/mlir/lib/IR/BuiltinDialect.cpp:120
    #17 0x7f7e1f66db56 in mlir::FuncOp::parse(mlir::OpAsmParser&, mlir::OperationState&) /home/bollu/work/mlir/llvm-project/build/tools/mlir/include/mlir/IR/BuiltinOps.cpp.inc:209
    #18 0x7f7e1f9a02e0 in parseOperation /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:895
    #19 0x7f7e1f9a02e0 in parseCustomOperation /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:1672
    #20 0x7f7e1f9a02e0 in (anonymous namespace)::OperationParser::parseOperation() /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:693
    #21 0x7f7e1f9a170e in parse /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:2041
    #22 0x7f7e1f9a170e in mlir::parseSourceFile(llvm::SourceMgr const&, mlir::Block*, mlir::MLIRContext*, mlir::LocationAttr*) /home/bollu/work/mlir/llvm-project/mlir/lib/Parser/Parser.cpp:2098
    #23 0x7f7e2a100dda in mlir::OwningOpRef<mlir::ModuleOp> mlir::parseSourceFile<mlir::ModuleOp>(llvm::SourceMgr const&, mlir::MLIRContext*) /home/bollu/work/mlir/llvm-project/mlir/include/mlir/Parser.h:132
    #24 0x7f7e2a100dda in mlir::parseSourceFile(llvm::SourceMgr const&, mlir::MLIRContext*) /home/bollu/work/mlir/llvm-project/mlir/include/mlir/Parser.h:201
    #25 0x7f7e2a100dda in performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, mlir::PassPipelineCLParser const&) (.constprop.144) /home/bollu/work/mlir/llvm-project/mlir/lib/Support/MlirOptMain.cpp:55
    #26 0x7f7e2a101fbe in processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, bool, bool, bool, bool, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&) /home/bollu/work/mlir/llvm-project/mlir/lib/Support/MlirOptMain.cpp:110
    #27 0x7f7e2a102135 in mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool) /home/bollu/work/mlir/llvm-project/mlir/lib/Support/MlirOptMain.cpp:148
    #28 0x7f7e2a103a0e in mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) /home/bollu/work/mlir/llvm-project/mlir/lib/Support/MlirOptMain.cpp:251
    #29 0x4e9fc1 in main /home/bollu/work/mlir/lz/build/../hask-opt/hask-opt.cpp:100:17
    #30 0x7f7e198cdbf6 in __libc_start_main /build/glibc-S7xCS9/glibc-2.27/csu/../csu/libc-start.c:310
    #31 0x43f5a9 in _start (/home/bollu/work/mlir/lz/build/bin/hask-opt+0x43f5a9)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/bollu/work/mlir/llvm-project/mlir/include/mlir/IR/UseDefLists.h:203 in mlir::IROperand<mlir::OpOperand, mlir::detail::OpaqueValue>::insertIntoCurrent()
==20217==ABORTING
  • Loading branch information
bollu committed Jan 6, 2021
1 parent e0c9aa0 commit ffa7bb9
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 11 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,49 @@ Convert GHC Core to MLIR.


# Log: [newest] to [oldest]

# Wednesday, Jan 6th

- Tensor is insufficient for my purposes because I see no way to express something like a `zip` in any way that MLIR
will know how to optimize. This is because it seems that all the effort in MLIR is spent on affine/linalg/.. all of which
work on `memref`s.
- I'm going to weaken the checks and balances on `memref`s to see how far it takes me.
In particular, I'm commenting out:

```diff
diff --git a/mlir/include/mlir/IR/BuiltinTypes.h b/mlir/include/mlir/IR/BuiltinTypes.h
index 3bfb3ce4c79b..ace5b1a24c05 100644
--- a/mlir/include/mlir/IR/BuiltinTypes.h
+++ b/mlir/include/mlir/IR/BuiltinTypes.h
@@ -445,7 +445,8 @@ public:

/// Return true if the specified element type is ok in a memref.
static bool isValidElementType(Type type) {
- return type.isIntOrIndexOrFloat() || type.isa<VectorType, ComplexType>();
+ return true;
+ // return type.isIntOrIndexOrFloat() || type.isa<VectorType, ComplexType>();
}

/// Methods for support type inquiry through isa, cast, and dyn_cast.
diff --git a/mlir/lib/Parser/TypeParser.cpp b/mlir/lib/Parser/TypeParser.cpp
index ab7f85a645e4..f777963fd9a7 100644
--- a/mlir/lib/Parser/TypeParser.cpp
+++ b/mlir/lib/Parser/TypeParser.cpp
@@ -217,9 +217,10 @@ Type Parser::parseMemRefType() {
return nullptr;

// Check that memref is formed from allowed types.
- if (!elementType.isIntOrIndexOrFloat() &&
- !elementType.isa<VectorType, ComplexType>())
- return emitError(typeLoc, "invalid memref element type"), nullptr;
+ // allow arbitrary element types.
+ // if (!elementType.isIntOrIndexOrFloat() &&
+ // !elementType.isa<VectorType, ComplexType>())
+ // return emitError(typeLoc, "invalid memref element type"), nullptr;
```

which checks that the memref has an element type of `int/float/complex/index`.


# Tuesday, Jan 5th
- There's a [`for_with_yield`](https://github.com/llvm/llvm-project/blob/main/mlir/test/Conversion/AffineToStandard/lower-affine.mlir#L29)
Expand Down
6 changes: 6 additions & 0 deletions lib/GRIN/GRINTransforms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// https://github.com/grin-compiler/grin
// EvaluatedCaseElimination
// TrivialCaseOptimization
// SparseCaseOptimization
// UpdateElimination

67 changes: 56 additions & 11 deletions test/bench-vector/Tridiag.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,94 @@
// id `seq` (c*id, (d-d'*a)*id)

// Example: @prescanl (+) 0 \<1,2,3,4\> = \<0,1,3,6\>@
func @prescanr(%f: (!lz.value, !lz.value) -> (!lz.value), %seed: !lz.value, %xs: memref<?x!lz.value>) -> memref<?x!lz.value> {
func @prescanr(%f: (!lz.value, !lz.value) -> (!lz.value),
%seed: !lz.value,
%xs: memref<?x!lz.value>) -> memref<?x!lz.value> {
%N = constant 1024 : index
%out = alloc(%N) : memref<?x!lz.value>
affine.for %i = 0 to %N step 1
iter_args(%accum = %seed) -> (!lz.value) {
affine.store %accum, %out[%i] : memref<?x!lz.value>
%x = affine.load %xs[%i] : memref<?x!lz.value>
%accum_cur = std.call_indirect %f (%x, %accum) : (!lz.value, !lz.value) -> !lz.value
%accum_cur = std.call_indirect %f (%x, %accum)
: (!lz.value, !lz.value) -> !lz.value
affine.yield %accum_cur : !lz.value
}
return %out : memref<?x!lz.value>
}

// Example: @prescanl (+) 0 \<1,2,3,4\> = \<0,1,3,6\>@
// v we should take a closure, right?
func @prescanl(%f: (!lz.value, !lz.value) -> (!lz.value), %seed: !lz.value, %xs: memref<?x!lz.value>) -> memref<?x!lz.value> {
func @prescanl(%f: (!lz.value, !lz.value) -> (!lz.value),
%seed: !lz.value,
%xs: memref<?x!lz.value>) -> memref<?x!lz.value> {
%N = constant 1024 : index
%out = alloc(%N) : memref<?x!lz.value>
affine.for %i = 0 to %N step 1
iter_args(%accum = %seed) -> (!lz.value) {
affine.store %accum, %out[%i] : memref<?x!lz.value>
%x = affine.load %xs[%i] : memref<?x!lz.value>
%accum_cur = std.call_indirect %f (%x, %accum) : (!lz.value, !lz.value) -> !lz.value
%accum_cur = std.call_indirect %f (%x, %accum)
: (!lz.value, !lz.value) -> !lz.value
affine.yield %accum_cur : !lz.value
}
return %out : memref<?x!lz.value>
}

func @zip(%xs: memref<?xi64>, %ys: memref<?xi64>) -> memref<?x!lz.value> {
func @zip(%xs: memref<?xf64>, %ys: memref<?xf64>) -> memref<?x!lz.value> {
%N = constant 1024 : index
%out = alloc(%N) : memref<?x!lz.value>
affine.for %i = 0 to %N step 1 {
%x = affine.load %xs[%i] : memref<?xi64>
%y = affine.load %ys[%i] : memref<?xi64>
%zip = lz.construct(@Tuple2, %x: i64, %y: i64)
%x = affine.load %xs[%i] : memref<?xf64>
%y = affine.load %ys[%i] : memref<?xf64>
%zip = lz.construct(@Tuple2, %x: f64, %y: f64)
affine.store %zip, %out[%i] : memref<?x!lz.value>
}
return %out : memref<?x!lz.value>
}

//
// func @trihs() -> tensor<?xf64> {
// }
// write c', d' as c2, d2
func @modify(%cd2: !lz.value, %abcd: !lz.value) -> !lz.value {
%out = lz.case @Tuple %cd
[@Tuple -> { ^entry(%c2: f64, %d2: f64):
%out = lz.case @Tuple %abcd
[@Tuple -> { ^entry(%ab: !lz.value, %cd: !lz.value):
%out = lz.case @Tuple %ab
[@Tuple -> { ^entry(%a: f64, %b: f64):
%out = lz.case @Tuple %cd
[@Tuple -> { ^entry(%c: f64, %d: f64):
%c2a = std.mulf %c2, %a : f64
%b_minus_c2a = std.subf %b, %c2a : f64
%c1 = constant 1.0 : f64
%id = divf %c1, %b_minus_c2a : f64
%c_x_id = std.mulf %c, %id : f64
%d_min_d2 = std.subf %d, %d2 : f64
%d_min_d2_x_a = std.mulf %d_min_d2, %a : f64
%d_min_d2_x_a_x_id = std.mulf %d_min_d2_x_a, %id : f64
%out = lz.construct (@Tuple, %c_x_id : f64, %d_min_d2_x_a_x_id : f64)
lz.return %out : !lz.value
}]
lz.return %out : !lz.value

}]
lz.return %out : !lz.value
}]
lz.return %out : !lz.value
}]
return %out : !lz.value
}

func @trihs(%as: memref<?xf64>,
%bs: memref<?xf64>,
%cs: memref<?xf64>,
%ds: memref<?xf64>) -> memref<?xf64> {
%asbs = call @zip (%as, %bs)
: (memref<?xf64>, memref<?xf64>) -> memref<?x!lz.value>
%csds = call @zip (%cs, %ds)
: (memref<?xf64>, memref<?xf64>) -> memref<?x!lz.value>
return %cs : memref<?xf64>
}

//
// func @trihand(%as: tensor<?xf64>, %bs: tensor<?xf64>, %cs: tensor<?xf64>, %ds: tensor<?xf64>) -> tensor<?xf64> {
//
Expand Down

0 comments on commit ffa7bb9

Please sign in to comment.