From f66e4a5ebf190c7972f2c0faacd91ca7deda5977 Mon Sep 17 00:00:00 2001 From: DannyIsFunny <912790387@qq.com> Date: Sun, 26 Apr 2020 11:51:25 +0000 Subject: [PATCH] test=develop --- lite/api/cxx_api_impl.cc | 57 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/lite/api/cxx_api_impl.cc b/lite/api/cxx_api_impl.cc index ed2145a580..c327d47c99 100644 --- a/lite/api/cxx_api_impl.cc +++ b/lite/api/cxx_api_impl.cc @@ -34,38 +34,43 @@ namespace lite { void CxxPaddleApiImpl::Init(const lite_api::CxxConfig &config) { config_ = config; - auto places = config.valid_places(); - std::vector passes{}; + if (!status_is_cloned_) { + auto places = config.valid_places(); + std::vector passes{}; #ifdef LITE_WITH_CUDA - // if kCUDA is included in valid places, it should be initialized first, - // otherwise skip this step. - for (auto &p : places) { - if (p.target == TARGET(kCUDA)) { - Env::Init(); - if (config_.multi_stream()) { - passes = {"multi_stream_analysis_pass"}; - VLOG(3) << "add pass: " << passes[0]; + // if kCUDA is included in valid places, it should be initialized first, + // otherwise skip this step. + for (auto &p : places) { + if (p.target == TARGET(kCUDA)) { + Env::Init(); + if (config_.multi_stream()) { + passes = {"multi_stream_analysis_pass"}; + VLOG(3) << "add pass: " << passes[0]; + } + break; } - break; } - } #endif #ifdef LITE_WITH_MLU - Env::Init(); - lite::DeviceInfo::Global().SetMLURunMode(config.mlu_core_version(), - config.mlu_core_number(), - config.mlu_use_first_conv(), - config.mlu_first_conv_mean(), - config.mlu_first_conv_std(), - config.mlu_input_layout()); + Env::Init(); + lite::DeviceInfo::Global().SetMLURunMode(config.mlu_core_version(), + config.mlu_core_number(), + config.mlu_use_first_conv(), + config.mlu_first_conv_mean(), + config.mlu_first_conv_std(), + config.mlu_input_layout()); #endif // LITE_WITH_MLU - auto use_layout_preprocess_pass = - config.model_dir().find("OPENCL_PRE_PRECESS"); - VLOG(1) << "use_layout_preprocess_pass:" << use_layout_preprocess_pass; - if (places[0].target == TARGET(kOpenCL) && - use_layout_preprocess_pass != std::string::npos) { - passes = {"type_layout_cast_preprocess_pass"}; - VLOG(1) << "add pass:" << passes[0]; + auto use_layout_preprocess_pass = + config.model_dir().find("OPENCL_PRE_PRECESS"); + VLOG(1) << "use_layout_preprocess_pass:" << use_layout_preprocess_pass; + if (places[0].target == TARGET(kOpenCL) && + use_layout_preprocess_pass != std::string::npos) { + passes = {"type_layout_cast_preprocess_pass"}; + VLOG(1) << "add pass:" << passes[0]; + } + raw_predictor_->Build(config, places, passes); + } else { + CHECK(raw_predictor_) << "The Predictor can not be nullptr in Clone mode."; } mode_ = config.power_mode(); threads_ = config.threads(); -- GitLab