From 36594017dd8d6654221c109c4637dd7189b176cf Mon Sep 17 00:00:00 2001 From: tensor-tang Date: Tue, 5 Jun 2018 14:32:01 +0800 Subject: [PATCH] make infer init explicit --- paddle/contrib/inference/paddle_inference_api_impl.cc | 11 ++++++----- paddle/contrib/inference/paddle_inference_api_impl.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/paddle/contrib/inference/paddle_inference_api_impl.cc b/paddle/contrib/inference/paddle_inference_api_impl.cc index 2d710727e2..bda2981a14 100644 --- a/paddle/contrib/inference/paddle_inference_api_impl.cc +++ b/paddle/contrib/inference/paddle_inference_api_impl.cc @@ -54,7 +54,8 @@ std::string num2str(T a) { } } // namespace -bool NativePaddlePredictor::Init(std::shared_ptr scope) { +bool NativePaddlePredictor::Init( + std::shared_ptr parent_scope) { VLOG(3) << "Predictor::init()"; if (config_.use_gpu) { @@ -62,9 +63,9 @@ bool NativePaddlePredictor::Init(std::shared_ptr scope) { } else { place_ = paddle::platform::CPUPlace(); } - if (scope) { - scope_ = scope; - sub_scope_ = &(scope->NewScope()); + if (parent_scope) { + scope_ = parent_scope; + sub_scope_ = &(parent_scope->NewScope()); } else { paddle::framework::InitDevices(false); scope_.reset(new paddle::framework::Scope()); @@ -275,7 +276,7 @@ CreatePaddlePredictor( } std::unique_ptr predictor(new NativePaddlePredictor(config)); - if (!dynamic_cast(predictor.get())->Init()) { + if (!dynamic_cast(predictor.get())->Init(nullptr)) { return nullptr; } return std::move(predictor); diff --git a/paddle/contrib/inference/paddle_inference_api_impl.h b/paddle/contrib/inference/paddle_inference_api_impl.h index dfb34a8631..86d1db7bcc 100644 --- a/paddle/contrib/inference/paddle_inference_api_impl.h +++ b/paddle/contrib/inference/paddle_inference_api_impl.h @@ -35,7 +35,7 @@ class NativePaddlePredictor : public PaddlePredictor { : config_(config) {} // will only create sub scope if have global scope - bool Init(std::shared_ptr scope = nullptr); + bool Init(std::shared_ptr parent_scope); bool Run(const std::vector &inputs, std::vector *output_data) override; -- GitLab