Skip to content
Open
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
26 changes: 26 additions & 0 deletions include/PTO/IR/PTOOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,32 @@ def WaitFlagOp : PTO_Op<"wait_flag"> {
}];
}

def SetFlagDynOp : PTO_Op<"set_flag_dyn"> {
let summary = "Set synchronization flag between pipes (dynamic event id)";
let arguments = (ins
PTO_PipeAttr:$src_pipe,
PTO_PipeAttr:$dst_pipe,
Index:$event_id
);
let results = (outs);
let assemblyFormat = [{
`[` $src_pipe `,` $dst_pipe `,` $event_id `]` attr-dict
}];
}

def WaitFlagDynOp : PTO_Op<"wait_flag_dyn"> {
let summary = "Wait for synchronization flag (dynamic event id)";
let arguments = (ins
PTO_PipeAttr:$src_pipe,
PTO_PipeAttr:$dst_pipe,
Index:$event_id
);
let results = (outs);
let assemblyFormat = [{
`[` $src_pipe `,` $dst_pipe `,` $event_id `]` attr-dict
}];
}

Copy link
Contributor

Choose a reason for hiding this comment

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

新增op务必同时更新文档 docs/PTO_IR_manual.md

//===----------------------------------------------------------------------===//
// Buffer-ID Synchronization (A5)
//===----------------------------------------------------------------------===//
Expand Down
22 changes: 22 additions & 0 deletions include/PTO/Transforms/InsertSync/MultiBufferSelector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef MLIR_DIALECT_PTO_TRANSFORMS_INSERTSYNC_MULTIBUFFERSELECTOR_H
#define MLIR_DIALECT_PTO_TRANSFORMS_INSERTSYNC_MULTIBUFFERSELECTOR_H

#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/IR/PatternMatch.h"

namespace mlir {
namespace pto {

/// Build a boolean `cond` that flips between even/odd iterations across a loop
/// nest.
///
/// - The condition is inserted at the beginning of `baseLoop`'s body.
/// - The computed parity is based on a flattened linear index across `baseLoop`
/// and all its parent `scf.for` loops, supporting non-unit steps.
/// - Returns a null Value if `baseLoop` is invalid.
Value buildLoopNestParityCond(IRRewriter &rewriter, scf::ForOp baseLoop);

} // namespace pto
} // namespace mlir

#endif // MLIR_DIALECT_PTO_TRANSFORMS_INSERTSYNC_MULTIBUFFERSELECTOR_H
3 changes: 0 additions & 3 deletions include/PTO/Transforms/InsertSync/SyncCodegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class SyncCodegen {
Value GetBufferSelected(IRRewriter &rewriter, Operation *op,
SyncOperation *sync);

// 生成嵌套循环的计数器 (用于多缓冲切换)
Value createNestedIndexModular(IRRewriter &rewriter, Operation *defineOp);

private:
SyncIRs &syncIR_;
func::FuncOp func_;
Expand Down
1 change: 1 addition & 0 deletions include/PTO/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ std::unique_ptr<Pass> createLoweringSyncToPipePass();

// Creates a pass for ...
std::unique_ptr<Pass> createPTOInsertSyncPass();
std::unique_ptr<Pass> createPTOEnableMultiBufferPass();
// Default arch is A3 unless overridden by callers.
std::unique_ptr<Pass> createEmitPTOManualPass();
// Explicitly select target arch for codegen.
Expand Down
17 changes: 17 additions & 0 deletions include/PTO/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ def PTOInsertSync : Pass<"pto-insert-sync", "func::FuncOp"> {
];
}

def PTOEnableMultiBuffer : Pass<"pto-enable-multibuffer", "func::FuncOp"> {
let summary = "Materialize multi-buffer (ping/pong) selection";
let description = [{
Rewrites `pto.pointer_cast(addrs=[ping,pong])` into a loop-local selector
that dynamically picks the active address. This enables planned ping/pong
buffers to take effect in the emitted C++.
}];

let constructor = "mlir::pto::createPTOEnableMultiBufferPass()";

let dependentDialects = [
"mlir::pto::PTODialect",
"mlir::arith::ArithDialect",
"mlir::scf::SCFDialect"
];
}

def ConvertToPTOOp : Pass<"convert-to-pto-op"> {
let summary = "Convert Ops from other dialects to PTO Ops";
let constructor = "mlir::pto::createConvertToPTOOpPass()";
Expand Down
2 changes: 2 additions & 0 deletions lib/PTO/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_mlir_dialect_library(PTOTransforms
AllocToPointerCast.cpp
InferPTOMemScope.cpp
PTOPlanMemory.cpp
EnableMultiBuffer.cpp
PTORemoveRedundantBarrier.cpp
InferPTOLayout.cpp
BufferizableOpInterfaceImpl.cpp
Expand All @@ -22,6 +23,7 @@ add_mlir_dialect_library(PTOTransforms
InsertSync/InsertSyncAnalysis.cpp
InsertSync/MemoryDependentAnalyzer.cpp
InsertSync/MoveSyncState.cpp
InsertSync/MultiBufferSelector.cpp
InsertSync/RemoveRedundantSync.cpp
InsertSync/SyncEventIdAllocation.cpp
InsertSync/SyncCodegen.cpp
Expand Down
Loading