Skip to content

Add more patterns to lower to flow.tensor ops - #5576

Merged
MaheshRavishankar merged 7 commits into
iree-org:mainfrom
MaheshRavishankar:subtensor_insert_to_flow
Apr 27, 2021
Merged

MaheshRavishankar merged 7 commits into
iree-org:mainfrom
MaheshRavishankar:subtensor_insert_to_flow

Conversation

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

The following operations can be lowered to flow.tensor. ops.

  1. linalg.tensor_reshape -> flow.tensor.reshape : Once all reshapes can be folded away, the remaining reshapes only exist at the boundaries of dispatch regions. These are better off converted to flow.tensor.reshape so that they could become no-ops when lowered to the hal layer.

  2. subtensor -> flow.tensor.slice. A subtensor operation can be lowered to a flow.tensor.slice operation in some cases. This can become a no-op in many cases.

  3. subtensor_insert -> flow.tensor.update. A subtensor_insert operation can be lowered to a flow.tensor.update operation which will allow for doign in-place updates.

This will eliminate some dispatch regions that do not need to be created.

@google-cla google-cla Bot added the cla: yes label Apr 22, 2021
@MaheshRavishankar

Copy link
Copy Markdown
Collaborator Author

I am looking into if subtensor to flow.tensor.slice is really needed. So might drop that pattern from the list.

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator Author

@antiagainst @hanhanW for the benfit of these to really kick in, I need some patterns upstream, but if I add those patterns first, it will fail in IREE. So these adds the code paths to not fail when those patterns are used. After they make their way in, we might be able to get some improvement here.
Will also need some better handling of flow -> hal lowering of flow.dispatch.slice to really help. But this doesnt seem to cause regressions, so sending it out for review

@antiagainst antiagainst 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.

Nice!

MaheshRavishankar added 7 commits April 26, 2021 16:15
Inlining reshapes into dispatch regions cause subtle issues. The
`subtensor` -> `tensor_reshape` pattern causes issues during
bufferization.

To avoid this two approaches are possible
1) Fuse reshapes with other operations as much as possible during
   fusion on linalg ops.
2) Lower reshapes to `flow.tensor.reshape` before dispatch region
   creation.
When the slice of the subtensor update is contiguous in memory, the
subtensor_insert can be lowered to a flow.tensor.update.
@MaheshRavishankar
MaheshRavishankar force-pushed the subtensor_insert_to_flow branch from 50c4e80 to 717ae8e Compare April 26, 2021 23:15
@MaheshRavishankar
MaheshRavishankar merged commit dbd43a7 into iree-org:main Apr 27, 2021
@MaheshRavishankar
MaheshRavishankar deleted the subtensor_insert_to_flow branch April 27, 2021 04:05
ThomasRaoux pushed a commit to ThomasRaoux/iree that referenced this pull request Apr 27, 2021
The following operations can be lowered to flow.tensor. ops.

linalg.tensor_reshape -> flow.tensor.reshape : Once all reshapes can be folded away, the remaining reshapes only exist at the boundaries of dispatch regions. These are better off converted to flow.tensor.reshape so that they could become no-ops when lowered to the hal layer.

subtensor -> flow.tensor.slice. A subtensor operation can be lowered to a flow.tensor.slice operation in some cases. This can become a no-op in many cases.

subtensor_insert -> flow.tensor.update. A subtensor_insert operation can be lowered to a flow.tensor.update operation which will allow for doign in-place updates.

This will eliminate some dispatch regions that do not need to be created.
This was referenced Apr 27, 2021
simon-camp pushed a commit to simon-camp/iree that referenced this pull request Apr 29, 2021
The following operations can be lowered to flow.tensor. ops.

linalg.tensor_reshape -> flow.tensor.reshape : Once all reshapes can be folded away, the remaining reshapes only exist at the boundaries of dispatch regions. These are better off converted to flow.tensor.reshape so that they could become no-ops when lowered to the hal layer.

subtensor -> flow.tensor.slice. A subtensor operation can be lowered to a flow.tensor.slice operation in some cases. This can become a no-op in many cases.

subtensor_insert -> flow.tensor.update. A subtensor_insert operation can be lowered to a flow.tensor.update operation which will allow for doign in-place updates.

This will eliminate some dispatch regions that do not need to be created.
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.

4 participants