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

[Arc] Automatic module partition #7650

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions include/circt/Dialect/Arc/ArcOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,21 @@ def FinalOp : ClockTreeLikeOp<"final"> {
}];
}

//===----------------------------------------------------------------------===//
// Partition
//===----------------------------------------------------------------------===//

def TaskOp : ArcOp<"task", [
RecursiveMemoryEffects, NoTerminator, NoRegionArguments, SingleBlock,
// ParentOneOf<["ClockTreeOp", "ModelOp"]>
]> {
let summary = "A region reserved after the computation of different partitions";
let arguments = (ins
OptionalAttr<SymbolNameAttr>:$task_name
);
let regions = (region SizedRegion<1>:$body);
}

//===----------------------------------------------------------------------===//
// Storage Allocation
//===----------------------------------------------------------------------===//
Expand Down
2 changes: 2 additions & 0 deletions include/circt/Dialect/Arc/ArcPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ std::unique_ptr<mlir::Pass> createLowerVectorizationsPass(
LowerVectorizationsModeEnum mode = LowerVectorizationsModeEnum::Full);
std::unique_ptr<mlir::Pass> createMakeTablesPass();
std::unique_ptr<mlir::Pass> createMuxToControlFlowPass();
std::unique_ptr<mlir::Pass>
createPartitionPass(const PartitionOptions &opts = {});
std::unique_ptr<mlir::Pass> createPrintCostModelPass();
std::unique_ptr<mlir::Pass> createSimplifyVariadicOpsPass();
std::unique_ptr<mlir::Pass> createSplitLoopsPass();
Expand Down
12 changes: 12 additions & 0 deletions include/circt/Dialect/Arc/ArcPasses.td
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ def SimplifyVariadicOps : Pass<"arc-simplify-variadic-ops", "mlir::ModuleOp"> {
];
}

def Partition: Pass<"arc-partition", "arc::ModelOp"> {
let summary = "Partition the entire circuit into multiple chunks";
let options = [
Option<"chunks", "chunks", "unsigned", "1",
"Number of resulting chunks">
];
}

def PartitionClone: Pass<"arc-partition-clone", "arc::ModelOp"> {
let summary = "Commit the planned partition by cloning models";
}

def SplitFuncs : Pass<"arc-split-funcs", "mlir::ModuleOp"> {
let summary = "Split large funcs into multiple smaller funcs";
let dependentDialects = ["mlir::func::FuncDialect"];
Expand Down
22 changes: 20 additions & 2 deletions lib/Dialect/Arc/Transforms/AllocateState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,27 @@ void AllocateStatePass::allocateBlock(Block *block) {
LLVM_DEBUG(llvm::dbgs() << "- Visiting block in "
<< block->getParentOp()->getName() << "\n");

// The allocation should run in (reversed?) topo-sorted order for preexisting
// substorages to work correctly.

DenseSet<Value> allocated;
std::function<void(Value)> visit;
visit = [&](Value parent) {
if (allocated.contains(parent))
return;
for (auto childAlloc : opsByStorage[parent])
if (auto childStorageAlloc = dyn_cast<AllocStorageOp>(childAlloc)) {
auto child = childStorageAlloc.getResult();
if (opsByStorage.contains(child)) // Used by allocations in this block
visit(child);
}
allocateOps(parent, block, opsByStorage[parent]);
allocated.insert(parent);
};

// Actually allocate each operation.
for (auto &[storage, ops] : opsByStorage)
allocateOps(storage, block, ops);
for (auto &[storage, _] : opsByStorage)
visit(storage);
}

void AllocateStatePass::allocateOps(Value storage, Block *block,
Expand Down
1 change: 1 addition & 0 deletions lib/Dialect/Arc/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_circt_dialect_library(CIRCTArcTransforms
MakeTables.cpp
MergeIfs.cpp
MuxToControlFlow.cpp
Partition.cpp
PrintCostModel.cpp
SimplifyVariadicOps.cpp
SplitFuncs.cpp
Expand Down
Loading
Loading