From f5d9336825e8f27fd02c260b5687c78ded61ed67 Mon Sep 17 00:00:00 2001 From: Liu Yiqun Date: Tue, 30 Jan 2018 10:55:07 +0000 Subject: [PATCH] Unify the definition of kFeedOpType and kFetchOpType. --- paddle/framework/executor.cc | 3 --- paddle/framework/feed_fetch_type.h | 4 ++++ paddle/framework/program_desc.cc | 24 +++++++++---------- paddle/framework/program_desc.h | 5 ++-- paddle/framework/prune.cc | 3 +-- paddle/inference/io.cc | 7 +++--- paddle/inference/io.h | 5 ---- .../book/test_inference_recognize_digits.cc | 6 ++--- 8 files changed, 25 insertions(+), 32 deletions(-) diff --git a/paddle/framework/executor.cc b/paddle/framework/executor.cc index cbf3ec75265..4f87cf8b95d 100644 --- a/paddle/framework/executor.cc +++ b/paddle/framework/executor.cc @@ -33,9 +33,6 @@ DEFINE_bool(check_nan_inf, false, namespace paddle { namespace framework { -const std::string kFeedOpType = "feed"; -const std::string kFetchOpType = "fetch"; - Executor::Executor(const platform::Place& place) : place_(place) {} static void CreateTensor(Variable* var, proto::VarDesc::VarType var_type) { diff --git a/paddle/framework/feed_fetch_type.h b/paddle/framework/feed_fetch_type.h index 9bc4a90c448..168f456675a 100644 --- a/paddle/framework/feed_fetch_type.h +++ b/paddle/framework/feed_fetch_type.h @@ -13,6 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ #pragma once +#include #include #include "paddle/framework/lod_tensor.h" @@ -20,5 +21,8 @@ namespace paddle { namespace framework { using FeedFetchType = LoDTensor; using FeedFetchList = std::vector; + +static const std::string kFeedOpType = "feed"; +static const std::string kFetchOpType = "fetch"; } // namespace framework } // namespace paddle diff --git a/paddle/framework/program_desc.cc b/paddle/framework/program_desc.cc index e59e392dfd1..15ea4035c6e 100644 --- a/paddle/framework/program_desc.cc +++ b/paddle/framework/program_desc.cc @@ -14,13 +14,11 @@ limitations under the License. */ #include "paddle/framework/program_desc.h" #include "paddle/framework/block_desc.h" +#include "paddle/framework/feed_fetch_type.h" namespace paddle { namespace framework { -const std::string kFeedOpType = "feed"; -const std::string kFetchOpType = "fetch"; - BlockDesc *ProgramDesc::AppendBlock(const BlockDesc &parent) { auto *b = desc_.add_blocks(); b->set_parent_idx(parent.ID()); @@ -67,26 +65,26 @@ ProgramDesc::ProgramDesc(const std::string &binary_str) { } } -const std::vector ProgramDesc::GetFeedVarNames() { +const std::vector ProgramDesc::GetFeedTargetNames() { BlockDesc *global_block = blocks_[0].get(); - std::vector feed_var_names; + std::vector feed_target_names; for (auto *op : global_block->AllOps()) { - if (op->Type() == "feed") { - feed_var_names.insert(feed_var_names.begin(), op->Output("Out")[0]); + if (op->Type() == kFeedOpType) { + feed_target_names.insert(feed_target_names.begin(), op->Output("Out")[0]); } } - return feed_var_names; + return feed_target_names; } -const std::vector ProgramDesc::GetFetchVarNames() { +const std::vector ProgramDesc::GetFetchTargetNames() { BlockDesc *global_block = blocks_[0].get(); - std::vector fetch_var_names; + std::vector fetch_target_names; for (auto *op : global_block->AllOps()) { - if (op->Type() == "fetch") { - fetch_var_names.push_back(op->Input("X")[0]); + if (op->Type() == kFetchOpType) { + fetch_target_names.push_back(op->Input("X")[0]); } } - return fetch_var_names; + return fetch_target_names; } } // namespace framework diff --git a/paddle/framework/program_desc.h b/paddle/framework/program_desc.h index 2c3883275a2..b9741b31393 100644 --- a/paddle/framework/program_desc.h +++ b/paddle/framework/program_desc.h @@ -45,9 +45,8 @@ class ProgramDesc { proto::ProgramDesc *Proto(); - const std::vector GetFeedVarNames(); - - const std::vector GetFetchVarNames(); + const std::vector GetFeedTargetNames(); + const std::vector GetFetchTargetNames(); private: proto::ProgramDesc desc_; diff --git a/paddle/framework/prune.cc b/paddle/framework/prune.cc index bff8e0bceac..db63cd12c9a 100644 --- a/paddle/framework/prune.cc +++ b/paddle/framework/prune.cc @@ -21,12 +21,11 @@ limitations under the License. */ #include #include +#include "paddle/framework/feed_fetch_type.h" namespace paddle { namespace framework { -const std::string kFeedOpType = "feed"; -const std::string kFetchOpType = "fetch"; const std::string kDropOutOpType = "dropout"; const std::string kBatchNormOpType = "batch_norm"; diff --git a/paddle/inference/io.cc b/paddle/inference/io.cc index d1842ec938f..556f235d164 100644 --- a/paddle/inference/io.cc +++ b/paddle/inference/io.cc @@ -13,13 +13,14 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "paddle/inference/io.h" + #include +#include "paddle/framework/block_desc.h" +#include "paddle/framework/feed_fetch_type.h" namespace paddle { namespace inference { -const std::string kFeedOpType = "feed"; - bool IsParameter(const framework::VarDesc* var, const framework::ProgramDesc* main_program) { if (var->Persistable()) { @@ -27,7 +28,7 @@ bool IsParameter(const framework::VarDesc* var, for (size_t i = 0; i < main_program->Size(); ++i) { const framework::BlockDesc& block = main_program->Block(i); for (auto* op : block.AllOps()) { - if (op->Type() == kFeedOpType) { + if (op->Type() == framework::kFeedOpType) { continue; } for (auto input_argument_name : op->InputArgumentNames()) { diff --git a/paddle/inference/io.h b/paddle/inference/io.h index 400f5af8c53..fa9a620764f 100644 --- a/paddle/inference/io.h +++ b/paddle/inference/io.h @@ -16,18 +16,13 @@ limitations under the License. */ #include #include -#include "paddle/framework/block_desc.h" #include "paddle/framework/executor.h" #include "paddle/framework/program_desc.h" #include "paddle/framework/scope.h" -#include "paddle/framework/var_desc.h" namespace paddle { namespace inference { -bool IsParameter(const framework::VarDesc* var, - const framework::ProgramDesc* main_program); - void LoadPersistables(framework::Executor& executor, framework::Scope& scope, const std::string& dirname, diff --git a/paddle/inference/tests/book/test_inference_recognize_digits.cc b/paddle/inference/tests/book/test_inference_recognize_digits.cc index d8e4c4d7eee..a2cdd607526 100644 --- a/paddle/inference/tests/book/test_inference_recognize_digits.cc +++ b/paddle/inference/tests/book/test_inference_recognize_digits.cc @@ -33,11 +33,11 @@ void TestInference(const std::string& dirname, // 2. Initialize the inference_program and load all parameters from file auto* inference_program = paddle::inference::Load(executor, *scope, dirname); - // 3. Get the feed_var_names and fetch_var_names + // 3. Get the feed_target_names and fetch_target_names const std::vector& feed_target_names = - inference_program->GetFeedVarNames(); + inference_program->GetFeedTargetNames(); const std::vector& fetch_target_names = - inference_program->GetFetchVarNames(); + inference_program->GetFetchTargetNames(); // 4. Prepare inputs std::map feed_targets; -- GitLab