From bb1cf7ffbba3fb4a116dad96178d4455f14f07eb Mon Sep 17 00:00:00 2001 From: Yiqun Liu Date: Mon, 30 Dec 2019 21:22:19 +0800 Subject: [PATCH] Optimize the execution of RuntimeProgram by saving the bool whether the op is feed/fetch op. (#2703) test=develop --- lite/core/program.cc | 3 +-- lite/core/program.h | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lite/core/program.cc b/lite/core/program.cc index a26e97886f..41d178f015 100644 --- a/lite/core/program.cc +++ b/lite/core/program.cc @@ -137,8 +137,7 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) { void RuntimeProgram::Run() { for (auto& inst : instructions_) { - std::string op_type = inst.op()->op_info()->Type(); - if (op_type == "feed" || op_type == "fetch") continue; + if (inst.is_feed_fetch_op()) continue; inst.Run(); #ifdef LITE_WITH_PROFILE #ifdef LITE_WITH_PRECISION_PROFILE diff --git a/lite/core/program.h b/lite/core/program.h index e3f6642d3a..c845a17c52 100644 --- a/lite/core/program.h +++ b/lite/core/program.h @@ -90,7 +90,12 @@ struct Program { struct Instruction { Instruction(const std::shared_ptr& op, std::unique_ptr&& kernel) - : op_(op), kernel_(std::move(kernel)) {} + : op_(op), kernel_(std::move(kernel)) { + std::string op_type = op->Type(); + if (op_type == "feed" || op_type == "fetch") { + is_feed_fetch_op_ = true; + } + } // Run the instruction. void Run(); @@ -101,6 +106,8 @@ struct Instruction { const KernelBase* kernel() const { return kernel_.get(); } KernelBase* mutable_kernel() { return kernel_.get(); } + bool is_feed_fetch_op() const { return is_feed_fetch_op_; } + #ifdef LITE_WITH_PROFILE void set_profiler(profile::Profiler* profiler) { profiler_ = profiler; @@ -118,6 +125,7 @@ struct Instruction { private: std::shared_ptr op_; std::unique_ptr kernel_; + bool is_feed_fetch_op_{false}; bool first_epoch_{true}; bool has_run_{false}; -- GitLab