This is an archive of the discontinued LLVM Phabricator instance.

Avoid doing tile + fuse if tile sizes are zero.
ClosedPublic

Authored by mravishankar on Jan 30 2022, 3:59 PM.

Diff Detail

Event Timeline

mravishankar created this revision.Jan 30 2022, 3:59 PM
mravishankar requested review of this revision.Jan 30 2022, 3:59 PM
gysit accepted this revision.Jan 30 2022, 11:36 PM

Thanks for fixing!

If there are no strong reasons to stick to the test code I would go for something shorter, e.g. using matvec:

builtin.func @no_fusion(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?xf32>,
    %arg2: tensor<?xf32>) -> tensor<?xf32> {
  %c0 = arith.constant 0 : index
  %c1 = arith.constant 1 : index
  %cst = arith.constant 1.0 : f32
  %0 = linalg.fill(%cst, %arg0) : f32, tensor<?x?xf32> -> tensor<?x?xf32>
  %1 = linalg.matvec ins(%0, %arg1: tensor<?x?xf32>, tensor<?xf32>) outs(%arg2: tensor<?xf32>) -> tensor<?xf32>
  return %1 : tensor<?xf32>
}

Also I would rename the test file to tile-and-fuse-no-fuse.mlir. We are not consistent there but I think most tests by now use hyphen instead of underscore.

This revision is now accepted and ready to land.Jan 30 2022, 11:36 PM
bondhugula requested changes to this revision.Jan 31 2022, 8:44 AM
bondhugula added a subscriber: bondhugula.
bondhugula added inline comments.
mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
595–598

A tile size of zero is always invalid. You should really fail even if a single tile size is zero - the specification would on the whole be invalid.

This revision now requires changes to proceed.Jan 31 2022, 8:44 AM

Address comments.

Thanks for fixing!

If there are no strong reasons to stick to the test code I would go for something shorter, e.g. using matvec:

builtin.func @no_fusion(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?xf32>,
    %arg2: tensor<?xf32>) -> tensor<?xf32> {
  %c0 = arith.constant 0 : index
  %c1 = arith.constant 1 : index
  %cst = arith.constant 1.0 : f32
  %0 = linalg.fill(%cst, %arg0) : f32, tensor<?x?xf32> -> tensor<?x?xf32>
  %1 = linalg.matvec ins(%0, %arg1: tensor<?x?xf32>, tensor<?xf32>) outs(%arg2: tensor<?xf32>) -> tensor<?xf32>
  return %1 : tensor<?xf32>
}

Also I would rename the test file to tile-and-fuse-no-fuse.mlir. We are not consistent there but I think most tests by now use hyphen instead of underscore.

Done. Btw, I tried to make it such that the getRootReplacement... doesnt assert if no tiled loops are generated. Couldnt figure out an easy way to do this. Ideally it would return the same op, but you then cannot use that with replaceAllUsesWith (since that is an error). Would be nice to have a way to not fail if no tiled loops are generated. This is a WAR for that.

mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
595–598

Thats not the norm that Linalg tiling uses. Tile size = 0 is a specification that a particular loop should not be tiled.

This revision is now accepted and ready to land.Jan 31 2022, 9:48 PM

Done. Btw, I tried to make it such that the getRootReplacement... doesnt assert if no tiled loops are generated. Couldnt figure out an easy way to do this. Ideally it would return the same op, but you then cannot use that with replaceAllUsesWith (since that is an error). Would be nice to have a way to not fail if no tiled loops are generated. This is a WAR for that.

True, I think getRootReplacement should return FailureOr<ValueRange>? I made a TODO and will look at it ASAP. However, I still think it is a good idea to fail early if no tiling is needed.

mlir/test/Dialect/Linalg/tile-and-fuse-no-fuse.mlir
4

nit: it is only gemm now

Rebase and adress comments.

This revision was automatically updated to reflect the committed changes.