[mlir][linalg] Retire Linalg's StrategyVectorizePass

We retire linalg's strategy vectorize pass. Our goal is to use transform dialect instead of passes.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D133684
This commit is contained in:
Guray Ozen 2022-09-15 10:45:46 +02:00
parent 220d850823
commit 51e0946591
4 changed files with 1 additions and 134 deletions

View File

@ -134,15 +134,6 @@ std::unique_ptr<OperationPass<func::FuncOp>> createLinalgStrategyPeelPass(
const linalg::LinalgTransformationFilter &filter =
linalg::LinalgTransformationFilter());
/// Create a LinalgStrategyVectorizePass.
std::unique_ptr<OperationPass<func::FuncOp>> createLinalgStrategyVectorizePass(
StringRef opName = "",
linalg::LinalgVectorizationOptions opt =
linalg::LinalgVectorizationOptions(),
const linalg::LinalgTransformationFilter &filter =
linalg::LinalgTransformationFilter(),
bool padVectorize = false);
/// Create a LinalgStrategyLowerVectorsPass.
std::unique_ptr<OperationPass<func::FuncOp>>
createLinalgStrategyLowerVectorsPass(

View File

@ -238,21 +238,6 @@ def LinalgStrategyPeelPass
];
}
def LinalgStrategyVectorizePass
: Pass<"linalg-strategy-vectorize-pass", "func::FuncOp"> {
let summary = "Configurable pass to apply pattern-based linalg vectorization.";
let constructor = "mlir::createLinalgStrategyVectorizePass()";
let dependentDialects = ["linalg::LinalgDialect"];
let options = [
Option<"anchorFuncName", "anchor-func", "std::string", /*default=*/"",
"Which func op is the anchor to latch on.">,
Option<"anchorOpName", "anchor-op", "std::string", /*default=*/"",
"Which linalg op within the func is the anchor to latch on.">,
Option<"vectorizePadding", "vectorize-padding", "bool", "false",
"Enable vectorization of padding ops.">,
];
}
def LinalgStrategyLowerVectorsPass
: Pass<"linalg-strategy-lower-vectors-pass", "func::FuncOp"> {
let summary = "Configurable pass to lower vector operations.";

View File

@ -112,32 +112,6 @@ private:
linalg::LinalgPeelOptions options;
};
/// Represent one application of createLinalgStrategyVectorizePass.
struct Vectorize : public Transformation {
explicit Vectorize(linalg::LinalgVectorizationOptions options,
LinalgTransformationFilter::FilterFunction f = nullptr,
bool padVectorize = false)
: Transformation(std::move(f)), options(options),
vectorizePadding(padVectorize) {}
Vectorize(StringRef name, linalg::LinalgVectorizationOptions options,
LinalgTransformationFilter::FilterFunction f = nullptr,
bool padVectorize = false)
: Transformation(std::move(f)), opName(name), options(options),
vectorizePadding(padVectorize) {}
void addToPassPipeline(OpPassManager &pm,
LinalgTransformationFilter m) const override {
pm.addPass(createLinalgStrategyVectorizePass(opName, options, m,
vectorizePadding));
}
private:
std::string opName;
linalg::LinalgVectorizationOptions options;
bool vectorizePadding;
};
/// Represent one application of createLinalgStrategyLowerVectorsPass.
struct VectorLowering : public Transformation {
explicit VectorLowering(
@ -203,7 +177,7 @@ struct CodegenStrategy {
padIf(bool b, StringRef opName, linalg::LinalgPaddingOptions options,
LinalgTransformationFilter::FilterFunction f = nullptr) {
return b ? pad(opName, std::move(options), std::move(f)) : *this;
}
}
/// Append patterns to decompose convolutions.
CodegenStrategy &
decompose(const LinalgTransformationFilter::FilterFunction &f = nullptr) {
@ -229,23 +203,6 @@ struct CodegenStrategy {
LinalgTransformationFilter::FilterFunction f = nullptr) {
return b ? peel(opName, options, std::move(f)) : *this;
}
/// Append a pattern to rewrite `LinalgOpType` as a vector operation.
CodegenStrategy &
vectorize(StringRef opName,
const LinalgTransformationFilter::FilterFunction &f = nullptr,
bool vectorizePadding = false) {
transformationSequence.emplace_back(std::make_unique<Vectorize>(
opName, linalg::LinalgVectorizationOptions(), f, vectorizePadding));
return *this;
}
/// Conditionally append a pattern to rewrite `LinalgOpType` as a vector
/// operation.
CodegenStrategy &
vectorizeIf(bool b, StringRef opName,
LinalgTransformationFilter::FilterFunction f = nullptr,
bool vectorizePadding = false) {
return b ? vectorize(opName, std::move(f), vectorizePadding) : *this;
}
/// Append a pattern to lower all vector operations.
CodegenStrategy &vectorLowering(LinalgVectorLoweringOptions options) {
transformationSequence.emplace_back(

View File

@ -40,7 +40,6 @@ namespace mlir {
#define GEN_PASS_DEF_LINALGSTRATEGYPADPASS
#define GEN_PASS_DEF_LINALGSTRATEGYDECOMPOSEPASS
#define GEN_PASS_DEF_LINALGSTRATEGYPEELPASS
#define GEN_PASS_DEF_LINALGSTRATEGYVECTORIZEPASS
#define GEN_PASS_DEF_LINALGSTRATEGYLOWERVECTORSPASS
#define GEN_PASS_DEF_LINALGSTRATEGYREMOVEMARKERSPASS
#include "mlir/Dialect/Linalg/Passes.h.inc"
@ -215,62 +214,6 @@ struct LinalgStrategyPeelPass
LinalgTransformationFilter filter;
};
/// Configurable pass to apply pattern-based linalg vectorization.
struct LinalgStrategyVectorizePass
: public impl::LinalgStrategyVectorizePassBase<
LinalgStrategyVectorizePass> {
LinalgStrategyVectorizePass() = default;
LinalgStrategyVectorizePass(StringRef opName, LinalgVectorizationOptions opt,
LinalgTransformationFilter filt,
bool padVectorize = false)
: options(opt), filter(std::move(filt)) {
this->anchorOpName.setValue(opName.str());
this->vectorizePadding.setValue(padVectorize);
}
void runOnOperation() override {
auto funcOp = getOperation();
if (!anchorFuncName.empty() && funcOp.getName() != anchorFuncName)
return;
RewritePatternSet vectorizationPatterns(funcOp.getContext());
if (!anchorOpName.empty()) {
vectorizationPatterns.add<LinalgVectorizationPattern>(
anchorOpName, funcOp.getContext(), options, filter);
} else {
vectorizationPatterns.add<LinalgVectorizationPattern>(funcOp.getContext(),
filter, options);
}
vector::populateVectorTransferPermutationMapLoweringPatterns(
vectorizationPatterns);
vector::populateVectorReductionToContractPatterns(vectorizationPatterns);
vectorizationPatterns.add<linalg::LinalgCopyVTRForwardingPattern,
linalg::LinalgCopyVTWForwardingPattern>(
funcOp.getContext(), /*benefit=*/2);
TransferReadOp::getCanonicalizationPatterns(vectorizationPatterns,
funcOp.getContext());
TransferWriteOp::getCanonicalizationPatterns(vectorizationPatterns,
funcOp.getContext());
(void)applyPatternsAndFoldGreedily(funcOp,
std::move(vectorizationPatterns));
// Apply the pad tensor op vectorization separately to avoid running the
// GenericPadOpVectorizationPattern too early.
// TODO: Improve once we have better infrastructure to control pattern
// application.
if (vectorizePadding) {
RewritePatternSet patterns(funcOp.getContext());
linalg::populatePadOpVectorizationPatterns(patterns);
(void)applyPatternsAndFoldGreedily(funcOp, std::move(patterns));
}
}
LinalgVectorizationOptions options;
LinalgTransformationFilter filter;
};
/// Configurable pass to lower vector operations.
struct LinalgStrategyLowerVectorsPass
: public impl::LinalgStrategyLowerVectorsPassBase<
@ -393,15 +336,6 @@ mlir::createLinalgStrategyPeelPass(StringRef opName,
return std::make_unique<LinalgStrategyPeelPass>(opName, opt, filter);
}
/// Create a LinalgStrategyVectorizePass.
std::unique_ptr<OperationPass<func::FuncOp>>
mlir::createLinalgStrategyVectorizePass(
StringRef opName, LinalgVectorizationOptions opt,
const LinalgTransformationFilter &filter, bool padVectorize) {
return std::make_unique<LinalgStrategyVectorizePass>(opName, opt, filter,
padVectorize);
}
/// Create a LinalgStrategyLowerVectorsPass.
std::unique_ptr<OperationPass<func::FuncOp>>
mlir::createLinalgStrategyLowerVectorsPass(