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

[IR] Add control flag for ir inplace pass #57090

Merged
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
19 changes: 13 additions & 6 deletions paddle/fluid/framework/executor_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "paddle/ir/core/value.h"
#include "paddle/ir/pass/pass.h"
#include "paddle/ir/pass/pass_manager.h"
#include "paddle/phi/core/flags.h"

PHI_DECLARE_bool(new_ir_apply_inplace_pass);

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -444,9 +447,11 @@ std::unique_ptr<::ir::Program> ConstructFowardIrProgram(

auto ir_res = paddle::dialect::PdOpLowerToKernelPass(program.get());

::ir::PassManager pm(::ir::IrContext::Instance(), 3);
pm.AddPass(::ir::CreateInplacePass());
pm.Run(ir_res.get());
if (FLAGS_new_ir_apply_inplace_pass) {
::ir::PassManager pm(::ir::IrContext::Instance(), 3);
pm.AddPass(::ir::CreateInplacePass());
pm.Run(ir_res.get());
}

return ir_res;
}
Expand Down Expand Up @@ -521,9 +526,11 @@ std::unique_ptr<::ir::Program> ConstructBackwardIrProgram(

auto res = paddle::dialect::PdOpLowerToKernelPass(program.get());

::ir::PassManager pm(::ir::IrContext::Instance(), 3);
pm.AddPass(::ir::CreateInplacePass());
pm.Run(res.get());
if (FLAGS_new_ir_apply_inplace_pass) {
::ir::PassManager pm(::ir::IrContext::Instance(), 3);
pm.AddPass(::ir::CreateInplacePass());
pm.Run(res.get());
}

return res;
}
Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/ir/transforms/inplace_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ class InplacePass : public ir::Pass {
"is_inplace",
ir::BoolAttribute::get(ir::IrContext::Instance(), true));
}
LOG_FIRST_N(INFO, 1)
<< "Apply inplace pass on lowering ::ir::Program to Kernel Dialect.";
}

bool CanApplyOn(ir::Operation* op) const override {
Expand Down