Skip to content

[spirv] Migrate ConvertToGPUPass' invocation tiling logic - #5814

Merged
antiagainst merged 12 commits into
iree-org:mainfrom
antiagainst:migrate-convert2gpu
May 14, 2021
Merged

antiagainst merged 12 commits into
iree-org:mainfrom
antiagainst:migrate-convert2gpu

Conversation

@antiagainst

Copy link
Copy Markdown
Member

ConvertToGPUPass is a sink for lowering away all Linalg ops
in the SPIR-V pipeline: it can distribute a Linalg op to both
global invocation IDs (if just having one-level distribution) or
local invocation IDs (if having two-level distribution).

This is mostly historical; now we have more proper layering
in the pipeline where we perform the first-level tiling and
distribution at flow level and the second/third level at
TileAndVectorizeInOneWorkgroupPass, the functionality
in ConvertToGPUPass is overlapping with that, although
in a complementary way: the tiling in the former pass does
not handle the cases where we cannot do imperfect tiling;
it requires perfectly tiled cases, as we are assuming number
of processors equal to number of iterations to avoid generating
scf.for loop from the start. ConvertToGPUPass is more
generic and can handle all cases. This is all opaque and
complicated.

This commit relaxes the TileAndVectorizeInOneWorkgroupPass
to not assume the number of processors equal to the number
of iterations. Now we just tile and cyclically distribute using
scf.for loops. This causes issues for perfectly tiled cases
as we need to canonicalize the affine.min and one-trip
scf.for away to expose static sizes for further vectorization.
That can be done by pulling in additional canonicalization
patterns.

Also in order to utilize TileAndVectorizeInOneWorkgroupPass
for the second/third level tiling we need to have the corresponding
scheme in launch configuration for them. This commit also
adds the default second/third level tiling for all now supported
Linalg ops: no tiling on subgroup and tiling to 1 for invocations.
This at the same time helps to clean up a bunch of unwieldy
templated configurations for different ops..

Together, the above migrates the invocation tiling logic
in ConvertToGPUPass to their proper places. This is the
first step as reining in ConvertToGPUPass and launch
configurations.

@google-cla google-cla Bot added the cla: yes label May 8, 2021
@antiagainst

Copy link
Copy Markdown
Member Author

Note that this depends on https://reviews.llvm.org/D102079, so it will fail tests right now.

@antiagainst antiagainst added cleanup 🧹 codegen/spirv SPIR-V code generation compiler backend labels May 8, 2021

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall looks great. Just a few comments.

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

Together, the above migrates the invocation tiling logic
in ConvertToGPUPass to their proper places. This is the
first step as reining in ConvertToGPUPass and launch
configurations.

FYI, started the work on launch configurations here MaheshRavishankar@26144e2 . I am plumbing it through on the CPU side for now to see how it works with dynamic pass pipelines. Once it is stabilized we can adapt the SPIR-V/CUDA paths to use the same and unify all of them. We can chat about details offline.

// Remove trip-one loops created during cyclic loop distribution if we can
// prove the tiling was perfect.
RewritePatternSet canoncalizationPatterns(context);
populateAffineMinSCFCanonicalizationPattern(canoncalizationPatterns);

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.

Ideally we should be able to use this pattern from core
AffineMinRangeCanonicalizationPattern instead that take the same range lambda. That would allow us to remove populateAffineMinSCFCanonicalizationPattern we have in MLIR eventually.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah didn't know about that pattern.. I can take a look and do it later.

@antiagainst

Copy link
Copy Markdown
Member Author

Together, the above migrates the invocation tiling logic
in ConvertToGPUPass to their proper places. This is the
first step as reining in ConvertToGPUPass and launch
configurations.

FYI, started the work on launch configurations here MaheshRavishankar@26144e2 . I am plumbing it through on the CPU side for now to see how it works with dynamic pass pipelines. Once it is stabilized we can adapt the SPIR-V/CUDA paths to use the same and unify all of them. We can chat about details offline.

Awesome. I'll take a look and comment there.

@antiagainst
antiagainst merged commit d7b3bb9 into iree-org:main May 14, 2021
@antiagainst
antiagainst deleted the migrate-convert2gpu branch May 14, 2021 13:50
@not-jenni not-jenni mentioned this pull request May 14, 2021
antiagainst added a commit to antiagainst/iree that referenced this pull request May 14, 2021
…ee-org#5814)"

This reverts commit d7b3bb9
because it causes numeric issues on internal tests.
antiagainst added a commit that referenced this pull request May 14, 2021
)" (#5905)

This reverts commit d7b3bb9
because it causes numeric issues on internal tests.
antiagainst added a commit to antiagainst/iree that referenced this pull request May 18, 2021
antiagainst added a commit to antiagainst/iree that referenced this pull request Aug 5, 2021
This is another step towards cleaning up the SPIRVConvertToGPUPass
after iree-org#5814. We still have
sets of patterns in the pass, one for handling copying to workgroup
memory, the other for tiling into global invocation IDs. These are
relatively disjoint functionalities; both should be cleaned up in
their own ways. So this commit is a prelimiary step towards that
by shuffling code around to their proper places and properly naming
stuff. This makes it clear for future dedicated improvements
afterwards.
antiagainst added a commit to antiagainst/iree that referenced this pull request Aug 5, 2021
This is another step towards cleaning up the SPIRVConvertToGPUPass
after iree-org#5814. We still have
sets of patterns in the pass, one for handling copying to workgroup
memory, the other for tiling into global invocation IDs. These are
relatively disjoint functionalities; both should be cleaned up in
their own ways. So this commit is a prelimiary step towards that
by shuffling code around to their proper places and properly naming
stuff. This makes it clear for future dedicated improvements
afterwards in following up commits.

The test for vectorized workgroup memory copy is disabled for now
to make migration easier.
antiagainst added a commit to antiagainst/iree that referenced this pull request Aug 5, 2021
This is another step towards cleaning up the SPIRVConvertToGPUPass
after iree-org#5814. We still have two
sets of patterns in the pass, one for handling copying to workgroup
memory, the other for tiling into global invocation IDs. These are
relatively disjoint functionalities; both should be cleaned up in
their own ways. So this commit is a prelimiary step towards that
by shuffling code around to their proper places and properly naming
stuff. This makes it clear for future dedicated improvements
afterwards in following up commits.

The test for vectorized workgroup memory copy is disabled for now
to make migration easier.
antiagainst added a commit to antiagainst/iree that referenced this pull request Aug 5, 2021
This is another step towards cleaning up the SPIRVConvertToGPUPass
after iree-org#5814. We still have two
sets of patterns in the pass, one for handling copying to workgroup
memory, the other for tiling into global invocation IDs. These are
relatively disjoint functionalities; both should be cleaned up in
their own ways. So this commit is a prelimiary step towards that
by shuffling code around to their proper places and properly naming
stuff. This makes it clear for future dedicated improvements
afterwards in following up commits.

This commit is NFC (just shuffling code around), except that the
test for vectorized workgroup memory copy is disabled for now
to make migration easier.
antiagainst added a commit to antiagainst/iree that referenced this pull request Aug 5, 2021
This is another step towards cleaning up the SPIRVConvertToGPUPass
after iree-org#5814. We still have two
sets of patterns in the pass, one for handling copying to workgroup
memory, the other for tiling into global invocation IDs. These are
relatively disjoint functionalities; both should be cleaned up in
their own ways. So this commit is a prelimiary step towards that
by shuffling code around to their proper places and properly naming
stuff. This makes it clear for future dedicated improvements
afterwards in following up commits.

Along the way, this also cleans up the SPIRVVectorToGPU pass, which
uses utilities from the SPIRVConvertToGPU pass. SPIRVVectorToGPUPass
really just contains one pattern to handle copying to workgroup
memory (with vectorization). So renaming it properly. Again,
futher cleanup will be done in following up patches.

This commit is NFC (just shuffling code around), except that the
test for vectorized workgroup memory copy is disabled for now
to make migration easier.
antiagainst added a commit that referenced this pull request Aug 5, 2021
This is another step towards cleaning up the SPIRVConvertToGPUPass
after #5814. We still have two
sets of patterns in the pass, one for handling copying to workgroup
memory, the other for tiling into global invocation IDs. These are
relatively disjoint functionalities; both should be cleaned up in
their own ways. So this commit is a prelimiary step towards that
by shuffling code around to their proper places and properly naming
stuff. This makes it clear for future dedicated improvements
afterwards in following up commits.

Along the way, this also cleans up the SPIRVVectorToGPU pass, which
uses utilities from the SPIRVConvertToGPU pass. SPIRVVectorToGPUPass
really just contains one pattern to handle copying to workgroup
memory (with vectorization). So renaming it properly. Again,
futher cleanup will be done in following up patches.

This commit is NFC (just shuffling code around), except that the
test for vectorized workgroup memory copy is disabled for now
to make migration easier.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup 🧹 codegen/spirv SPIR-V code generation compiler backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants