[all-commits] [llvm/llvm-project] cb2e65: [mlir][linalg] Fix incorrect bound calculation for...

Lei Zhang via All-commits all-commits at lists.llvm.org
Thu Sep 30 10:54:58 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: cb2e6518000c7e1c5c2244592457afe4a97827e7
      https://github.com/llvm/llvm-project/commit/cb2e6518000c7e1c5c2244592457afe4a97827e7
  Author: Lei Zhang <antiagainst at google.com>
  Date:   2021-09-30 (Thu, 30 Sep 2021)

  Changed paths:
    M mlir/lib/Dialect/Linalg/Utils/Utils.cpp
    M mlir/test/Dialect/Linalg/tile-and-fuse-on-tensors.mlir
    M mlir/test/Dialect/Linalg/tile-and-fuse-tensors.mlir
    M mlir/test/Dialect/Linalg/tile-conv.mlir
    M mlir/test/Dialect/Linalg/tile-simple-conv.mlir

  Log Message:
  -----------
  [mlir][linalg] Fix incorrect bound calculation for tiling conv

For convolution, the input window dimension's access affine map
is of the form `(d0 * s0 + d1)`, where `d0`/`d1` is the output/
filter window dimension, and `s0` is the stride.

When tiling, https://reviews.llvm.org/D109267 changed how the
way dimensions are acquired. Instead of directly querying using
`*.dim` ops on the original convolution op, we now get it by
applying the access affine map to the loop upper bounds. This
is fine for dimensions having single-dimension affine maps,
like matmul, but not for convolution input. It will cause
incorrect compuation and out of bound. A concrete example, say
we have 1x225x225x3 (NHWC) input, 3x3x3x32 (HWCF) filter, and
1x112x112x3 (NHWC) output with stride 2, (112 * 2 + 3) would be
227, which is different from the correct input window dimension
size 225.

Instead, we should first calculate the max indices for each loop,
and apply the affine map to them, and then plus one to get the
dimension size. Note this makes no difference for matmul-like
ops given they will have `d0 - 1 + 1` effectively.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D110849




More information about the All-commits mailing list