Repository navigation
Introduce Collapse Pass - #11713
Introduce Collapse Pass#11713
Conversation
MaheshRavishankar
left a comment
There was a problem hiding this comment.
Nice! Overall looks good to me. Just a few nits!
|
|
||
| // IndexOp allows accesing induction variables. Collapsing might cause | ||
| // performance regression, so we disable it. | ||
| if (genericOp.hasIndexSemantics()) return false; |
There was a problem hiding this comment.
Are we sure about this? I think the core transformation supports this. We should just drop this constraint....
There was a problem hiding this comment.
Yes you are right, the core transformation supports this. But it causes a performance regression in one CPU benchmark. I turned this off for a benchmark.
Here is the reproducer of slowdown.
https://gist.github.com/grypp/b8c3f8fd6c2720b5a4f57c497e829812#file-collapse-mlir-L64-L67
I can look at the data access pattern instead of the hasIndexSemantics, but I am not sure what's the best way to do that.
There was a problem hiding this comment.
The collapsing shouldn’t happen when the loop index is used directly. So we should figure out why the upstream patterns allows it to happen. We don’t need to investigate the regression itself which is most likely due to wrong a miscompile.
There was a problem hiding this comment.
I dont see a reason why collapsing should happen. Upstream pattern handles it correctly, I dont see any problem with it.
There was a problem hiding this comment.
W.R.T regression, if it causes regression we can leave it off for now. Upstream it handles it for completeness. It is up to the user to either handle it or not.
There was a problem hiding this comment.
Let's file an issue and put the github issue ID to TODO here?
There was a problem hiding this comment.
As an alternative idea, I could create a flag and use it to turn off collapse in this regressed benchmark.
| static FailureOr<linalg::GenericOp> findRootGenericOp( | ||
| DispatchRegionOp regionOp) { | ||
| auto &ops = regionOp.getBody().front().getOperations(); | ||
| if (ops.size() != 2) return failure(); |
There was a problem hiding this comment.
This is too specific. I think we should just walk through the region and find the number of ops that are "compute" ops. You can treat all ops that implement TilingInterface as compute ops. So then you can check the number of these ops is 1?
There was a problem hiding this comment.
I implemented what you described here. On top of that I added if (ops.size() != 2) to make sure the root has no producer. The original code was doing similar.
|
|
||
| // IndexOp allows accesing induction variables. Collapsing might cause | ||
| // performance regression, so we disable it. | ||
| if (genericOp.hasIndexSemantics()) return false; |
There was a problem hiding this comment.
W.R.T regression, if it causes regression we can leave it off for now. Upstream it handles it for completeness. It is up to the user to either handle it or not.
|
|
||
| // IndexOp allows accesing induction variables. Collapsing might cause | ||
| // performance regression, so we disable it. | ||
| if (genericOp.hasIndexSemantics()) return false; |
There was a problem hiding this comment.
Let's file an issue and put the github issue ID to TODO here?
d3f7e5f to
425e34b
Compare
This is a follow-up PR. iree-org#11295 had already implemented the collapsing logic. This PR introduces a new Collapse Pass for `linalg.generic` operations in `dispatch.region`. The new Pass implements the following steps: 1. Finds `linalg.generic` that has no producer in `dispatch.region`, which means there will only be one `linalg.generic` in the region. 2. Collapse dimensions of the tensors in `linalg.generic` if possible 3. Generates new workload region for the collapsed Op and new `dispatch.region` PR also removes collapse flag and changes a test that was using accordingly.
This reverts commit 37983c6.
This is a follow-up PR. #11295 had already implemented the collapsing logic for `linalg.generic` operations in `dispatch.region`. This PR extracts that logic in a new Collapse Pass. The new pass performs the following steps. The first and third steps here are new compared to the previous one as we are creating the Pass. 1. Finds `linalg.generic` that has no producer in `dispatch.region`, which means there will only be one `linalg.generic` in the region. 2. Collapse dimensions of the tensors in `linalg.generic` if possible 3. Generates new workload region for the collapsed Op and new `dispatch.region` PR also removes collapse flag and changes a test that was using accordingly.
This is a follow-up PR. #11295 had already implemented the collapsing logic for
linalg.genericoperations indispatch.region. This PR extracts that logic in a new Collapse Pass.The new pass performs the following steps. The first and third steps here are new compared to the previous one as we are creating the Pass.
linalg.genericthat has no producer indispatch.region, which means there will only be onelinalg.genericin the region.linalg.genericif possibledispatch.regionPR also removes collapse flag and changes a test that was using accordingly.