This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg] Rewrite `linalg.conv_2d_nhwc_hwcf` into 1-D
ClosedPublic

Authored by antiagainst on Nov 1 2021, 7:18 AM.

Details

Summary

We'd like to take a progressive approach towards Fconvolution op
CodeGen, by 1) tiling it to fit compute hierarchy first, and then

  1. tiling along window dimensions with size 1 to reduce the problem

to be matmul-like. After that, we can 3) downscale high-D convolution
ops to low-D by removing the size-1 window dimensions. The final
step would be 4) vectorizing the low-D convolution op directly.

We have patterns for 1), 2), and 4). This commit adds a pattern for

  1. for linalg.conv_2d_nhwc_hwcf ops as a starter. Supporting other

high-D convolution ops should be similar and mechanical.

Diff Detail

Event Timeline

antiagainst created this revision.Nov 1 2021, 7:18 AM
antiagainst requested review of this revision.Nov 1 2021, 7:18 AM
nicolasvasilache accepted this revision.Nov 1 2021, 11:42 AM

LGTM

Next step would be to make this available to the CodegenStrategy and the sandbox, probably via this pass https://sourcegraph.com/github.com/llvm/llvm-project/-/blob/mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp?L242.
e2e experiments will tell us if this needs to be exposed in a better way.

mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
908

We can iterate from this to get started but note that there are implications on bufferization.
Alternatively we could use rank-reducing InsertSliceOp / ExtractSliceOp; this may be needed for proper inplace bufferization but let's punt for now until we see the whole end-to-end story.

This revision is now accepted and ready to land.Nov 1 2021, 11:42 AM
antiagainst added inline comments.Nov 2 2021, 6:56 AM
mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
908

Yeah. I was a bit worried about its implication over vectorization too. I think insert/extract slice op might be better supported there. But I think this reshape ops should be also be supported too. Need to fix if missing. Good point about bufferization; I wasn't thinking much about it previously. We can change this if it turns out to be an issue.