Skip to content

[CodeGen] Fuse linalg.fill and reduction linalg.generic - #5242

Merged
antiagainst merged 5 commits into
iree-org:mainfrom
antiagainst:fuse-reduction-fill
Mar 30, 2021
Merged

antiagainst merged 5 commits into
iree-org:mainfrom
antiagainst:fuse-reduction-fill

Conversation

@antiagainst

@antiagainst antiagainst commented Mar 28, 2021 •

Copy link
Copy Markdown
Member

This commit adjusts dispatch region formation to additionally
recognize linalg.generic as a root op and reverses the order
with which we decide fusion groups. This enables us to fuse
linalg.generic output tensors into the same group, thus we
can pull in the linalg.fill for reduction linalg.generic. This
works for both tiled cases and non-tiled cases. We actually
already treat linalg.generic as a root op (as a second step
when deciding fusion groups). This simplifies the logic by
unifying them into one.

This avoids sad dispatch regions like the following:

  flow.executable @call_dispatch_143 attributes {sym_visibility = "private"} {
    flow.dispatch.entry @call_dispatch_143 attributes {signature = () -> tensor<f32>, workgroup_rank = 3 : index}
    module  {
      func @call_dispatch_143(%arg0: !flow.dispatch.tensor<writeonly:f32>) {
        %cst = constant 0xFF800000 : f32
        %0 = linalg.init_tensor [] : tensor<f32>
        %1 = linalg.fill(%0, %cst) : tensor<f32>, f32 -> tensor<f32>
        flow.dispatch.tensor.store %1, %arg0 : tensor<f32> -> !flow.dispatch.tensor<writeonly:f32>
        return
      }
    }
  }

This commit adjusts dispatch region formation to additionally
recognize linalg.generic as a root op and reverses the order
with which we decide fusion groups. This enables us to fuse
linalg.generic output tensors into the same group, thus we
can pull in the linalg.fill for reduction linalg.generic. This
works for both tiled cases and non-tiled cases. We actually
already treat linalg.generic as a root op (as a second step
when deciding fusion groups). This simplifies the logic by
unifying them into one.

This avoids sad dispatch regions like the following:

```mlir
  flow.executable @call_dispatch_143 attributes {sym_visibility = "private"} {
    flow.dispatch.entry @call_dispatch_143 attributes {signature = () -> tensor<f32>, workgroup_rank = 3 : index}
    module  {
      func @call_dispatch_143(%arg0: !flow.dispatch.tensor<writeonly:f32>) {
        %cst = constant 0xFF800000 : f32
        %0 = linalg.init_tensor [] : tensor<f32>
        %1 = linalg.fill(%0, %cst) : tensor<f32>, f32 -> tensor<f32>
        flow.dispatch.tensor.store %1, %arg0 : tensor<f32> -> !flow.dispatch.tensor<writeonly:f32>
        return
      }
    }
  }
```

Also split the dispatch region formation test file into two:
one with the cases we support now, another with forced on
fusion. This keeps us honest and avoids surprises between
tests and real behavior.

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

Thanks! Mostly looks fine. Just a minor comment about removing legacy test file.

@antiagainst
antiagainst merged commit 6ff9098 into iree-org:main Mar 30, 2021
@KoolJBlack KoolJBlack mentioned this pull request Mar 31, 2021
@antiagainst
antiagainst deleted the fuse-reduction-fill branch August 19, 2021 21:06
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.

4 participants