-
Notifications
You must be signed in to change notification settings - Fork 15
Support Steering-Control-Based Dataflow Representation & Mapping #144
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5ff1133
prototype steer control transformation
ShangkunLi 6a3bb7a
add comments
ShangkunLi 57b7f7e
add test for steer control transform
ShangkunLi a4316f6
support steer control mapping
ShangkunLi 7eec1c2
[clean] remove some debugging code
ShangkunLi b0c5874
add dataflow mode attribute
ShangkunLi 773a4a6
add test for true/false_steer
ShangkunLi 7970c7a
[fix] fix some erros in transform
ShangkunLi d32dcc2
add dataflow mode checking
ShangkunLi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tancheng marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
lib/NeuraDialect/Transforms/RemovePredicatedTypePass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| #include "NeuraDialect/NeuraDialect.h" | ||
| #include "NeuraDialect/NeuraOps.h" | ||
| #include "NeuraDialect/NeuraPasses.h" | ||
| #include "NeuraDialect/NeuraTypes.h" | ||
| #include "mlir/Dialect/Func/IR/FuncOps.h" | ||
| #include "mlir/IR/PatternMatch.h" | ||
| #include "mlir/Pass/Pass.h" | ||
| #include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
|
|
||
| using namespace mlir; | ||
|
|
||
| #define GEN_PASS_DEF_REMOVEPREDICATEDTYPE | ||
| #include "NeuraDialect/NeuraPasses.h.inc" | ||
|
|
||
| namespace { | ||
|
|
||
| struct RemovePredicatedTypePass | ||
| : public PassWrapper<RemovePredicatedTypePass, OperationPass<ModuleOp>> { | ||
| MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(RemovePredicatedTypePass) | ||
|
|
||
| StringRef getArgument() const override { return "remove-predicated-type"; } | ||
| StringRef getDescription() const override { | ||
| return "Remove predicated types from Neura dialect operations, reverting " | ||
| "to basic types."; | ||
| } | ||
|
|
||
| void runOnOperation() override { | ||
| ModuleOp module = getOperation(); | ||
|
|
||
| // Processes each function. | ||
| module.walk([&](FunctionOpInterface func) { | ||
| auto accel_attr = func->getAttrOfType<StringAttr>("accelerator"); | ||
| if (!accel_attr || accel_attr.getValue() != "neura") { | ||
| return; | ||
| } | ||
|
|
||
| // Converts block arguments. | ||
| func.walk([&](Block *block) { | ||
| // Processes block arguments. | ||
| for (BlockArgument arg : block->getArguments()) { | ||
| Type orig_type = arg.getType(); | ||
| if (auto predicated_type = | ||
| llvm::dyn_cast<neura::PredicatedValue>(orig_type)) { | ||
| arg.setType(predicated_type.getValueType()); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| // Gets operations in topological order. | ||
| SmallVector<Operation *> ordered_ops; | ||
| getOperationsInTopologicalOrder(func, ordered_ops); | ||
|
|
||
| // Processes each operation in topological order. | ||
| for (Operation *op : ordered_ops) { | ||
| if (failed(removePredicatedType(op))) { | ||
| llvm::errs() << "Failed to convert op from predicated form: " << *op | ||
| << "\n"; | ||
| signalPassFailure(); | ||
| return; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private: | ||
| // Gets operations in topological order. | ||
| void getOperationsInTopologicalOrder(FunctionOpInterface func, | ||
| SmallVector<Operation *> &ordered_ops) { | ||
| DenseSet<Operation *> visited_ops; | ||
| func.walk<WalkOrder::PreOrder>([&](Operation *op) { | ||
| if (visited_ops.contains(op)) { | ||
| return; | ||
| } | ||
|
|
||
| // Visits operands first. | ||
| for (Value operand : op->getOperands()) { | ||
| if (Operation *def_op = operand.getDefiningOp()) { | ||
| if (!visited_ops.contains(def_op)) { | ||
| visited_ops.insert(def_op); | ||
| ordered_ops.push_back(def_op); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!visited_ops.contains(op)) { | ||
| visited_ops.insert(op); | ||
| ordered_ops.push_back(op); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // Converts a single operation from predicated to normal types. | ||
| LogicalResult removePredicatedType(Operation *op) { | ||
| // Skips if not a Neura op. | ||
| if (op->getDialect()->getNamespace() != "neura") { | ||
| return success(); | ||
| } | ||
|
|
||
| // Skips if no results or no predicated types. | ||
| if (op->getNumResults() == 0 || | ||
| !llvm::any_of(op->getResultTypes(), [](Type t) { | ||
| return mlir::isa<mlir::neura::PredicatedValue>(t); | ||
| })) { | ||
| return success(); | ||
| } | ||
|
|
||
| // Converts result types to non-predicated form. | ||
| OpBuilder builder(op); | ||
| SmallVector<Type> new_results; | ||
| for (Type t : op->getResultTypes()) { | ||
| if (auto predicated_type = llvm::dyn_cast<neura::PredicatedValue>(t)) { | ||
| new_results.push_back(predicated_type.getValueType()); | ||
| } else { | ||
| new_results.push_back(t); | ||
| } | ||
| } | ||
|
|
||
| // Creates new operation with updated result types. | ||
| OperationState state(op->getLoc(), op->getName()); | ||
| state.addOperands(op->getOperands()); | ||
| state.addTypes(new_results); | ||
| state.addAttributes(op->getAttrs()); | ||
|
|
||
| // Copies regions if needed. | ||
| for (unsigned i = 0; i < op->getNumRegions(); ++i) { | ||
| state.addRegion(); | ||
| } | ||
|
|
||
| Operation *new_op = builder.create(state); | ||
|
|
||
| // Moves regions if any. | ||
| for (unsigned i = 0; i < op->getNumRegions(); ++i) { | ||
| Region &old_region = op->getRegion(i); | ||
| Region &new_region = new_op->getRegion(i); | ||
| new_region.takeBody(old_region); | ||
| } | ||
|
|
||
| // Replaces old op. | ||
| op->replaceAllUsesWith(new_op); | ||
| op->erase(); | ||
| return success(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| namespace mlir { | ||
| namespace neura { | ||
|
|
||
| std::unique_ptr<Pass> createRemovePredicatedTypePass() { | ||
| return std::make_unique<RemovePredicatedTypePass>(); | ||
| } | ||
|
|
||
| } // namespace neura | ||
| } // namespace mlir |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.