From adb4aa628812e4b6bb5a392866ef641f471ca102 Mon Sep 17 00:00:00 2001 From: haozech Date: Tue, 28 Apr 2020 06:45:19 +0000 Subject: [PATCH] add shared params. test=develop --- lite/api/cxx_api.h | 9 ++++++++- lite/api/cxx_api_impl.cc | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lite/api/cxx_api.h b/lite/api/cxx_api.h index cec8e2ec37..67f9a9d1d8 100644 --- a/lite/api/cxx_api.h +++ b/lite/api/cxx_api.h @@ -80,11 +80,18 @@ class LITE_API Predictor { const std::vector& valid_places, const std::vector& passes = {}); - std::shared_ptr Clone() const { + std::shared_ptr Clone( + cosnst std::vector var_names) const { // CHECK(program_desc_) << "Both program and scope of current predicotr // should be not be nullptr in Clone mode." ; // CHECK(scope_) << "Both program and scope of current predicotr should // be not be nullptr in Clone mode."; + for (auto i : var_names) { + exec_scope_->Var(i); + auto* tensor = scope_->Var(i)->GetMutable(); + auto* sub_tensor = exec_scope_->Var(i)->GetMutable(); + sub_tensor->CopyDataFrom(tensor); + } auto predictor = std::make_shared(program_desc_, scope_, valid_places_); return predictor; diff --git a/lite/api/cxx_api_impl.cc b/lite/api/cxx_api_impl.cc index c327d47c99..5faddd69d0 100644 --- a/lite/api/cxx_api_impl.cc +++ b/lite/api/cxx_api_impl.cc @@ -119,10 +119,11 @@ void CxxPaddleApiImpl::Run() { raw_predictor_->Run(); } -std::shared_ptr CxxPaddleApiImpl::Clone() { +std::shared_ptr CxxPaddleApiImpl::Clone( + cosnst std::vector var_names) { std::lock_guard lock(mutex_); - auto predictor = - std::make_shared(raw_predictor_->Clone()); + auto predictor = std::make_shared( + raw_predictor_->Clone(var_names)); status_is_cloned_ = true; predictor->Init(config_); return predictor; -- GitLab