Skip to content

Commit

Permalink
[AMDAIECoreToStandard] Improve error message when core not isolated (#…
Browse files Browse the repository at this point in the history
…718)

In case we hit this error again, I'd like the message to be more
informative. The new error is something like:
```
<unknown>:0: error: 'arith.constant' op is not in the core in which it is used. Cores must be `isolated` before this point.
<unknown>:0: note: see current operation: %0 = "arith.constant"() <{value = 0 : i32}> : () -> i32
<unknown>:0: error: 'aie.device' op Failed to lower to LLVM
<unknown>:0: note: see current operation:
"aie.device"() <{device = 8 : i32}> ({
```

compared to old error, something like: 
```
LLVM ERROR: operation destroyed but still has uses
Please report issues to https://github.com/iree-org/iree/issues and include the crash backtrace.
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libIREECompiler.so 0x00007fa09d494f87 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  libIREECompiler.so 0x00007fa09d4931c0 llvm::sys::RunSignalHandlers() + 80
```
  • Loading branch information
newling authored Aug 29, 2024
1 parent 0a8a140 commit b7418ee
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions compiler/plugins/target/AMD-AIE/aie/AMDAIECoreToStandard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,31 @@ struct AMDAIECoreToStandardFunc : OpConversionPattern<CoreOp> {
tileRow(tileRow) {}

LogicalResult matchAndRewrite(
CoreOp op, OpAdaptor adaptor,
CoreOp coreOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
TileOp t = getTileOp(*op);
TileOp t = getTileOp(*coreOp);
int col = t.getCol();
int row = t.getRow();

// Only pull code for the indicated function
if ((tileRow != row && tileRow != -1) ||
(tileCol != col && tileCol != -1)) {
rewriter.eraseOp(op);
rewriter.eraseOp(coreOp);
return success();
}

// The parent should be an AIE.device op.
rewriter.setInsertionPointAfter(op->getParentOp());
rewriter.setInsertionPointAfter(coreOp->getParentOp());

std::string coreName("core_" + std::to_string(col) + "_" +
std::to_string(row));
auto coreFunc = rewriter.create<func::FuncOp>(
rewriter.getUnknownLoc(), coreName,
FunctionType::get(rewriter.getContext(), {}, {}));
rewriter.cloneRegionBefore(op.getBody(), coreFunc.getBody(),



rewriter.cloneRegionBefore(coreOp.getBody(), coreFunc.getBody(),
coreFunc.getBody().begin(), mapper);

// Rewrite the AIE.end() op
Expand All @@ -160,7 +163,7 @@ struct AMDAIECoreToStandardFunc : OpConversionPattern<CoreOp> {
}
});

rewriter.eraseOp(op);
rewriter.eraseOp(coreOp);
return success();
}
};
Expand Down Expand Up @@ -211,13 +214,16 @@ struct AMDAIECoreToStandardPass : mlir::OperationPass<ModuleOp> {

void runOnOperation() override {
ModuleOp m = getOperation();
OpBuilder builder = OpBuilder::atBlockEnd(m.getBody());


if (m.getOps<DeviceOp>().empty()) {
m.emitOpError("expected AIE.device operation at toplevel");
return signalPassFailure();
}

OpBuilder builder = OpBuilder::atBlockEnd(m.getBody());


// Ensure that we don't have an incorrect target triple. This may override
// some bogus target triple in the original mlir.
m->setAttr(LLVM::LLVMDialect::getTargetTripleAttrName(),
Expand Down Expand Up @@ -251,6 +257,28 @@ struct AMDAIECoreToStandardPass : mlir::OperationPass<ModuleOp> {
if (failed(applyPartialConversion(m, target, std::move(patterns))))
return signalPassFailure();

// Assert that cores are isolated
{
SmallVector<CoreOp> coreOps;
m->walk([&](CoreOp coreOp) { coreOps.push_back(coreOp); });
for (CoreOp coreOp : coreOps) {
auto walkResult = coreOp->walk([&](Operation *childOp) {
if (childOp == coreOp) return WalkResult::advance();
for (Value operand : childOp->getOperands()) {
if (Operation *operandOp = operand.getDefiningOp()) {
if (!coreOp->isAncestor(operandOp)) {
operandOp->emitOpError(
"is not in the core in which it is used. Cores must be "
"`isolated` before this point.");
return WalkResult::interrupt();
}
}
}
return WalkResult::advance();
});
if (walkResult.wasInterrupted()) return signalPassFailure();
}
}
RewritePatternSet outlinePatterns(&getContext());
outlinePatterns.add<AMDAIECoreToStandardFunc>(m.getContext(), mapper,
tileCol, tileRow);
Expand Down

0 comments on commit b7418ee

Please sign in to comment.