Skip to content

[LLVMGPU] Use forall workgroup distribution in TileAndFuse pipeline - #18565

Merged
Max191 merged 1 commit into
iree-org:mainfrom
Max191-agents:tile-and-fuse-forall-workgroup-dist
Oct 24, 2024
Merged

Max191 merged 1 commit into
iree-org:mainfrom
Max191-agents:tile-and-fuse-forall-workgroup-dist

Conversation

@Max191

@Max191 Max191 commented Sep 20, 2024 •

Copy link
Copy Markdown
Contributor

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. createConcretizeMmaShapes 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

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator
  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.

Can you share an example of this? If the collapse shape is at the end of workgroup for all, i'd expect we can fold it away with flow.dispatch.tensor.store ops.

@Max191

Max191 commented Sep 24, 2024

Copy link
Copy Markdown
Contributor Author
  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.

Can you share an example of this? If the collapse shape is at the end of workgroup for all, i'd expect we can fold it away with flow.dispatch.tensor.store ops.

You can end up with IR like this:

    %collapsed = tensor.collapse_shape %transposed [[0, 1], [2, 3]] : tensor<4x16x4x16xf32> into tensor<64x64xf32>
    scf.forall.in_parallel {
      tensor.parallel_insert_slice %collapsed into %arg2[%arg0, %arg1] [64, 64] [1, 1] : tensor<64x64xf32> into tensor<2048x10240xf32>
    }

And it would not be correct in general to fold the collapse_shape into the parallel_insert_slice/forall dest. This collapse_shape comes from the tensor.unpack after PackToIntrinsics. Moving PackToIntrinsics and DecomposePackUnPack before workgroup distributions means the collapse_shape will be outside of the scf.forall already, and then the transpose from the unpack can be fused into the forall loop. Then, the collapse_shape can be folded into the flow.dispatch.tensor.store consumer outside of the forall, since it is a full slice.

@Max191
Max191 force-pushed the tile-and-fuse-forall-workgroup-dist branch from 6008d75 to b50353c Compare October 4, 2024 16:43
@Max191
Max191 force-pushed the tile-and-fuse-forall-workgroup-dist branch from b50353c to 25500cb Compare October 14, 2024 19:51
@Max191
Max191 force-pushed the tile-and-fuse-forall-workgroup-dist branch 5 times, most recently from 25fe98d to c2435db Compare October 21, 2024 15:02
@Max191
Max191 force-pushed the tile-and-fuse-forall-workgroup-dist branch from c2435db to 13f3240 Compare October 24, 2024 14:43
@Max191
Max191 merged commit c3fae2f into iree-org:main Oct 24, 2024
@Max191
Max191 deleted the tile-and-fuse-forall-workgroup-dist branch October 25, 2024 14:21
nirvedhmeshram added a commit to nirvedhmeshram/iree that referenced this pull request Oct 25, 2024
Eliasj42 pushed a commit that referenced this pull request Oct 31, 2024
…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]>
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