Skip to content

Commit bad8bf5

Browse files
authored
[mlir][vector] Linearization: push 'bit width' logic out of patterns (#136581)
[NFC] Vector linearization is a collection of rewrite patterns that reduce the rank of vector operands and results. In #83314 an option to ignore (make 'legal') operations with large inner-most dimensions was added. This current PR is a step towards making that option live outside of upstream MLIR. The motivation is to remove non-core functionality (I would like to use this pass, but would prefer not to deal with 'targetVectorBitWidth` at all). As a follow-up to this PR, I propose that user(s) of the `targetVectorBitWidth` move the relevant code (now in mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp) to their code bases, and then eventually remove it from upstream. In addition the tests need to split out (I've intentionally not modified the lit tests here, to make it easier to confirm that this is a NFC). I'm happy to help make it easier to do this final step! The approach I've used is to move the logic pertaining to `targetVectorBitWidth` out the patterns, and into the conversion target, which the end user can control outside of core MLIR.
1 parent 0e9fb52 commit bad8bf5

File tree

4 files changed

+273
-196
lines changed

4 files changed

+273
-196
lines changed

mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,29 @@ void populateVectorNarrowTypeRewritePatterns(RewritePatternSet &patterns,
406406
void populateVectorTransposeNarrowTypeRewritePatterns(
407407
RewritePatternSet &patterns, PatternBenefit benefit = 1);
408408

409-
/// Populates patterns for ND vectors (N >= 2) linearization and sets up the
410-
/// provided ConversionTarget with the appropriate legality configuration for
411-
/// the ops to get converted properly.
412-
void populateVectorLinearizeTypeConversionsAndLegality(
413-
TypeConverter &typeConverter, RewritePatternSet &patterns,
414-
ConversionTarget &target, unsigned targetBitWidth);
415-
416-
/// Populates patterns for linearizing ND (N >= 2) vector operations to 1D
417-
/// vector shuffle operations.
418-
void populateVectorLinearizeShuffleLikeOpsPatterns(
419-
const TypeConverter &typeConverter, RewritePatternSet &patterns,
420-
ConversionTarget &target, unsigned targetBitWidth);
409+
/// Initialize `typeConverter` and `conversionTarget` for vector linearization.
410+
/// This registers (1) which operations are legal and hence should not be
411+
/// linearized, (2) what converted types are (rank-1 vectors) and how to
412+
/// materialze the conversion (with shape_cast)
413+
///
414+
/// Note: the set of legal operations can be extended by a user if for example
415+
/// certain rank>1 vectors are considered valid, but adding additional
416+
/// dynamically legal ops to `conversionTarget`.
417+
void populateForVectorLinearize(TypeConverter &typeConverter,
418+
ConversionTarget &conversionTarget);
419+
420+
/// Populates `patterns` for ND vector (N >= 2) linearization. This currently
421+
/// contains patterns for converting ConstantLike, Vectorizable, and
422+
/// vector::BitCast ops.
423+
void populateVectorLinearizeBasePatterns(const TypeConverter &,
424+
const ConversionTarget &,
425+
RewritePatternSet &patterns);
426+
427+
/// Populates `patterns` for linearizing ND (N >= 2) vector operations
428+
/// to 1D vector shuffle operations.
429+
void populateVectorLinearizeShuffleLikeOpsPatterns(const TypeConverter &,
430+
const ConversionTarget &,
431+
RewritePatternSet &patterns);
421432

422433
} // namespace vector
423434
} // namespace mlir

0 commit comments

Comments
 (0)