Skip to content
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
23 changes: 20 additions & 3 deletions lib/NeuraDialect/Transforms/GenerateCodePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,24 @@ struct TileLocation {
// ---- Operation kind helpers ----.
static bool isDataMov(Operation *op) { return dyn_cast<DataMovOp>(op) != nullptr; }
static bool isCtrlMov(Operation *op) { return dyn_cast<CtrlMovOp>(op) != nullptr; }
static bool isPhi(Operation *op) { return dyn_cast<PhiOp>(op) != nullptr; }
static bool isPhiStart(Operation *op) { return dyn_cast<PhiStartOp>(op) != nullptr; }
static bool isReserve(Operation *op) { return dyn_cast<ReserveOp>(op) != nullptr; }
static bool isConstant(Operation *op) { return dyn_cast<ConstantOp>(op) != nullptr; }
// ---- Constant for phi_start operation ----.
static constexpr unsigned kReserveOpIndex = 1;

// Returns the reserve operand for phi_start (operand #1). Guards to ReserveOp.
static Value getReserveOperand(Operation *op) {
if (auto phi_start = dyn_cast<PhiStartOp>(op)) {
assert(op->getNumOperands() > kReserveOpIndex &&
"phi_start must have a reserve at operand #1");
Value candidate = phi_start->getOperand(kReserveOpIndex);
assert((!candidate || isa<ReserveOp>(candidate.getDefiningOp())) &&
"phi_start operand #1 must be a ReserveOp");
return candidate;
}
return Value();
}

// ----- placement helpers -----.
static TileLocation getTileLocation(Operation *op) {
Expand Down Expand Up @@ -453,8 +468,10 @@ struct GenerateCodePass
operation_placements[op] = getTileLocation(op);

// build reserve -> phi mapping.
if (isPhi(op) && op->getNumOperands() >= 1) {
reserve_to_phi_map[op->getOperand(0)] = op;
if (isPhiStart(op)) {
if (Value reserve = getReserveOperand(op)) {
reserve_to_phi_map[reserve] = op;
}
}

// collect forwarders.
Expand Down
4 changes: 2 additions & 2 deletions test/code_gen/test_code_generate.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func.func @loop_test() -> f32 {
// ASM-NEXT: DATA_MOV, [EAST, RED] -> [WEST, RED] (t=8, inv_iters=1)
// ASM-NEXT: } (idx_per_ii=3)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [WEST, RED], [UNRESOLVED, ERROR] -> [WEST, RED], [$0] (t=4, inv_iters=0)
// ASM-NEXT: PHI_START, [WEST, RED], [$0] -> [WEST, RED], [$0] (t=4, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=4)
// ASM: PE(2,1):
// ASM-NEXT: {
Expand All @@ -162,7 +162,7 @@ func.func @loop_test() -> f32 {
// ASM-NEXT: } (idx_per_ii=2)
// ASM: PE(0,2):
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [$0], [UNRESOLVED, ERROR] -> [SOUTH, RED] (t=5, inv_iters=1)
// ASM-NEXT: PHI_START, [$0], [SOUTH, RED] -> [SOUTH, RED] (t=5, inv_iters=1)
// ASM-NEXT: } (idx_per_ii=0)
// ASM-NEXT: {
// ASM-NEXT: CONSTANT, [#10] -> [$0] (t=1, inv_iters=0)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/bicg/bicg_kernel.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@
// ASM-NEXT: DATA_MOV, [WEST, RED] -> [$3] (t=8, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=8)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [$0], [UNRESOLVED, ERROR] -> [$0] (t=9, inv_iters=0)
// ASM-NEXT: PHI_START, [$0], [$2] -> [$0] (t=9, inv_iters=0)
// ASM-NEXT: DATA_MOV, [WEST, RED] -> [EAST, RED] (t=9, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=9)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [$0], [UNRESOLVED, ERROR] -> [$4], [$0] (t=10, inv_iters=0)
// ASM-NEXT: PHI_START, [$0], [$1] -> [$4], [$0] (t=10, inv_iters=0)
// ASM-NEXT: DATA_MOV, [WEST, RED] -> [$1] (t=10, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=10)

Expand Down
17 changes: 14 additions & 3 deletions test/e2e/fir/fir_kernel.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@
// YAML-NEXT: dst_operands:
// YAML-NEXT: - operand: "$0"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - opcode: "CTRL_MOV"
// YAML-NEXT: id: 39
// YAML-NEXT: time_step: 8
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
// YAML-NEXT: - operand: "EAST"
// YAML-NEXT: color: "RED"
// YAML-NEXT: dst_operands:
// YAML-NEXT: - operand: "$1"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - index_per_ii: 4
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "PHI_START"
Expand All @@ -103,8 +113,8 @@
// YAML-NEXT: src_operands:
// YAML-NEXT: - operand: "$0"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - operand: "UNRESOLVED"
// YAML-NEXT: color: "ERROR"
// YAML-NEXT: - operand: "EAST"
// YAML-NEXT: color: "RED"
// YAML-NEXT: dst_operands:
// YAML-NEXT: - operand: "EAST"
// YAML-NEXT: color: "RED"
Expand All @@ -114,9 +124,10 @@
// ASM: PE(0,1):
// ASM-NEXT: {
// ASM-NEXT: GRANT_ONCE, [#0] -> [$0] (t=3, inv_iters=0)
// ASM-NEXT: CTRL_MOV, [EAST, RED] -> [$1] (t=8, inv_iters=1)
// ASM-NEXT: } (idx_per_ii=3)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [$0], [UNRESOLVED, ERROR] -> [EAST, RED] (t=4, inv_iters=0)
// ASM-NEXT: PHI_START, [$0], [EAST, RED] -> [EAST, RED] (t=4, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=4)
// ASM: PE(1,1):
// ASM-NEXT: {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/fir/fir_kernel_vec.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
// YAML-NEXT: src_operands:
// YAML-NEXT: - operand: "$0"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - operand: "UNRESOLVED"
// YAML-NEXT: color: "ERROR"
// YAML-NEXT: - operand: "EAST"
// YAML-NEXT: color: "RED"
// YAML-NEXT: dst_operands:
// YAML-NEXT: - operand: "EAST"
// YAML-NEXT: color: "RED"
Expand All @@ -119,7 +119,7 @@
// ASM-NEXT: GRANT_ONCE, [] -> [$0] (t=3, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=3)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [$0], [UNRESOLVED, ERROR] -> [EAST, RED] (t=4, inv_iters=0)
// ASM-NEXT: PHI_START, [$0], [EAST, RED] -> [EAST, RED] (t=4, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=4)
// ASM: PE(1,1):
// ASM-NEXT: {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/histogram/histogram_kernel.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
// ASM-NEXT: GRANT_ONCE, [#0] -> [$0] (t=0, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=0)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [$0], [UNRESOLVED, ERROR] -> [WEST, RED], [$0] (t=1, inv_iters=0)
// ASM-NEXT: PHI_START, [$0], [WEST, RED] -> [WEST, RED], [$0] (t=1, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=1)
// ASM-NEXT: {
// ASM-NEXT: ADD, [$0], [#1] -> [$0], [WEST, RED] (t=2, inv_iters=0)
Expand Down
4 changes: 2 additions & 2 deletions test/mapping_quality/branch_for.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ func.func @loop_test() -> f32 {
// ASM-NEXT: GRANT_PREDICATE, [$0], [NORTH, RED] -> [$0] (t=4, inv_iters=1)
// ASM-NEXT: } (idx_per_ii=0)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [WEST, RED], [UNRESOLVED, ERROR] -> [NORTH, RED] (t=1, inv_iters=0)
// ASM-NEXT: PHI_START, [WEST, RED], [$0] -> [NORTH, RED] (t=1, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=1)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [WEST, RED], [UNRESOLVED, ERROR] -> [NORTH, RED], [WEST, RED] (t=2, inv_iters=0)
// ASM-NEXT: PHI_START, [WEST, RED], [NORTH, RED] -> [NORTH, RED], [WEST, RED] (t=2, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=2)
// ASM-NEXT: {
// ASM-NEXT: DATA_MOV, [NORTH, RED] -> [$0] (t=3, inv_iters=0)
Expand Down
4 changes: 2 additions & 2 deletions test/neura/ctrl/branch_for.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ func.func @loop_test() -> f32 {
// ASM-NEXT: GRANT_ONCE, [#0.000000] -> [$0] (t=2, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=2)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [$0], [UNRESOLVED, ERROR] -> [EAST, RED] (t=3, inv_iters=0)
// ASM-NEXT: PHI_START, [$0], [NORTH, RED] -> [EAST, RED] (t=3, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=3)
// ASM: PE(1,0):
// ASM-NEXT: {
// ASM-NEXT: FADD, [WEST, RED], [#3.000000] -> [WEST, RED], [EAST, RED] (t=4, inv_iters=1)
// ASM-NEXT: } (idx_per_ii=0)
// ASM-NEXT: {
// ASM-NEXT: PHI_START, [WEST, RED], [UNRESOLVED, ERROR] -> [$0] (t=1, inv_iters=0)
// ASM-NEXT: PHI_START, [WEST, RED], [NORTH, RED] -> [$0] (t=1, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=1)
// ASM-NEXT: {
// ASM-NEXT: ADD, [$0], [#1] -> [$0], [NORTH, RED] (t=2, inv_iters=0)
Expand Down