Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Paddle inference]conv2d_add_act_pass support cutlass #64201

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions paddle/fluid/inference/api/analysis_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -945,11 +945,7 @@ bool AnalysisPredictor::PrepareExecutor() {
// gpu
if (!config_.custom_pass_only_) {
for (const auto &gpu_pass : kPirGpuPasses) {
auto pass = pir::PassRegistry::Instance().Get(gpu_pass);
if (pass->name() == "matmul_add_act_fuse_pass") {
pass->Set("use_cutlass", new bool(config_.use_cutlass_));
}
pass_pm.AddPass(std::move(pass));
pass_pm.AddPass(pir::PassRegistry::Instance().Get(gpu_pass));
}
}

Expand Down Expand Up @@ -990,6 +986,14 @@ bool AnalysisPredictor::PrepareExecutor() {
std::make_unique<pir::PassManager::IRPrinterOption>(
ir_printing_conditions, ir_printing_conditions));
}
// set attr
for (const auto &pass : pass_pm.passes()) {
if (pass->name() == "matmul_add_act_fuse_pass" ||
pass->name() == "conv2d_add_act_fuse_pass" ||
pass->name() == "conv2d_add_fuse_pass") {
pass->Set("use_cutlass", new bool(config_.use_cutlass_));
}
}
pass_pm.Run(pir_program_.get());

// Apply some basic passes required by the framework
Expand Down
3 changes: 3 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/op_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

namespace paddle {
namespace dialect {
// __force_backend__ in ["gpu","gpudnn","cpu",""]
inline const char kForceBackendAttr[] = "__force_backend__";

class IntArrayAttribute : public pir::Attribute {
public:
using Attribute::Attribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ class RemoveRedundantTransposePattern : public paddle::drr::DrrPatternBase {
}
};

class RemoveInvalidTransposePattern : public paddle::drr::DrrPatternBase {
public:
std::string name() const override { return "RemoveInvalidTransposePattern"; }
uint32_t benefit() const override { return 1; }

void operator()(paddle::drr::DrrPatternContext *ctx) const override {
paddle::drr::SourcePattern pat = ctx->SourcePattern();
const auto &transpose =
pat.Op("pd_op.transpose", {{"perm", pat.Attr("perm")}});
pat.Tensor("ret") = transpose(pat.Tensor("arg_transpose"));
pat.AddConstraint([this](const paddle::drr::MatchContext &match_ctx) {
const auto &perm = match_ctx.Attr<std::vector<int>>("perm");
std::vector<int> dst_vector(perm.size());
std::iota(dst_vector.begin(), dst_vector.end(), 0);
for (size_t i = 0; i < perm.size(); i++) {
if (perm[i] != dst_vector[i]) {
return false;
}
}
return true;
});
paddle::drr::ResultPattern res = pat.ResultPattern();
res.Tensor("ret").Assign(res.Tensor("arg_transpose"));
}
};

class RemoveRedundantTransposePass : public pir::PatternRewritePass {
public:
RemoveRedundantTransposePass()
Expand All @@ -63,6 +89,7 @@ class RemoveRedundantTransposePass : public pir::PatternRewritePass {
pir::RewritePatternSet InitializePatterns(pir::IrContext *context) override {
pir::RewritePatternSet ps(context);
ps.Add(paddle::drr::Create<RemoveRedundantTransposePattern>(context));
ps.Add(paddle::drr::Create<RemoveInvalidTransposePattern>(context));
return ps;
}
};
Expand Down
Loading