Skip to content
Closed
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
20 changes: 20 additions & 0 deletions test/neura/interpreter/phiOp_interpret.mlir
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rename the test as phi_interpret.mlir.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: neura-interpreter %s | FileCheck %s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we run mlir-neura-opt with --assign-accelerator --leverage-predicated-value so the IR would contain PredicatedValue as https://github.com/coredac/dataflow/blob/64e7b3537cc5de007ec81b706c67cb20f0ce2860/test/neura/ctrl/branch_no_arg.mlir#L62
and then run neura-interpreter again to double check?

module {
func.func @test_phi() -> f32 {
%true_path_val = "neura.constant"() <{
value = 10.0 : f32,
predicate = true
}> : () -> f32

%false_path_val = "neura.constant"() <{
value = 20.0 : f32,
predicate = false
}> : () -> f32

%result = "neura.phi"(%true_path_val, %false_path_val) : (f32, f32) -> f32

return %result : f32
// CHECK: [neura-interpreter] Output: 10.000000
}
}
11 changes: 11 additions & 0 deletions tools/neura-interpreter/neura-interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ int main(int argc, char **argv) {

valueMap[constOp.getResult()] = val;

} else if (auto phiOp = dyn_cast<neura::PhiOp>(op)) {
PredicatedData result{0.0f, false}; // Default to a false predicate.
// Find the one operand with a true predicate.
for (Value operand : phiOp.getOperands()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we assert there must be at most one operand with predicate as true?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plz hold on, let me re-think the design. Its current form cannot support the diagram shown in README: https://github.com/tancheng/CGRA-Mapper

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I introduced grant_predicate and grant_once in #39, so we don't need to complicate phi's definition for now, so you are good to go: "assert there must be at most one operand with predicate as true".

Later on, we can introduce new op to fuse the (phi and grant_once and const) if needed.

auto incoming = valueMap[operand];
if (incoming.predicate) {
result = incoming;
break; // Found the active value.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move the comment above the if.

}
}
valueMap[phiOp.getResult()] = result;
} else if (auto movOp = dyn_cast<neura::DataMovOp>(op)) {
valueMap[movOp.getResult()] = valueMap[movOp.getOperand()];

Expand Down