[Mlir-commits] [mlir] 8d35080 - [mlir][Linalg] Wrong tile size for convolutions fixed
Jakub Lichman
llvmlistbot at llvm.org
Wed Sep 2 23:01:57 PDT 2020
Author: Jakub Lichman
Date: 2020-09-03T06:01:21Z
New Revision: 8d35080ebbea477316159a5af7d925bb51d805d0
URL: https://github.com/llvm/llvm-project/commit/8d35080ebbea477316159a5af7d925bb51d805d0
DIFF: https://github.com/llvm/llvm-project/commit/8d35080ebbea477316159a5af7d925bb51d805d0.diff
LOG: [mlir][Linalg] Wrong tile size for convolutions fixed
Sizes of tiles (subviews) are bigger by 1 than they should. Let's consider
1D convolution without batches or channels. Furthermore let m iterate over
the output and n over the kernel then input is accessed with m + n. In tiling
subview sizes for convolutions are computed by applying requested tile size
together with kernel size to the above mentioned expression thus let's say
for tile size of 2 the subview size is 2 + size(n), which is bigger by one
than it should since we move kernel only once. The problem behind it is that
range is not turned into closed interval before the composition. This commit
fixes the problem by turning ranges first into closed intervals by substracting
1 and after the composition back to half open by adding 1.
Differential Revision: https://reviews.llvm.org/D86638
Added:
Modified:
mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
mlir/test/Dialect/Linalg/tile_conv.mlir
mlir/test/Dialect/Linalg/tile_simple_conv.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
index 6dc98628850f..daaad2e6fa4b 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
@@ -243,7 +243,9 @@ static SmallVector<Value, 4> makeTiledViews(OpBuilder &b, Location loc,
for (unsigned idx = 0, idxIvs = 0, e = tileSizes.size(); idx < e; ++idx) {
bool isTiled = !isZero(tileSizes[idx]);
lbs.push_back(isTiled ? ivs[idxIvs++] : (Value)std_constant_index(0));
- subViewSizes.push_back(isTiled ? tileSizes[idx] : viewSizes[idx]);
+ // Before composing, we need to make range a closed interval.
+ Value size = isTiled ? tileSizes[idx] : viewSizes[idx];
+ subViewSizes.push_back(size - std_constant_index(1));
}
auto *op = linalgOp.getOperation();
@@ -282,7 +284,9 @@ static SmallVector<Value, 4> makeTiledViews(OpBuilder &b, Location loc,
auto m = map.getSubMap({r});
auto offset = applyMapToValues(b, loc, m, lbs).front();
offsets.push_back(offset);
- auto size = applyMapToValues(b, loc, m, subViewSizes).front();
+ auto closedIntSize = applyMapToValues(b, loc, m, subViewSizes).front();
+ // Resulting size needs to be made half open interval again.
+ auto size = closedIntSize + std_constant_index(1);
// The size of the subview should be trimmed to avoid out-of-bounds
// accesses, unless we statically know the subview size divides the view
diff --git a/mlir/test/Dialect/Linalg/tile_conv.mlir b/mlir/test/Dialect/Linalg/tile_conv.mlir
index a08a2f1e585c..3b76f8a3139c 100644
--- a/mlir/test/Dialect/Linalg/tile_conv.mlir
+++ b/mlir/test/Dialect/Linalg/tile_conv.mlir
@@ -1,7 +1,7 @@
// RUN: mlir-opt %s -linalg-tile="linalg-tile-sizes=2,3,0,0,4" | FileCheck %s -check-prefix=TILE-23004
// TILE-23004-DAG: #[[$D0x30pS0x10:.*]] = affine_map<(d0) -> (d0 * 30)>
-// TILE-23004-DAG: #[[$S0x10p90D0x30pS1:.*]] = affine_map<(d0)[s0, s1] -> (s0 * 10 + 90, d0 * -30 + s1)>
+// TILE-23004-DAG: #[[$S0x10p90D0x30pS1:.*]] = affine_map<(d0)[s0, s1] -> (s0 * 10 + 51, d0 * -30 + s1)>
// TILE-23004-DAG: #[[$strided4D:.*]] = affine_map<(d0, d1, d2, d3)[s0, s1, s2, s3] -> (d0 * s1 + s0 + d1 * s2 + d2 * s3 + d3)>
// TILE-23004-DAG: #[[$bound_map_4:.*]] = affine_map<(d0)[s0] -> (4, -d0 + s0)>
diff --git a/mlir/test/Dialect/Linalg/tile_simple_conv.mlir b/mlir/test/Dialect/Linalg/tile_simple_conv.mlir
index f854f7570fef..b71f4bc0d3a8 100644
--- a/mlir/test/Dialect/Linalg/tile_simple_conv.mlir
+++ b/mlir/test/Dialect/Linalg/tile_simple_conv.mlir
@@ -1,8 +1,8 @@
// RUN: mlir-opt %s -linalg-tile="linalg-tile-sizes=2,3,4" | FileCheck %s
// CHECK-DAG: #[[MAP0:.*]] = affine_map<(d0)[s0] -> (2, -d0 + s0)>
-// CHECK-DAG: #[[MAP1:.*]] = affine_map<(d0)[s0, s1] -> (s0 + 3, -d0 + s1)>
-// CHECK-DAG: #[[MAP2:.*]] = affine_map<(d0)[s0, s1] -> (s0 + 4, -d0 + s1)>
+// CHECK-DAG: #[[MAP1:.*]] = affine_map<(d0)[s0, s1] -> (s0 + 2, -d0 + s1)>
+// CHECK-DAG: #[[MAP2:.*]] = affine_map<(d0)[s0, s1] -> (s0 + 3, -d0 + s1)>
// CHECK-DAG: #[[MAP4:.*]] = affine_map<(d0)[s0] -> (3, -d0 + s0)>
// CHECK-DAG: #[[MAP5:.*]] = affine_map<(d0)[s0] -> (4, -d0 + s0)>
@@ -46,4 +46,4 @@ func @conv(%arg0 : memref<?x?x?x?xf32>, %arg1 : memref<?x?x?x?xf32>, %arg2 : mem
// CHECK: %[[T19:.*]] = dim %[[ARG2]], %[[C3]]
// CHECK: %[[SV2:.*]] = subview %[[ARG2]][%[[ARG3]], %[[ARG4]], %[[ARG5]], 0]
// CHECK-SAME: [%[[T14]], %[[T16]], %[[T18]], %[[T19]]]
-// CHECK: linalg.conv(%[[ARG0]], %[[SV1]], %[[SV2]])
\ No newline at end of file
+// CHECK: linalg.conv(%[[ARG0]], %[[SV1]], %[[SV2]])
More information about the Mlir-commits
mailing list