Skip to content

[TIR][Schedule] Transform layout quality of life - #11269

Merged
vinx13 merged 23 commits into
apache:mainfrom
Lunderberg:transform_layout_quality_of_life
May 26, 2022
Merged

[TIR][Schedule] Transform layout quality of life#11269
vinx13 merged 23 commits into
apache:mainfrom
Lunderberg:transform_layout_quality_of_life

Conversation

@Lunderberg

@LunderbergLunderberg commented May 10, 2022

Copy link
Copy Markdown
Contributor

Draft PR, seeing whether some of the TE-specific interface features can be pulled over into the TIR-based schedules. These are implemented as Schedule.transform_layout_sugared, which wraps around the existing Schedule.transform_layout.

  • Specify buffer by name, rather than by access_type/index.
  • Optional specify block by name, rather than needing a separate call to Schedule.get_block.
  • Enable *args in the index mapping function.
  • Allow AXIS_SEPARATOR in the index mapping function, delegate to Schedule.set_axis_separators

@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

@vinx13 A draft of some ease-of-use changes I'd been experimenting with this afternoon. These are python-only, and unpack to the same C++ calls, so it (hopefully) shouldn't cause issues elsewhere.

@vinx13

vinx13 commented May 10, 2022

Copy link
Copy Markdown
Member

This is super cool, thanks for the PR. Shall we consider more informative names on what's being sugared. For example, axis_separators are related to physical layout, do you think something like transform_to_physical_layout would be more meaningful? Feel free to come up with better names

@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

I'd definitely be up for a better name, as transform_layout_sugared definitely leaves the reader uncertain what is being done. My one concern with having a completely different name is that it may not be clear to a reader that this is the same underlying schedule primitive in C++.

Another alternative would be to merge this as the input handling of Schedule.transform_layout. There's already some handling, such as the conversion from Callable to IndexMap, so this would be similar python-only handling. This would also avoid the issue of having multiple functions that aren't immediately obvious as wrappers around each other.

@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

Something sort of like the changes here are what I'm picturing. Not complete, because Union[Tuple[int,str],str] breaks the @type_checked annotation, but something sort of like this.

@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

#11289 should resolve the type-checking annotation issue with Tuples, if we want to go forward with the other changes here.

@Lunderberg
Lunderbergforce-pushed the transform_layout_quality_of_life branch from 5ce8acb to ec66ff1CompareMay 16, 2022 13:48
@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

CI functionality tests all passed, updates to resolve sphinx documentation tests, and rebase to resolve merge conflict.

buffer_index: int,
buffer_index_type: str,
block: Union[BlockRV, str],
buffer: Union[Tuple[str, int], str, Buffer],

@vinx13vinx13May 17, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this will break trace to python conversion. It is implemented here https://github.com/apache/tvm/blob/main/src/tir/schedule/primitive/layout_transformation.cc#L288. Unfortunately CI didn’t catch this

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Thank you for the catch, and I'll update TransformLayoutTraits::UnpackedAsPython with the updated arguments. Is there somewhere that should have an additional test for round-tripping the python conversion? It looks like this UnpackedAsPython is used in Trace.as_python, but I don't see any tests that call it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Found it. The verify_trace_roundtrip helper function verifies that the trace can be round-tripped through JSON, and that the trace can be converted to python, but doesn't verify that the trace can be round-tripped through python.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It should be corrected now, including updates to verify_trace_roundtrip to validate the python roundtrip by default. If this finds other breakages unrelated to this PR, I'll limit the python roundtrip checks to opt-in tests, with a tracking issue to resolve any other breakages.

@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

All tests passing, including tests for the UnpackAsPython. Marking the PR as ready for review.

@Lunderberg
Lunderberg marked this pull request as ready for review May 18, 2022 16:11
@LunderbergLunderberg changed the title [Draft][TIR][Schedule] Transform layout quality of life[TIR][Schedule] Transform layout quality of lifeMay 18, 2022
@Lunderberg
Lunderberg requested a review from vinx13May 19, 2022 13:12

@csullivancsullivan left a comment

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.

Very nice! I really like the new interface and refactoring under IndexMap for reuse in TE and TIR.

@vinx13vinx13 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall LGTM

Comment threadpython/tvm/tir/schedule/schedule.py Outdated
Comment threadpython/tvm/tir/schedule/schedule.py Outdated
@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

Current CI failures due to Scipy URL change, should restart CI after #11399 lands.

@Lunderberg
Lunderbergforce-pushed the transform_layout_quality_of_life branch from a7251f2 to a513f18CompareMay 23, 2022 16:30
@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

CI failure in Docs: GPU looks like it was caused by a network timeout. Re-triggering CI.

@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

CI failure this time was due to CUDA version in Docs: GPU. Looks like the docker image was recently updating, merging main into the dev branch and retriggering CI.

@Lunderberg
Lunderbergforce-pushed the transform_layout_quality_of_life branch from 5af3cfd to 00e7eb6CompareMay 25, 2022 19:11
@Lunderberg

Copy link
Copy Markdown
ContributorAuthor

Retriggering CI following #11456.

@vinx13
vinx13 merged commit 814f550 into apache:mainMay 26, 2022
@Lunderberg
Lunderberg deleted the transform_layout_quality_of_life branch May 26, 2022 11:56
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Jun 8, 2022
Similar to apache#11269, which added this
functionality to `Schedule.transform_layout`.
vinx13 pushed a commit that referenced this pull request Jun 9, 2022
…11624)
* [Schedule] Allowed string argument as block arg
This has previously been implemented for `Schedule.transform_layout`
in #11296, extending to allow for
block arguments in all `Schedule` methods.
This change was only made for arguments that must be a `BlockRV`. For
arguments that may be either a `BlockRV` or another
type (e.g. `Schedule.get_child_blocks` accepts either `BlockRV` or
`LoopRV`), this sugar is not implemented, to avoid ambiguity.
* [Schedule] Allowed string argument to Schedule.reindex
Similar to #11269, which added this
functionality to `Schedule.transform_layout`.
* CI test update
Kathryn-cat pushed a commit to Kathryn-cat/tvm that referenced this pull request Jun 10, 2022
…pache#11624)
* [Schedule] Allowed string argument as block arg
This has previously been implemented for `Schedule.transform_layout`
in apache#11296, extending to allow for
block arguments in all `Schedule` methods.
This change was only made for arguments that must be a `BlockRV`. For
arguments that may be either a `BlockRV` or another
type (e.g. `Schedule.get_child_blocks` accepts either `BlockRV` or
`LoopRV`), this sugar is not implemented, to avoid ambiguity.
* [Schedule] Allowed string argument to Schedule.reindex
Similar to apache#11269, which added this
functionality to `Schedule.transform_layout`.
* CI test update
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Sep 16, 2022
Follow-up from apache#11269, which allowed
schedule arguments of the buffer to be transformed to be specified as
a string, or as a `tir::Buffer`. The string handling worked
correctly, but the `tir::Buffer` object was handled incorrectly. This
commit corrects the handling of `tir::Buffer` arguments when
scheduling, and adds a unit test to validate this behavior.
vinx13 pushed a commit that referenced this pull request Sep 19, 2022
…2816)
Follow-up from #11269, which allowed
schedule arguments of the buffer to be transformed to be specified as
a string, or as a `tir::Buffer`. The string handling worked
correctly, but the `tir::Buffer` object was handled incorrectly. This
commit corrects the handling of `tir::Buffer` arguments when
scheduling, and adds a unit test to validate this behavior.
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
…ache#12816)
Follow-up from apache#11269, which allowed
schedule arguments of the buffer to be transformed to be specified as
a string, or as a `tir::Buffer`. The string handling worked
correctly, but the `tir::Buffer` object was handled incorrectly. This
commit corrects the handling of `tir::Buffer` arguments when
scheduling, and adds a unit test to validate this behavior.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Lunderberg@vinx13@csullivan