Skip to content

Move Shared Mem Transpose Detection Logic to LinalgOpTrait - #10495

Merged
KoolJBlack merged 3 commits into
iree-org:mainfrom
KoolJBlack:transpose-optrait
Sep 22, 2022
Merged

KoolJBlack merged 3 commits into
iree-org:mainfrom
KoolJBlack:transpose-optrait

Conversation

@KoolJBlack

@KoolJBlack KoolJBlack commented Sep 21, 2022 •

Copy link
Copy Markdown
Contributor

Cleanup to consolidate code and improve readability.

Related to #10005

@KoolJBlack
KoolJBlack marked this pull request as ready for review September 21, 2022 15:55
@KoolJBlack
KoolJBlack requested review from ThomasRaoux and dcaballe and removed request for MaheshRavishankar and ThomasRaoux September 21, 2022 15:56

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

Awesome! Thanks for the refactoring!

I think in general the idea is to keep in LinalgOpInfo only the code that is generic enough to be reusable. We can extend this class to take a couple of lambda filters, one for AffineMap and another one for LinalgOp, to pass specific constraints from each client that are not generic enough to be reusable but should be used to make the transpose property more specific. I'm adding more comments inline. Happy to quickly discuss this over GVC!

@KoolJBlack

Copy link
Copy Markdown
Contributor Author

@dcaballe on closer inspection, I've realized the isTransposeLinalgOp function does quite a few things including using different inverses for the input/output operands this will prolly be much harder to generalize
perhaps its not worth trying to merge these two codes, unless you know if what can be made generic in this logic
it seems its already detecting a particular type of transpose specific to CPU?

If I'm bypassing all of that logic, there is very little I can reuse on the GPU side that isn't just single function calls.

I'm now thinking it might make more sense to consolidate the transpose code in a LLVMGPU specific shared header that can be reused throughout.

@dcaballe

Copy link
Copy Markdown
Contributor

@dcaballe on closer inspection, I've realized the isTransposeLinalgOp function does quite a few things including using different inverses for the input/output operands this will prolly be much harder to generalize perhaps its not worth trying to merge these two codes, unless you know if what can be made generic in this logic it seems its already detecting a particular type of transpose specific to CPU?

This logic is not detecting anything specific to CPUs or any specific transposes. It's just detecting any transpose operation. There are, of course, some TODOs that will be incrementally addressed but it's nothing specific. The map inversion is due to the indexing map semantics in a LinalgOp. They represent how to transform the iteration space indexes for a specific input/output. However, to actually model the memory transformations that will happen out of those indexing maps, we have to transform them accordingly, hence the inversions that you see. Again, this is nothing specific. The inversion and related code is what we use to generate the actual transfer ops and transpose operations out of the generic op.

If I'm bypassing all of that logic, there is very little I can reuse on the GPU side that isn't just single function calls.

That's why I mentioned that the filter should add extra constraints, not just replace the existing one. The existing one is generic and will match all the transposes (eventually). An extra filter should build on top of the generic one and add more constraints to narrow down the output.

I'm now thinking it might make more sense to consolidate the transpose code in a LLVMGPU specific shared header that can be reused throughout.

I guess that's up to you but as you can see the logic will get complicated the moment to try to match more cases than the current one for the FVD.

@KoolJBlack

Copy link
Copy Markdown
Contributor Author

I've reworked the transpose info to support some more general traits that are useful for GPU. I've also removed the specific shared mem transpose code and added to a separate header. This is supplied as an additional filter for transposed ops.

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

Looks great! Just a couple of comments. Thanks!

@KoolJBlack
KoolJBlack enabled auto-merge (squash) September 22, 2022 18:16

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

Thanks! LGTM!

@KoolJBlack
KoolJBlack merged commit 9540b6d into iree-org:main Sep 22, 2022
@KoolJBlack
KoolJBlack deleted the transpose-optrait branch September 23, 2022 16:41
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