From d318a34e07388a9a6fac0f584ac85e8b460beb06 Mon Sep 17 00:00:00 2001 From: liuruilong Date: Sun, 14 Oct 2018 17:05:49 +0800 Subject: [PATCH] add clear act when dealloc --- src/io/api_paddle_mobile.cc | 5 +++++ src/io/api_paddle_mobile.h | 4 ++-- src/io/paddle_inference_api.h | 4 +++- test/framework/test_inference_api.cpp | 7 ++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/io/api_paddle_mobile.cc b/src/io/api_paddle_mobile.cc index 4609438ec9..b07232867c 100644 --- a/src/io/api_paddle_mobile.cc +++ b/src/io/api_paddle_mobile.cc @@ -101,6 +101,11 @@ bool PaddleMobilePredictor::Run( return true; } +template +PaddleMobilePredictor::~PaddleMobilePredictor() { + paddle_mobile_->Clear(); +} + // A factory to help create difference predictor. template <> std::unique_ptr diff --git a/src/io/api_paddle_mobile.h b/src/io/api_paddle_mobile.h index 66c6a4d5d9..bdeb7e1865 100644 --- a/src/io/api_paddle_mobile.h +++ b/src/io/api_paddle_mobile.h @@ -32,7 +32,7 @@ namespace paddle_mobile { template class PaddleMobilePredictor : public PaddlePredictor { public: - PaddleMobilePredictor() {} + PaddleMobilePredictor() = delete; explicit PaddleMobilePredictor(const PaddleMobileConfig& config); @@ -40,7 +40,7 @@ class PaddleMobilePredictor : public PaddlePredictor { std::vector* output_data, int batch_size = -1) override; - ~PaddleMobilePredictor() override{}; + ~PaddleMobilePredictor() override; private: std::unique_ptr> paddle_mobile_; diff --git a/src/io/paddle_inference_api.h b/src/io/paddle_inference_api.h index 97564f4132..104ba11153 100644 --- a/src/io/paddle_inference_api.h +++ b/src/io/paddle_inference_api.h @@ -87,7 +87,6 @@ enum class PaddleEngineKind { class PaddlePredictor { public: struct Config; - PaddlePredictor() = default; PaddlePredictor(const PaddlePredictor&) = delete; PaddlePredictor& operator=(const PaddlePredictor&) = delete; @@ -107,6 +106,9 @@ class PaddlePredictor { struct Config { std::string model_dir; // path to the model directory. }; + + protected: + PaddlePredictor() = default; }; struct PaddleMobileConfig : public PaddlePredictor::Config { diff --git a/test/framework/test_inference_api.cpp b/test/framework/test_inference_api.cpp index 7dec2fe297..e1713bb203 100644 --- a/test/framework/test_inference_api.cpp +++ b/test/framework/test_inference_api.cpp @@ -46,7 +46,12 @@ int main() { tensor_out.dtype = PaddleDType::FLOAT32; std::vector outputs(1, tensor_out); - assert(predictor->Run(paddle_tensor_feeds, &outputs)); + std::cout << " before predict " << std::endl; + + predictor->Run(paddle_tensor_feeds, &outputs); + + std::cout << " after predict " << std::endl; + // assert(); float* data_o = static_cast(outputs[0].data.data()); for (size_t j = 0; j < outputs[0].data.length() / sizeof(float); ++j) { -- GitLab