Repository navigation
[Codegen] Add pass to decompose pack unpack ops at dispatch boundaries - #18852
Conversation
|
Currently depends on #18843 for some StaticValueUtils. |
| using impl::DecomposeBoundaryPackUnPackOpsPassBase< | ||
| DecomposeBoundaryPackUnPackOpsPass>:: |
There was a problem hiding this comment.
| using impl::DecomposeBoundaryPackUnPackOpsPassBase< | |
| DecomposeBoundaryPackUnPackOpsPass>:: | |
| using impl::DecomposeBoundaryPackUnPackOpsPassBase:: |
There was a problem hiding this comment.
I'm not sure this works?
| OpPassManager &funcPassManager = maybeFuncPassManager.value(); | ||
| funcPassManager.addPass(createDecomposePackUnPackOpsPass( | ||
| tileOuterToOne, /*useOnlyReshapes=*/true, | ||
| /*controlFn=*/isFoldableIntoInterfaceTensor)); |
There was a problem hiding this comment.
Why do you need a whole pass for this? You're just using the control function on the existing pass; I would factor out this pass and move the control function into a shared location.
There was a problem hiding this comment.
The reason to have a separate pass is so that it is possible to run the pass using the command line. The other way to do this would be to add an option pointing to a specific control function, but I opted for adding a new pass because useOnlyReshapes does not exist in DecomposeBoundaryPackUnPackOps (since it should always be true for this new pass), so I thought it was more clear this way.
There was a problem hiding this comment.
Invoking a pass inside another pass is not the best way to do that then because it leads to confusing IR dumps. Factor DecomposePackUnPackOpsPass::runOnOperation into its own function and call the same function from this pass with different options. The other way to do it is with custom test pass pipelines, but the logic in the control function is involved enough that a separate pass makes sense
There was a problem hiding this comment.
I created a shared runOnOperation function, so now there is no nested pass call. PTAL
…dispatch boundaries Signed-off-by: Max Dawkins <[email protected]>
Signed-off-by: Max Dawkins <[email protected]>
20ef780 to
34c56e4
Compare
Signed-off-by: Max Dawkins <[email protected]>
…18565) This switches the TileAndFuse pipeline to use scf.forall distribution. Using scf.forall distribution also requires some changes to the pass ordering in the TileAndFuse pipeline, which is also handled by this PR: 1. The main difference is that PackToIntrinsics happens before workgroup distribution. Otherwise, collapse_shape ops can end up at the end of the workgroup forall, and an extra buffer is created. 2. Pack decomposition is now staged, with packs/unpacks at the function boundaries being decomposed early before workgroup decomposition, and the rest being decomposed after reduction tiling as before. This prevents unpacks being fused into the workgroup forall and causing the same problem as in (1). 3. `ConcretizeMmaShapes` now runs before workgroup tiling as well, so the resulting collapse_shape on the multi_mma op result can be propagated to the function boundary before any tiling. This is also to avoid the same problem as in (1). The lowering configs on the MMA path have also changed, since they now need to account for inner tile sizes of packing. depends on #18852 Signed-off-by: Max Dawkins <[email protected]>
| %1 = hal.interface.binding.subspan layout(#pipeline_layout) binding(0) alignment(64) offset(%c0) : !flow.dispatch.tensor<readwrite:tensor<16x16xf32>> | ||
| %src = flow.dispatch.tensor.load %0, offsets = [0, 0, 0, 0], sizes = [4, 4, 4, 4], strides = [1, 1, 1, 1] : !flow.dispatch.tensor<readonly:tensor<4x4x4x4xf32>> -> tensor<4x4x4x4xf32> | ||
| %dest = flow.dispatch.tensor.load %1, offsets = [0, 0], sizes = [16, 16], strides = [1, 1] : !flow.dispatch.tensor<readwrite:tensor<16x16xf32>> -> tensor<16x16xf32> | ||
| %unpack = tensor.unpack %src inner_dims_pos = [0, 1] inner_tiles = [4, 4] into %dest : tensor<4x4x4x4xf32> -> tensor<16x16xf32> |
There was a problem hiding this comment.
perhaps we should add a util.optimization_barrier on the %src which makes sure that the test is for folding unpack into the dest.
EDIT: I did not check all the test, but please take a look at other tests as well.
| %src = flow.dispatch.tensor.load %0, offsets = [0, 0], sizes = [16, 16], strides = [1, 1] : !flow.dispatch.tensor<readonly:tensor<16x16xf32>> -> tensor<16x16xf32> | ||
| %dest = flow.dispatch.tensor.load %1, offsets = [0, 0, 0, 0], sizes = [4, 4, 4, 4], strides = [1, 1, 1, 1] : !flow.dispatch.tensor<readwrite:tensor<4x4x4x4xf32>> -> tensor<4x4x4x4xf32> | ||
| %empty = tensor.empty() : tensor<16x16xf32> | ||
| %copy = linalg.copy ins(%src : tensor<16x16xf32>) outs(%empty : tensor<16x16xf32>) -> tensor<16x16xf32> |
There was a problem hiding this comment.
optional: we can use optimization barrier instead of linalg.copy.
Sure, I'll add some more tests |
#18852) This PR adds a wrapper pass around DecomposePackUnPackOps, which adds a control function for decomposing only packs and unpacks whose reshapes can be folded with dispatch tensor loads/stores. This PR also removes the public pass constructor with a control function, opting to use wrapper passes in place of constructing passes with arbitrary control functions. This is better for creating simple bug repros, since the control function is part of the pass. --------- Signed-off-by: Max Dawkins <[email protected]> Signed-off-by: Elias Joseph <[email protected]>
…18565) This switches the TileAndFuse pipeline to use scf.forall distribution. Using scf.forall distribution also requires some changes to the pass ordering in the TileAndFuse pipeline, which is also handled by this PR: 1. The main difference is that PackToIntrinsics happens before workgroup distribution. Otherwise, collapse_shape ops can end up at the end of the workgroup forall, and an extra buffer is created. 2. Pack decomposition is now staged, with packs/unpacks at the function boundaries being decomposed early before workgroup decomposition, and the rest being decomposed after reduction tiling as before. This prevents unpacks being fused into the workgroup forall and causing the same problem as in (1). 3. `ConcretizeMmaShapes` now runs before workgroup tiling as well, so the resulting collapse_shape on the multi_mma op result can be propagated to the function boundary before any tiling. This is also to avoid the same problem as in (1). The lowering configs on the MMA path have also changed, since they now need to account for inner tile sizes of packing. depends on #18852 Signed-off-by: Max Dawkins <[email protected]> Signed-off-by: Elias Joseph <[email protected]>
This PR adds a wrapper pass around DecomposePackUnPackOps, which adds a control function for decomposing only packs and unpacks whose reshapes can be folded with dispatch tensor loads/stores.
This PR also removes the public pass constructor with a control function, opting to use wrapper passes in place of constructing passes with arbitrary control functions. This is better for creating simple bug repros, since the control function is part of the pass.