Skip to content
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

[Codegen] Add control options in pack unpack decomposition #18469

Merged
merged 4 commits into from
Sep 20, 2024

Conversation

Max191
Copy link
Contributor

@Max191 Max191 commented Sep 10, 2024

Some early patterns in pack/unpack decomposition avoid generating reshape ops for unit dim packs and unpacks. However, the TileAndFuse pipeline uses these reshape ops to propagate expanded shapes to other fusable ops. This PR adds an option to the DecomposePackUnPackOps pass to create reshape ops anyway for unit dim cases.

The reason these unit dims show up right now is that the iree_linalg_ext.im2col op of a unit-batched conv will have a unit dimension in the batch dim. Ultimately, it would be good to allow for batchless im2col ops, but in general it is good to support ops that have required unit dimensions. When prototyping new ops, it can be easiest to not support rank-reducing cases at first (winograd ops are another example), so these unit dims may appear again in the future.

This PR also adds an optional control function to the pass options, which controls which packs and unpacks get decomposed. The control function is currently expected to be used when the useOnlyReshapes option is true, since there is no control function in some upstream patterns yet, but adding the control function upstream and fixing this is left as a TODO.

@Max191
Copy link
Contributor Author

Max191 commented Sep 10, 2024

Depends on llvm/llvm-project#108025

Comment on lines 62 to 64
std::unique_ptr<InterfacePass<FunctionOpInterface>>
createDecomposePackUnPackOpsPass(bool tileOuterToOne);
createDecomposePackUnPackOpsPass(bool tileOuterToOne,
bool useOnlyReshapes = false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the style that one has default values but the other does not. Perhaps we should just retire this wrapper and use the option path, or remove the default values from useOnlyReshapes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realized that we actually need an optional control function on the decomposition as well, so I think it is better to leave the wrapper now. I can add a default value for tileOuterToOne, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I decided to put the control function as an option, since it is optional. The command line option for it will exist but not be usable, but I think it was cleaner this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind, I just tested this locally and I don't think PassOptions work with functions. I will just leave it with the wrapper.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can add a default value for tileOuterToOne, WDYT?

It won't work because it is confusing to the default method. There is already a tablegen-ed definition, and adding a default value for the variable leads to a confusion. You'll likely hit a compilation error. That's why I suggested to remove the default value from useOnlyReshapes,

@Max191 Max191 force-pushed the decompose-pack-with-reshapes branch 2 times, most recently from 352dcb0 to 2fdb167 Compare September 19, 2024 15:56
@Max191 Max191 requested a review from hanhanW September 19, 2024 15:57
@Max191 Max191 changed the title [Codegen] Add option for using reshapes in pack unpack decomposition [Codegen] Add control options in pack unpack decomposition Sep 19, 2024
Copy link
Contributor

@qedawkins qedawkins left a comment

Choose a reason for hiding this comment

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

This looks fine, but the control function looks dead in this change. Can we move it to a follow up that actually tests it?

@qedawkins
Copy link
Contributor

(Also wait for approval from Hanhan as well)

Copy link
Contributor

@hanhanW hanhanW left a comment

Choose a reason for hiding this comment

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

LG, just two nits.

Signed-off-by: Max Dawkins <max.dawkins@gmail.com>
Signed-off-by: Max Dawkins <max.dawkins@gmail.com>
Signed-off-by: Max Dawkins <max.dawkins@gmail.com>
@Max191
Copy link
Contributor Author

Max191 commented Sep 20, 2024

This looks fine, but the control function looks dead in this change. Can we move it to a follow up that actually tests it?

I've tested the change locally on a branch. I'd rather just leave the change in this PR if you don't have a strong opinion, since it is a pretty simple change.

Signed-off-by: Max Dawkins <max.dawkins@gmail.com>
@Max191 Max191 merged commit 891f438 into iree-org:main Sep 20, 2024
35 checks passed
Sign up for free to 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