-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[MLIR][Transform][Python] expose transform.debug extension in Python #145550
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d502b35
[MLIR][Transform][Python] expose transform.debug extension in Python
rolfmorel 3cdc540
Formatting fix
rolfmorel 45eaa96
Remove Debug... prefix from ops
rolfmorel 25edc5c
Remove extraneous lines, per Alex's review
rolfmorel 1c87e8d
Formatting fix
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
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,19 @@ | ||
| //===-- TransformDebugExtensionOps.td - Binding entry point *- tablegen -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Entry point of the generated Python bindings for the Debug extension of the | ||
| // Transform dialect. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef PYTHON_BINDINGS_TRANSFORM_DEBUG_EXTENSION_OPS | ||
| #define PYTHON_BINDINGS_TRANSFORM_DEBUG_EXTENSION_OPS | ||
|
|
||
| include "mlir/Dialect/Transform/DebugExtension/DebugExtensionOps.td" | ||
|
|
||
| #endif // PYTHON_BINDINGS_TRANSFORM_DEBUG_EXTENSION_OPS |
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,81 @@ | ||
| # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| # See https://llvm.org/LICENSE.txt for license information. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from ...ir import Attribute, Operation, Value, StringAttr | ||
| from .._transform_debug_extension_ops_gen import * | ||
| from .._transform_pdl_extension_ops_gen import _Dialect | ||
|
|
||
| try: | ||
| from .._ods_common import _cext as _ods_cext | ||
| except ImportError as e: | ||
| raise RuntimeError("Error loading imports from extension module") from e | ||
|
|
||
| from typing import Union | ||
|
|
||
|
|
||
| @_ods_cext.register_operation(_Dialect, replace=True) | ||
| class EmitParamAsRemarkOp(EmitParamAsRemarkOp): | ||
| def __init__( | ||
| self, | ||
| param: Attribute, | ||
| *, | ||
| anchor: Optional[Operation] = None, | ||
| message: Optional[Union[StringAttr, str]] = None, | ||
| loc=None, | ||
| ip=None, | ||
| ): | ||
| if isinstance(message, str): | ||
| message = StringAttr.get(message) | ||
|
|
||
| super().__init__( | ||
| param, | ||
| anchor=anchor, | ||
| message=message, | ||
| loc=loc, | ||
| ip=ip, | ||
| ) | ||
|
|
||
|
|
||
| def emit_param_as_remark( | ||
| param: Attribute, | ||
| *, | ||
| anchor: Optional[Operation] = None, | ||
| message: Optional[Union[StringAttr, str]] = None, | ||
| loc=None, | ||
| ip=None, | ||
| ): | ||
| return EmitParamAsRemarkOp(param, anchor=anchor, message=message, loc=loc, ip=ip) | ||
|
|
||
|
|
||
| @_ods_cext.register_operation(_Dialect, replace=True) | ||
| class EmitRemarkAtOp(EmitRemarkAtOp): | ||
| def __init__( | ||
| self, | ||
| at: Union[Operation, Value], | ||
| message: Optional[Union[StringAttr, str]] = None, | ||
| *, | ||
| loc=None, | ||
| ip=None, | ||
| ): | ||
| if isinstance(message, str): | ||
| message = StringAttr.get(message) | ||
|
|
||
| super().__init__( | ||
| at, | ||
| message, | ||
| loc=loc, | ||
| ip=ip, | ||
| ) | ||
|
|
||
|
|
||
| def emit_remark_at( | ||
| at: Union[Operation, Value], | ||
| message: Optional[Union[StringAttr, str]] = None, | ||
| *, | ||
| loc=None, | ||
| ip=None, | ||
| ): | ||
| return EmitRemarkAtOp(at, message, loc=loc, ip=ip) |
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,45 @@ | ||
| # RUN: %PYTHON %s | FileCheck %s | ||
|
|
||
| from mlir.ir import * | ||
| from mlir.dialects import transform | ||
| from mlir.dialects.transform import debug | ||
|
|
||
|
|
||
| def run(f): | ||
| print("\nTEST:", f.__name__) | ||
| with Context(), Location.unknown(): | ||
| module = Module.create() | ||
| with InsertionPoint(module.body): | ||
| sequence = transform.SequenceOp( | ||
| transform.FailurePropagationMode.Propagate, | ||
| [], | ||
| transform.AnyOpType.get(), | ||
| ) | ||
| with InsertionPoint(sequence.body): | ||
| f(sequence.bodyTarget) | ||
| transform.YieldOp() | ||
| print(module) | ||
| return f | ||
|
|
||
|
|
||
| @run | ||
| def testDebugEmitParamAsRemark(target): | ||
| i0 = IntegerAttr.get(IntegerType.get_signless(32), 0) | ||
| i0_param = transform.ParamConstantOp(transform.AnyParamType.get(), i0) | ||
| debug.emit_param_as_remark(i0_param) | ||
| debug.emit_param_as_remark(i0_param, anchor=target, message="some text") | ||
| # CHECK-LABEL: TEST: testDebugEmitParamAsRemark | ||
| # CHECK: ^{{.*}}(%[[ARG0:.+]]: !transform.any_op): | ||
| # CHECK: %[[PARAM:.*]] = transform.param.constant | ||
| # CHECK: transform.debug.emit_param_as_remark %[[PARAM]] | ||
| # CHECK: transform.debug.emit_param_as_remark %[[PARAM]] | ||
| # CHECK-SAME: "some text" | ||
| # CHECK-SAME: at %[[ARG0]] | ||
|
|
||
|
|
||
| @run | ||
| def testDebugEmitRemarkAtOp(target): | ||
| debug.emit_remark_at(target, "some text") | ||
| # CHECK-LABEL: TEST: testDebugEmitRemarkAtOp | ||
| # CHECK: ^{{.*}}(%[[ARG0:.+]]: !transform.any_op): | ||
| # CHECK: transform.debug.emit_remark_at %[[ARG0]], "some text" |
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.