[Codegen] Create CombineSourceLayoutTransformation pass for MapGatherOp#23165
Conversation
There was a problem hiding this comment.
I did not review all the code yet, but I have a first high-level question: do we want to make both transformation (gather and scatter) be in a single pass? They look orthogonal to me, and it is not clear that which folding is prioritized.
The other high level comment is passing bool-ish argument (i.e., your new enum) to functions. It makes this much more difficult to follow (especially in what is already difficult code). This comment depends on the first mega comment about if we want to split it into two passes or not.
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.td
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/GPU/GPUCombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
I think we want to allow this as the use case mentioned in #23038 has pad op in it? |
|
Hey @Abhishek-Varma I did not get a chance to review it today. I'll prioritize it tomorrow. You can continue working on other changes and use stacked PR features. (or just send the PR out and ask me/others to review the last commit.) |
|
I don't follow why a review comment is generated by LLM agents. I hided it and deleted the app. |
hanhanW
left a comment
There was a problem hiding this comment.
I haven't reviewed the core logic yet, but can we clean up first? I think some of them are not used at all, and it is adding tech debt and overheads to reviewers.
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.h
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
7b5bfa1 to
6821f91
Compare
...iler/src/iree/compiler/Codegen/Common/test/combine_layout_transformation_for_map_gather.mlir
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
9dc047e to
7e3b728
Compare
|
Hi @hanhanW. I've now changed the algo. I'm creating identity map_gather at the result of load_from_buffer and now iteratively fusing in consumer relayout ops instead of the earlier algo of creating an identity map_gather at the end of a relayout op chain. It's more intuitive now. I've also refactored the code because most of the foldings followed a similar structure - so reviewing it will be easier now! Locally, I've included this pass at iree/compiler/src/iree/compiler/Codegen/LLVMGPU/Passes.cpp Lines 544 to 545 in 7aa7be5 iree-codegen-test-c-promtion :-
I used the above setup to test the original regression with the repro dispatch and I confirm it resolves the issue :- NOTE: I confirmed first by simply switching off the I've even verified the output of the dispatch. Even isolated a few cases like I'm adding the output.mlir and input.mlir for reference that the pass can handle complex relayout chains. So, once this PR merges - I can raise another PR that removes the temporary workaround and adds this pass in the |
… Dispatch scope -- This commit adds support of map_gather op in CombineLayoutTransformation in Dispatch scope. -- Unlike map_scatter, we don't allow tensor.pad op in the relayout op chain for map_gather. This is because map_scatter has a known output buffer at the end of the chain, while map_gather only has a known source buffer at the beginning of the relayout ops chain. Signed-off-by: Abhishek Varma <[email protected]>
Signed-off-by: Abhishek Varma <[email protected]>
Signed-off-by: Abhishek Varma <[email protected]>
Signed-off-by: Abhishek Varma <[email protected]>
Signed-off-by: Abhishek Varma <[email protected]>
Signed-off-by: Abhishek Varma <[email protected]>
Signed-off-by: Abhishek Varma <[email protected]>
Max191
left a comment
There was a problem hiding this comment.
Overall, looks good. I left one main comment about the tensor.pad handling, and then mostly nits.
One more high level question: Have you verified numerical correctness with any e2e examples using the CombineLayoutTransformationForMapGather pass yet?
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.td
Outdated
Show resolved
Hide resolved
hanhanW
left a comment
There was a problem hiding this comment.
Mostly looks good. I was thinking if I should ask refactoring, or defer it when we're evalulating if we want to collapse two passes or not. Moving them to the same file and keep them two separate pass looks good to me.
compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.td
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformationForMapGather.cpp
Outdated
Show resolved
Hide resolved
7e3b728 to
35808c2
Compare
Signed-off-by: Abhishek Varma <[email protected]>
35808c2 to
48f1f33
Compare
Hi @Max191 - Yes, I did in fact check e2e correctness as reported here. I verified the repro's output as well as a standalone transpose op example. And today I also checked a bunch of complex relayout op chains' e2e correctness too. Here's what I did :-
The tests passed! :D |
hanhanW
left a comment
There was a problem hiding this comment.
Mostly looks good, just some nits. I think we over-abstract the "factor" functions.
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/test/combine_source_layout_transformation.mlir
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
|
The PR title and description need to be updated. |
Signed-off-by: Abhishek Varma <[email protected]>
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Show resolved
Hide resolved
hanhanW
left a comment
There was a problem hiding this comment.
just one final nit. lgtm
Max191
left a comment
There was a problem hiding this comment.
LGTM, nice work! Just a couple nits.
compiler/src/iree/compiler/Codegen/Common/CombineLayoutTransformation.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Abhishek Varma <[email protected]>
…Op (iree-org#23165) -- This commit creates a separate pass `iree-codegen-combine-source-layout-transformation` adding support of folding relayout operations into map_gather op. -- The following ops' folding are being supported through changes in this PR :- 1. `linalg::CopyOp` 2. `linalg::TransposeOp` 3. `tensor::ExpandShapeOp` 4. `tensor::CollapseShapeOp` 5. `tensor::ExtractSliceOp` 6. `tensor::PadOp` -- Consequently `getPaddingValue` and `createIdentityMapGather` member methods were added to `MapGatherOp`. -- The implementations for the `iree-codegen-combine-source-layout-transformation` pass reside in the same file as `MapScatter`'s relayout folding implementations (which has been renamed as `iree-codegen-combine-result-layout-transformation`). Signed-off-by: Abhishek Varma <[email protected]>
-- This commit creates a separate pass
iree-codegen-combine-source-layout-transformationadding support of folding relayout operations into map_gather op.
-- The following ops' folding are being supported through changes in this PR :-
1.
linalg::CopyOp2.
linalg::TransposeOp3.
tensor::ExpandShapeOp4.
tensor::CollapseShapeOp5.
tensor::ExtractSliceOp6.
tensor::PadOp-- Consequently
getPaddingValueandcreateIdentityMapGathermember methods were added toMapGatherOp.-- The implementations for the
iree-codegen-combine-source-layout-transformationpass reside in the same file asMapScatter's relayout folding implementations (which has been renamed asiree-codegen-combine-result-layout-transformation).