From 3a40472b0edee2a939408f2a485165c0f6e9205c Mon Sep 17 00:00:00 2001 From: zhangbo9674 Date: Fri, 8 Sep 2023 01:38:28 +0000 Subject: [PATCH 1/2] add control flag --- paddle/fluid/framework/executor_cache.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/framework/executor_cache.cc b/paddle/fluid/framework/executor_cache.cc index 7a97e67be90c5..f5c4c745cfd51 100644 --- a/paddle/fluid/framework/executor_cache.cc +++ b/paddle/fluid/framework/executor_cache.cc @@ -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 { @@ -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; } @@ -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; } From 1c681a6e18eb134c7e8806c6b850d7b7a0702b66 Mon Sep 17 00:00:00 2001 From: zhangbo9674 Date: Fri, 8 Sep 2023 02:51:50 +0000 Subject: [PATCH 2/2] add log --- paddle/fluid/ir/transforms/inplace_pass.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/paddle/fluid/ir/transforms/inplace_pass.cc b/paddle/fluid/ir/transforms/inplace_pass.cc index c445da1142087..222abc8344895 100644 --- a/paddle/fluid/ir/transforms/inplace_pass.cc +++ b/paddle/fluid/ir/transforms/inplace_pass.cc @@ -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 {