This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Vector] Fix vectorization of generic ops with transposed outputs
ClosedPublic

Authored by dcaballe on Jun 23 2023, 11:12 PM.

Details

Summary

This patch fixes a bug in the way we compute the vector type for vector
transfer writes when the value to store needs to be transposed.

Diff Detail

Event Timeline

dcaballe created this revision.Jun 23 2023, 11:12 PM
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
dcaballe requested review of this revision.Jun 23 2023, 11:12 PM
This revision is now accepted and ready to land.Jun 24 2023, 9:57 AM
mlir/lib/IR/AffineMap.cpp
570

This looks a bit weird and very specific from an API perspective, I wouldn't know when to use in other cases than your very specific use case.

How about something more reusable like (very rough sketch .. alternatives possible)

AffineMap AffineMap::getFilteredMultiDimIdentityMap(MLIRContext *ctx, int64_t numDims, llvm::function_ref<bool(AffineDimExpr)> keepDim) {
  auto m = getMultiDimIdentityMap(numDims, numSyms, ctx);
  // apply keepDim
  return m.dropResults(projectedDims);
}


// call 
auto m = AffineMap::getFilteredMultiDimIdentityMap(ctx, m.getNumDims, [](AffineDimExpr d){ return llvm::any_of(m.getResults(), [](AffineExpr e) { return e.isFunctionOf(d) ;})});

The double lambda nesting may be unappealing, sorry it's Sat night .. :p but you get the gist.
Feel free to introduce other helpers if they are generally reusable and not 1-off.

mlir/test/Dialect/Linalg/vectorization.mlir
1779

note: we should have an op able to simply target a particular op to vectorize, this would greatly increase applicability and avoid chasing parent ops and applying many patterns on the fly.
The existing transform.vectorize is dated and too monolithic but still used because "it works ok enough".
Bonus points if you quickly whip up a transform.vectorize_single_op.

I am open to renaming the existing op too but that will require more changes than we should spend effort on right now and is a good intro cleanup task.

dcaballe updated this revision to Diff 534710.Jun 26 2023, 12:41 PM

Address feedback. Thanks!

Thanks for the quick review!

mlir/lib/IR/AffineMap.cpp
570

Thanks! Make sense!

mlir/test/Dialect/Linalg/vectorization.mlir
1779

I think @awarzynski have been looking a bit more into the vectorization ops in the transform dialect. Maybe he can help with this although I understand this is low priority.

This revision was landed with ongoing or failed builds.Jun 26 2023, 1:25 PM
This revision was automatically updated to reflect the committed changes.
awarzynski added inline comments.Jun 30 2023, 11:03 AM
mlir/test/Dialect/Linalg/vectorization.mlir
1779

I might have a few spare cycles for this. I assume that you are thinking of something similar to transform.structured.masked_vectorize:

transform.sequence failures(propagate) {
^bb1(%arg1: !transform.any_op):
  %0 = transform.structured.match ops{["linalg.generic"]} in %arg1 : (!transform.any_op) -> !transform.any_op
  transform.structured.masked_vectorize %0 vector_sizes [4] : !transform.any_op
}