-
Notifications
You must be signed in to change notification settings - Fork 14
Enable the safe return in neura dataflow ir #223
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
base: main
Are you sure you want to change the base?
Conversation
| Example: | ||
| neura.return_void %cond : !neura.data<i1, i1> // In dataflow mode | ||
|
|
||
| This is NOT a terminator - the block ends with neura.yield instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then where is yield? Can the neura.yield be also shown in above example?
|
|
||
| // Looks for any suitable value in the predecessor block. | ||
| if (op.getNumResults() > 0) { | ||
| trigger_value = op.getResult(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elaborate on the "suitable value"? This line seems any op can serve as trigger_value, is this sufficient?
| builder.create<neura::CondBr>( | ||
| cond_br.getLoc(), cond_br.getCondition(), true_args, false_args, | ||
| cond_br.getTrueDest(), cond_br.getFalseDest()); | ||
| cond_br.erase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we need to or all the cond_br's conditions?
| // Handles cond_preds: adds a block argument for the trigger value, and | ||
| // updates each predecessor's terminator to pass the trigger value. | ||
| BlockArgument trigger_arg = | ||
| ret_block->addArgument(builder.getI1Type(), void_ret_op.getLoc()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
triggering value is getI1Type? I thought it is or of all conditions, and needs to be a regular type, i.e., <data, predicate>?
| } | ||
|
|
||
| Value getPrecessedCondition(Value condition, bool is_not_condition, | ||
| Value getProcessedCondition(Value condition, bool is_not_condition, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remind me why do we need this getProcessedCondition()?
| llvm::errs() << "[ctrl2data] Converting neura.return operations to " | ||
| "return_void/value...\n"; | ||
|
|
||
| for (neura::ReturnOp return_op : return_ops) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason that we can't have one pass (e.g., canonicalize_return_pass) to handle the transformation? Because canonicalize_return_pass touches condition, and condition would be transformed in ctrl2data_pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this? Can't this test be updated/fixed?
| //MAPPING: func.func @kernel | ||
| //MAPPING-SAME: accelerator = "neura", dataflow_mode = "predicate" | ||
| //MAPPING-SAME: mapping_info = {compiled_ii = 11 : i32, mapping_mode = "spatial-temporal", mapping_strategy = "heuristic", rec_mii = 9 : i32, res_mii = 5 : i32, x_tiles = 4 : i32, y_tiles = 4 : i32} | ||
| //MAPPING-SAME: mapping_info = {compiled_ii = 13 : i32, mapping_mode = "spatial-temporal", mapping_strategy = "heuristic", rec_mii = 9 : i32, res_mii = 6 : i32, x_tiles = 4 : i32, y_tiles = 4 : i32} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
II increased due to more cond ops are added?
In this pr:
Introduce two kinds of return ops in neura dataflow ir:
neura.return_void: its operand means the trigger valuesneura.return_value: its operand means the returned valuesThese two kinds of return ops are only enabled in dataflow ir. In conventional neural CDFG ir, we still use the
neura.return.We create a
canonicalize-returnpass to mark the type (return_type = void/value) ofneura.return. AndWe introduce some logic in the
transform-ctrl-to-data-flowpass to transform theneura.returntoneura.return_value/return_voidA
neura.yieldis added at each flattened block's end to act like a terminator for the block. This is just to obey the rules in MLIR block https://mlir.llvm.org/docs/LangRef/#blocks.TODO: Enable the interpreter for these two introduced ops. Since this pr is too large, I will make a separate pr for that.