-
Notifications
You must be signed in to change notification settings - Fork 33
[Tune] Introduce tpp-tune #1059
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
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f73990d
[Tune] Introduce tpp-tune
rolfmorel df10928
transform.tune.select has semantics when there is a single "choice"
rolfmorel a4306d4
Add --pack-block-factors cmd arg to control -pack-matmul options
rolfmorel 55ef828
Remove extraneous pprint
rolfmorel c4f0fbb
Make choices randomly
rolfmorel d80f2ba
Detect name collision
rolfmorel b5681dd
transform.tune.pick: tune.select but without forgetting the options
rolfmorel 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| from .._mlir_libs import get_dialect_registry | ||
| from .._mlir_libs._tppDialects.tune import register_dialect | ||
| from .._mlir_libs._tppDialects.tune import * | ||
|
|
||
| register_dialect(get_dialect_registry()) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,17 @@ | ||
| from mlir.dialects import transform | ||
| from mlir.dialects.transform import structured | ||
| from mlir.dialects.transform import structured, tune | ||
|
|
||
|
|
||
| # Wrapper to addresss verbosity. | ||
| def apply_registered_pass(*args, **kwargs): | ||
| return transform.apply_registered_pass(transform.AnyOpType.get(), *args, **kwargs) | ||
|
|
||
|
|
||
| # Wrapper to addresss verbosity. | ||
| def select(*args, **kwargs): | ||
| return tune.select(transform.AnyParamType.get(), *args, **kwargs) | ||
adam-smnk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # Wrapper to addresss verbosity. | ||
| def match(*args, **kwargs): | ||
| return structured.MatchOp(transform.AnyOpType.get(), *args, **kwargs) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| file(MAKE_DIRECTORY | ||
| ${CMAKE_BINARY_DIR}/bin) | ||
| file(CREATE_LINK | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/tpp-tune.py | ||
| ${CMAKE_BINARY_DIR}/bin/tpp-tune | ||
| SYMBOLIC) | ||
|
|
||
|
|
||
| add_custom_target(tpp-tune DEPENDS ${CMAKE_BINARY_DIR}/bin/tpp-tune TPPPythonModules) |
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,70 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
| from typing import Union, Sequence, Dict | ||
| from pprint import pprint | ||
|
|
||
|
|
||
| # Enable automagically finding TPP-MLIR's python modules (which include | ||
| # and extend MLIR's Python bindings). | ||
| python_packages_path = Path(__file__).parent.parent / "python_packages" | ||
| if python_packages_path.exists(): | ||
| sys.path = [str(python_packages_path)] + sys.path | ||
|
|
||
|
|
||
| from mlir import ir | ||
| from mlir.dialects import transform | ||
| from mlir.dialects.transform import tune as transform_tune | ||
|
|
||
|
|
||
| def walker(f): | ||
| def wrapper(op: Union[ir.OpView, ir.Operation]): | ||
| f(op) | ||
| for region in op.regions: | ||
| for block in region.blocks: | ||
| for child_op in block: | ||
| wrapper(child_op) | ||
|
|
||
| return wrapper | ||
|
|
||
|
|
||
| def autotune(choices: Dict[str, Sequence[ir.Attribute]]) -> Dict[str, ir.Attribute]: | ||
| # Aint tuning easy!! | ||
| return {key: values[0] for key, values in choices.items()} | ||
|
||
|
|
||
|
|
||
| file = sys.stdin | ||
| if len(sys.argv) > 1 and sys.argv[1] != "-": | ||
| file = open(sys.argv[1]) | ||
|
|
||
|
|
||
| with ir.Context(), ir.Location.unknown(): | ||
| schedule = ir.Module.parse(file.read()) | ||
|
|
||
| choices = {} | ||
|
|
||
| @walker | ||
| def choices_finder(op): | ||
| if isinstance(op, transform_tune.TuneSelectOp): | ||
| choices[op.name] = tuple(op.options) | ||
|
|
||
| choices_finder(schedule.operation) | ||
|
|
||
| pprint(choices, stream=sys.stderr) | ||
|
|
||
| selected = autotune(choices) | ||
|
|
||
| @walker | ||
| def selected_rewriter(op: Union[ir.OpView, ir.Operation]): | ||
| if isinstance(op, transform_tune.TuneSelectOp): | ||
| with ir.InsertionPoint(op): | ||
| param = transform.param_constant( | ||
| transform.AnyParamType.get(), selected[op.name] | ||
| ) | ||
| for use in op.result.uses: | ||
| use.owner.operands[use.operand_number] = param | ||
|
|
||
| selected_rewriter(schedule.operation) | ||
|
|
||
| print(schedule) | ||
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.