From 45ba9cf0fc4d9a0f7d187626eaeaa2c8ba80270b Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Wed, 14 Jun 2023 09:50:06 +0800 Subject: [PATCH] [IR]Polish ProgramTranslator private member code style (#54470) * [IR]Polish ProgramTranslator private member code style * update blog --- .../translator/program_translator.cc | 58 +++++++++---------- .../translator/program_translator.h | 12 ++-- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/paddle/fluid/ir_adaptor/translator/program_translator.cc b/paddle/fluid/ir_adaptor/translator/program_translator.cc index 77f27ba710c..ccb43c8a058 100644 --- a/paddle/fluid/ir_adaptor/translator/program_translator.cc +++ b/paddle/fluid/ir_adaptor/translator/program_translator.cc @@ -40,8 +40,8 @@ using VarDesc = ::paddle::framework::VarDesc; ProgramTranslator::ProgramTranslator(const ProgramDesc* legacy_program, ir::Program* program) - : legacy_program(legacy_program), program(program) { - ctx = ir::IrContext::Instance(); + : legacy_program_(legacy_program), program_(program) { + ctx_ = ir::IrContext::Instance(); } const std::unordered_set ProgramTranslator::no_cast_var_names = { @@ -51,24 +51,24 @@ const std::unordered_set ProgramTranslator::no_cast_var_names = { void ProgramTranslator::Translate() { PADDLE_ENFORCE_EQ( - legacy_program->Size(), + legacy_program_->Size(), 1u, platform::errors::PreconditionNotMet( "Not support multi block ProgramDesc translated, now has %d blocks", - legacy_program->Size())); + legacy_program_->Size())); - for (size_t block_idx = 0; block_idx < legacy_program->Size(); block_idx++) { - const BlockDesc& block = legacy_program->Block(block_idx); + for (size_t block_idx = 0; block_idx < legacy_program_->Size(); block_idx++) { + const BlockDesc& block = legacy_program_->Block(block_idx); GetParameterForSingleBlock(block); } - for (size_t block_idx = 0; block_idx < legacy_program->Size(); block_idx++) { - const BlockDesc& block = legacy_program->Block(block_idx); + for (size_t block_idx = 0; block_idx < legacy_program_->Size(); block_idx++) { + const BlockDesc& block = legacy_program_->Block(block_idx); InsertOperationToSingleBlock(block); } - for (size_t block_idx = 0; block_idx < legacy_program->Size(); block_idx++) { - const BlockDesc& block = legacy_program->Block(block_idx); + for (size_t block_idx = 0; block_idx < legacy_program_->Size(); block_idx++) { + const BlockDesc& block = legacy_program_->Block(block_idx); SetParameterFromSingleBlock(block); } } @@ -105,28 +105,28 @@ inline ir::Operation* InsertSetParamaterOp(ir::IrContext* ctx, void ProgramTranslator::GetParameterForSingleBlock(const BlockDesc& block) { for (auto& var : block.AllVars()) { if (!var->Persistable()) continue; - if (param_map.count(var->Name()) != 0) continue; + if (param_map_.count(var->Name()) != 0) continue; if (no_cast_var_names.count(var->Name()) != 0) continue; - parameter_name_mappings[var->Name()] = var; + parameter_name_mappings_[var->Name()] = var; } for (auto op_desc : block.AllOps()) { for (const auto& n : op_desc->Inputs()) { const auto& input_var_names = n.second; for (const auto& var_name : input_var_names) { - bool need_get_parameter_op = (parameter_name_mappings.find(var_name) != - parameter_name_mappings.end()); - need_get_parameter_op &= (parameter_visited.count(var_name) == 0); + bool need_get_parameter_op = (parameter_name_mappings_.find(var_name) != + parameter_name_mappings_.end()); + need_get_parameter_op &= (parameter_visited_.count(var_name) == 0); if (need_get_parameter_op) { ir::Operation* op = - InsertGetParamaterOp(ctx, parameter_name_mappings[var_name]); - program->block()->push_back(op); - param_map[var_name] = VariableDefiningInfo(op->result(0)); + InsertGetParamaterOp(ctx_, parameter_name_mappings_[var_name]); + program_->block()->push_back(op); + param_map_[var_name] = VariableDefiningInfo(op->result(0)); VLOG(10) << "[op translated][get parameter]" << op; - program->SetParameter(var_name, nullptr); - parameter_visited.insert(var_name); + program_->SetParameter(var_name, nullptr); + parameter_visited_.insert(var_name); } } } @@ -137,7 +137,7 @@ void ProgramTranslator::InsertOperationToSingleBlock(const BlockDesc& block) { auto& op_translator = OpTranslator::instance(); for (auto op : block.AllOps()) { OpTranslateFn& fn = op_translator[op->Type()]; - ir::Operation* operation = fn(ctx, ¶m_map, program, *op); + ir::Operation* operation = fn(ctx_, ¶m_map_, program_, *op); VLOG(10) << "[op translated][special]" << operation; } } @@ -148,15 +148,15 @@ void ProgramTranslator::SetParameterFromSingleBlock(const BlockDesc& block) { for (const auto& n : (*op_desc)->Outputs()) { const auto& output_var_names = n.second; for (const auto& var_name : output_var_names) { - bool need_set_parameter_op = (parameter_name_mappings.find(var_name) != - parameter_name_mappings.end()); - need_set_parameter_op &= (parameter_visited.count(var_name) == 0); + bool need_set_parameter_op = (parameter_name_mappings_.find(var_name) != + parameter_name_mappings_.end()); + need_set_parameter_op &= (parameter_visited_.count(var_name) == 0); if (need_set_parameter_op) { - ir::OpResult defining_op_result = param_map[var_name].value; + ir::OpResult defining_op_result = param_map_[var_name].value; ir::Operation* op = InsertSetParamaterOp( - ctx, defining_op_result, parameter_name_mappings[var_name]); + ctx_, defining_op_result, parameter_name_mappings_[var_name]); - ir::Block* block = program->block(); + ir::Block* block = program_->block(); ir::Block::iterator insert_pos = std::find( block->begin(), block->end(), defining_op_result.owner()); @@ -169,8 +169,8 @@ void ProgramTranslator::SetParameterFromSingleBlock(const BlockDesc& block) { block->insert(insert_pos, op); VLOG(10) << "[op translated][set parameter]" << op; - program->SetParameter(var_name, nullptr); - parameter_visited.insert(var_name); + program_->SetParameter(var_name, nullptr); + parameter_visited_.insert(var_name); } } } diff --git a/paddle/fluid/ir_adaptor/translator/program_translator.h b/paddle/fluid/ir_adaptor/translator/program_translator.h index cd9b1b4a81f..ec479aad730 100644 --- a/paddle/fluid/ir_adaptor/translator/program_translator.h +++ b/paddle/fluid/ir_adaptor/translator/program_translator.h @@ -59,13 +59,13 @@ class ProgramTranslator { void Translate(); private: - const ProgramDesc* legacy_program; // not owned - ir::Program* program; // not owned - ir::IrContext* ctx; // not owned + const ProgramDesc* legacy_program_; // not owned + ir::Program* program_; // not owned + ir::IrContext* ctx_; // not owned - TranslationContext param_map; - std::unordered_map parameter_name_mappings; - std::unordered_set parameter_visited; + TranslationContext param_map_; + std::unordered_map parameter_name_mappings_; + std::unordered_set parameter_visited_; /// In the legacy program desc, there are two special named varibales: /// 1. "feed", the input variable of feed op -- GitLab