-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logical objectFifo hoisting pass
- Loading branch information
Showing
10 changed files
with
284 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/AMDAIEHoistLogicalObjFifo.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2024 The IREE Authors | ||
// | ||
// Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include "iree-amd-aie/IR/AMDAIEOps.h" | ||
#include "iree-amd-aie/Transforms/Passes.h" | ||
#include "iree-amd-aie/Transforms/Transforms.h" | ||
#include "mlir/Dialect/Func/IR/FuncOps.h" | ||
|
||
#define DEBUG_TYPE "iree-amdaie-hoist-logical-objectfifo" | ||
|
||
namespace mlir::iree_compiler::AMDAIE { | ||
|
||
/// Hoist logical objectFifo operations until one of the operands is located | ||
/// within the same scope. | ||
LogicalResult hoistLogicalObjFifoOp(RewriterBase &rewriter, | ||
AMDAIE::LogicalObjectFifoFromMemrefOp op) { | ||
Operation *ancestorOp = op; | ||
while (ancestorOp) { | ||
Operation *newAncestorOp = ancestorOp->getParentOp(); | ||
if (llvm::any_of(op->getOperands(), [&](Value operand) { | ||
return operand.getDefiningOp() && | ||
newAncestorOp->isProperAncestor(operand.getDefiningOp()); | ||
})) { | ||
break; | ||
} | ||
if (isa<AMDAIE::WorkgroupOp, AMDAIE::ControlCodeOp, func::FuncOp>( | ||
newAncestorOp)) { | ||
break; | ||
} | ||
ancestorOp = newAncestorOp; | ||
} | ||
if (ancestorOp && ancestorOp != op) rewriter.moveOpBefore(op, ancestorOp); | ||
return failure(); | ||
} | ||
|
||
namespace { | ||
struct AMDAIEHoistLogicalObjFifoPass | ||
: public impl::AMDAIEHoistLogicalObjFifoBase< | ||
AMDAIEHoistLogicalObjFifoPass> { | ||
void runOnOperation() override; | ||
}; | ||
|
||
void AMDAIEHoistLogicalObjFifoPass::runOnOperation() { | ||
Operation *parentOp = getOperation(); | ||
IRRewriter rewriter(parentOp->getContext()); | ||
|
||
SmallVector<AMDAIE::LogicalObjectFifoFromMemrefOp> logicalObjFifos; | ||
parentOp->walk([&](AMDAIE::LogicalObjectFifoFromMemrefOp op) { | ||
(void)hoistLogicalObjFifoOp(rewriter, op); | ||
}); | ||
} | ||
|
||
} // namespace | ||
|
||
std::unique_ptr<Pass> createAMDAIEHoistLogicalObjFifoPass() { | ||
return std::make_unique<AMDAIEHoistLogicalObjFifoPass>(); | ||
} | ||
|
||
} // namespace mlir::iree_compiler::AMDAIE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
205 changes: 205 additions & 0 deletions
205
compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/test/hoist_logical_obj_fifo.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
// RUN: iree-opt --split-input-file --pass-pipeline="builtin.module(iree-amdaie-hoist-logical-objectfifo)" %s | FileCheck %s | ||
|
||
// CHECK-LABEL: @func_hoist | ||
// CHECK-SAME: %[[ARG0:.+]]: memref<32x64xi32> | ||
// CHECK: %[[C0:.+]] = arith.constant 0 : index | ||
// CHECK: %[[TILE_0_0:.+]] = amdaie.tile(%[[C0]], %[[C0]]) | ||
// CHECK: amdaie.logicalobjectfifo.from_memref %[[ARG0]], {%[[TILE_0_0]]} | ||
// CHECK: scf.forall | ||
// CHECK-NOT: amdaie.logicalobjectfifo.from_memref | ||
module { | ||
func.func @func_hoist(%arg0: memref<32x64xi32>) { | ||
%c0 = arith.constant 0 : index | ||
%tile_0_0 = amdaie.tile(%c0, %c0) | ||
scf.forall (%arg1, %arg2) in (1, 2) { | ||
%obj0 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_0_0} : memref<32x64xi32> -> !amdaie.logicalobjectfifo<memref<32x64xi32>> | ||
} | ||
return | ||
} | ||
} | ||
|
||
|
||
// ----- | ||
|
||
// CHECK-LABEL: @func_no_hoist | ||
// CHECK-SAME: %[[ARG0:.+]]: memref<32x64xi32> | ||
// CHECK: %[[C0:.+]] = arith.constant 0 : index | ||
// CHECK: scf.forall | ||
// CHECK: %[[TILE_0_0:.+]] = amdaie.tile(%[[C0]], %[[C0]]) | ||
// CHECK: amdaie.logicalobjectfifo.from_memref %[[ARG0]], {%[[TILE_0_0]]} | ||
module { | ||
func.func @func_no_hoist(%arg0: memref<32x64xi32>) { | ||
%c0 = arith.constant 0 : index | ||
scf.forall (%arg1, %arg2) in (1, 2) { | ||
%tile_0_0 = amdaie.tile(%c0, %c0) | ||
%obj0 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_0_0} : memref<32x64xi32> -> !amdaie.logicalobjectfifo<memref<32x64xi32>> | ||
} | ||
return | ||
} | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: @workgroup_hoist | ||
// CHECK-SAME: %[[ARG0:.+]]: memref<32x64xi32> | ||
// CHECK: amdaie.workgroup | ||
// CHECK: %[[C0:.+]] = arith.constant 0 : index | ||
// CHECK: %[[TILE_0_0:.+]] = amdaie.tile(%[[C0]], %[[C0]]) | ||
// CHECK: amdaie.logicalobjectfifo.from_memref %[[ARG0]], {%[[TILE_0_0]]} | ||
// CHECK: scf.forall | ||
// CHECK-NOT: amdaie.logicalobjectfifo.from_memref | ||
func.func @workgroup_hoist(%arg0: memref<32x64xi32>) { | ||
amdaie.workgroup { | ||
%c0 = arith.constant 0 : index | ||
%tile_0_0 = amdaie.tile(%c0, %c0) | ||
scf.forall (%arg1, %arg2) in (1, 2) { | ||
%obj0 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_0_0} : memref<32x64xi32> -> !amdaie.logicalobjectfifo<memref<32x64xi32>> | ||
} | ||
amdaie.controlcode { | ||
amdaie.end | ||
} | ||
} | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: @workgroup_no_hoist | ||
// CHECK-SAME: %[[ARG0:.+]]: memref<32x64xi32> | ||
// CHECK: amdaie.workgroup | ||
// CHECK: %[[C0:.+]] = arith.constant 0 : index | ||
// CHECK: scf.forall | ||
// CHECK: %[[TILE_0_0:.+]] = amdaie.tile(%[[C0]], %[[C0]]) | ||
// CHECK: amdaie.logicalobjectfifo.from_memref %[[ARG0]], {%[[TILE_0_0]]} | ||
func.func @workgroup_no_hoist(%arg0: memref<32x64xi32>) { | ||
amdaie.workgroup { | ||
%c0 = arith.constant 0 : index | ||
scf.forall (%arg1, %arg2) in (1, 2) { | ||
%tile_0_0 = amdaie.tile(%c0, %c0) | ||
%obj0 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_0_0} : memref<32x64xi32> -> !amdaie.logicalobjectfifo<memref<32x64xi32>> | ||
} | ||
amdaie.controlcode { | ||
amdaie.end | ||
} | ||
} | ||
return | ||
} | ||
// ----- | ||
|
||
// CHECK-LABEL: @workgroup_no_hoist_outside | ||
// CHECK-SAME: %[[ARG0:.+]]: memref<32x64xi32> | ||
// CHECK: %[[C0:.+]] = arith.constant 0 : index | ||
// CHECK: %[[TILE_0_0:.+]] = amdaie.tile(%[[C0]], %[[C0]]) | ||
// CHECK: amdaie.workgroup | ||
// CHECK: amdaie.logicalobjectfifo.from_memref %[[ARG0]], {%[[TILE_0_0]]} | ||
func.func @workgroup_no_hoist_outside(%arg0: memref<32x64xi32>) { | ||
%c0 = arith.constant 0 : index | ||
%tile_0_0 = amdaie.tile(%c0, %c0) | ||
amdaie.workgroup { | ||
%obj0 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_0_0} : memref<32x64xi32> -> !amdaie.logicalobjectfifo<memref<32x64xi32>> | ||
amdaie.controlcode { | ||
amdaie.end | ||
} | ||
} | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: @controlcode_hoist | ||
// CHECK-SAME: %[[ARG0:.+]]: memref<32x64xi32> | ||
// CHECK: amdaie.controlcode | ||
// CHECK: %[[C0:.+]] = arith.constant 0 : index | ||
// CHECK: %[[TILE_0_0:.+]] = amdaie.tile(%[[C0]], %[[C0]]) | ||
// CHECK: amdaie.logicalobjectfifo.from_memref %[[ARG0]], {%[[TILE_0_0]]} | ||
// CHECK: scf.forall | ||
// CHECK: scf.forall | ||
// CHECK-NOT: amdaie.logicalobjectfifo.from_memref | ||
func.func @controlcode_hoist(%arg0: memref<32x64xi32>) { | ||
amdaie.workgroup { | ||
amdaie.controlcode { | ||
%c0 = arith.constant 0 : index | ||
%tile_0_0 = amdaie.tile(%c0, %c0) | ||
scf.forall (%arg1, %arg2) in (1, 2) { | ||
scf.forall (%arg3, %arg4) in (1, 2) { | ||
%obj0 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_0_0} : memref<32x64xi32> -> !amdaie.logicalobjectfifo<memref<32x64xi32>> | ||
} | ||
} | ||
amdaie.end | ||
} | ||
} | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: @controlcode_partial_hoist | ||
// CHECK-SAME: %[[ARG0:.+]]: memref<32x64xi32> | ||
// CHECK: amdaie.controlcode | ||
// CHECK: %[[C0:.+]] = arith.constant 0 : index | ||
// CHECK: scf.forall | ||
// CHECK: %[[TILE_0_0:.+]] = amdaie.tile(%[[C0]], %[[C0]]) | ||
// CHECK: amdaie.logicalobjectfifo.from_memref %[[ARG0]], {%[[TILE_0_0]]} | ||
// CHECK: scf.forall | ||
// CHECK-NOT: amdaie.logicalobjectfifo.from_memref | ||
func.func @controlcode_partial_hoist(%arg0: memref<32x64xi32>) { | ||
amdaie.workgroup { | ||
amdaie.controlcode { | ||
%c0 = arith.constant 0 : index | ||
scf.forall (%arg1, %arg2) in (1, 2) { | ||
%tile_0_0 = amdaie.tile(%c0, %c0) | ||
scf.forall (%arg3, %arg4) in (1, 2) { | ||
%obj0 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_0_0} : memref<32x64xi32> -> !amdaie.logicalobjectfifo<memref<32x64xi32>> | ||
} | ||
} | ||
amdaie.end | ||
} | ||
} | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: @controlcode_no_hoist | ||
// CHECK-SAME: %[[ARG0:.+]]: memref<32x64xi32> | ||
// CHECK: amdaie.controlcode | ||
// CHECK: %[[C0:.+]] = arith.constant 0 : index | ||
// CHECK: scf.forall | ||
// CHECK: scf.forall | ||
// CHECK: %[[TILE_0_0:.+]] = amdaie.tile(%[[C0]], %[[C0]]) | ||
// CHECK: amdaie.logicalobjectfifo.from_memref %[[ARG0]], {%[[TILE_0_0]]} | ||
func.func @controlcode_no_hoist(%arg0: memref<32x64xi32>) { | ||
amdaie.workgroup { | ||
amdaie.controlcode { | ||
%c0 = arith.constant 0 : index | ||
scf.forall (%arg1, %arg2) in (1, 2) { | ||
scf.forall (%arg3, %arg4) in (1, 2) { | ||
%tile_0_0 = amdaie.tile(%c0, %c0) | ||
%obj0 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_0_0} : memref<32x64xi32> -> !amdaie.logicalobjectfifo<memref<32x64xi32>> | ||
} | ||
} | ||
amdaie.end | ||
} | ||
} | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: @controlcode_no_hoist_outside | ||
// CHECK-SAME: %[[ARG0:.+]]: memref<32x64xi32> | ||
// CHECK: %[[C0:.+]] = arith.constant 0 : index | ||
// CHECK: %[[TILE_0_0:.+]] = amdaie.tile(%[[C0]], %[[C0]]) | ||
// CHECK: amdaie.controlcode | ||
// CHECK: amdaie.logicalobjectfifo.from_memref %[[ARG0]], {%[[TILE_0_0]]} | ||
func.func @controlcode_no_hoist_outside(%arg0: memref<32x64xi32>) { | ||
amdaie.workgroup { | ||
%c0 = arith.constant 0 : index | ||
%tile_0_0 = amdaie.tile(%c0, %c0) | ||
amdaie.controlcode { | ||
%obj0 = amdaie.logicalobjectfifo.from_memref %arg0, {%tile_0_0} : memref<32x64xi32> -> !amdaie.logicalobjectfifo<memref<32x64xi32>> | ||
amdaie.end | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters