提交 6aba3b8b 编写于 作者: H huzhiqiang 提交者: GitHub

move the method of SetThread and SetPowerMode from MobileConfig into ConfigBase (#2147)

* move the method of SetThread and SetPowerMode from MobileConfig into ConfigBase 
* cxxPredictor will support SetThread and SetPowerMode method
上级 74074146
...@@ -176,7 +176,7 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING) ...@@ -176,7 +176,7 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING)
# FPGA_DEPS ${fpga_kernels}) # FPGA_DEPS ${fpga_kernels})
endif() endif()
lite_cc_library(paddle_api SRCS paddle_api.cc DEPS op_params tensor) lite_cc_library(paddle_api SRCS paddle_api.cc DEPS op_params tensor device_info)
#----------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------
# The final inference library for both CxxConfig and MobileConfig. # The final inference library for both CxxConfig and MobileConfig.
......
...@@ -77,29 +77,5 @@ std::shared_ptr<PaddlePredictor> CreatePaddlePredictor( ...@@ -77,29 +77,5 @@ std::shared_ptr<PaddlePredictor> CreatePaddlePredictor(
return x; return x;
} }
MobileConfig::MobileConfig(PowerMode mode, int threads) {
#ifdef LITE_WITH_ARM
lite::DeviceInfo::Global().SetRunMode(mode, threads);
mode_ = lite::DeviceInfo::Global().mode();
threads_ = lite::DeviceInfo::Global().threads();
#endif
}
void MobileConfig::set_power_mode(paddle::lite_api::PowerMode mode) {
#ifdef LITE_WITH_ARM
lite::DeviceInfo::Global().SetRunMode(mode, threads_);
mode_ = lite::DeviceInfo::Global().mode();
threads_ = lite::DeviceInfo::Global().threads();
#endif
}
void MobileConfig::set_threads(int threads) {
#ifdef LITE_WITH_ARM
lite::DeviceInfo::Global().SetRunMode(mode_, threads);
mode_ = lite::DeviceInfo::Global().mode();
threads_ = lite::DeviceInfo::Global().threads();
#endif
}
} // namespace lite_api } // namespace lite_api
} // namespace paddle } // namespace paddle
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include "lite/api/paddle_api.h" #include "lite/api/paddle_api.h"
#include "lite/core/device_info.h"
#include "lite/core/tensor.h" #include "lite/core/tensor.h"
namespace paddle { namespace paddle {
...@@ -73,5 +74,30 @@ std::shared_ptr<PaddlePredictor> CreatePaddlePredictor(const ConfigT &) { ...@@ -73,5 +74,30 @@ std::shared_ptr<PaddlePredictor> CreatePaddlePredictor(const ConfigT &) {
return std::shared_ptr<PaddlePredictor>(); return std::shared_ptr<PaddlePredictor>();
} }
ConfigBase::ConfigBase(PowerMode mode, int threads) {
#ifdef LITE_WITH_ARM
lite::DeviceInfo::Init();
lite::DeviceInfo::Global().SetRunMode(mode, threads);
mode_ = lite::DeviceInfo::Global().mode();
threads_ = lite::DeviceInfo::Global().threads();
#endif
}
void ConfigBase::set_power_mode(paddle::lite_api::PowerMode mode) {
#ifdef LITE_WITH_ARM
lite::DeviceInfo::Global().SetRunMode(mode, threads_);
mode_ = lite::DeviceInfo::Global().mode();
threads_ = lite::DeviceInfo::Global().threads();
#endif
}
void ConfigBase::set_threads(int threads) {
#ifdef LITE_WITH_ARM
lite::DeviceInfo::Global().SetRunMode(mode_, threads);
mode_ = lite::DeviceInfo::Global().mode();
threads_ = lite::DeviceInfo::Global().threads();
#endif
}
} // namespace lite_api } // namespace lite_api
} // namespace paddle } // namespace paddle
...@@ -90,11 +90,20 @@ class LITE_API PaddlePredictor { ...@@ -90,11 +90,20 @@ class LITE_API PaddlePredictor {
/// Base class for all the configs. /// Base class for all the configs.
class LITE_API ConfigBase { class LITE_API ConfigBase {
std::string model_dir_; std::string model_dir_;
int threads_{1};
PowerMode mode_{LITE_POWER_NO_BIND};
public: public:
explicit ConfigBase(PowerMode mode = LITE_POWER_NO_BIND, int threads = 1);
// set Model_dir
void set_model_dir(const std::string& x) { model_dir_ = x; } void set_model_dir(const std::string& x) { model_dir_ = x; }
const std::string& model_dir() const { return model_dir_; } const std::string& model_dir() const { return model_dir_; }
// set Power_mode
void set_power_mode(PowerMode mode);
PowerMode power_mode() const { return mode_; }
// set Thread
void set_threads(int threads);
int threads() const { return threads_; }
}; };
/// CxxConfig is the config for the Full feature predictor. /// CxxConfig is the config for the Full feature predictor.
...@@ -129,16 +138,11 @@ class LITE_API CxxConfig : public ConfigBase { ...@@ -129,16 +138,11 @@ class LITE_API CxxConfig : public ConfigBase {
/// MobileConfig is the config for the light weight predictor, it will skip /// MobileConfig is the config for the light weight predictor, it will skip
/// IR optimization or other unnecessary stages. /// IR optimization or other unnecessary stages.
class LITE_API MobileConfig : public ConfigBase { class LITE_API MobileConfig : public ConfigBase {
PowerMode mode_{LITE_POWER_HIGH};
int threads_{1};
std::string model_buffer_; std::string model_buffer_;
std::string param_buffer_; std::string param_buffer_;
bool model_from_memory_{false}; bool model_from_memory_{false};
public: public:
explicit MobileConfig(PowerMode mode = LITE_POWER_NO_BIND, int threads = 1);
void set_power_mode(PowerMode mode);
void set_threads(int threads);
void set_model_buffer(const char* model_buffer, void set_model_buffer(const char* model_buffer,
size_t model_buffer_size, size_t model_buffer_size,
const char* param_buffer, const char* param_buffer,
...@@ -148,8 +152,6 @@ class LITE_API MobileConfig : public ConfigBase { ...@@ -148,8 +152,6 @@ class LITE_API MobileConfig : public ConfigBase {
model_from_memory_ = true; model_from_memory_ = true;
} }
PowerMode power_mode() const { return mode_; }
int threads() const { return threads_; }
bool model_from_memory() const { return model_from_memory_; } bool model_from_memory() const { return model_from_memory_; }
const std::string& model_buffer() const { return model_buffer_; } const std::string& model_buffer() const { return model_buffer_; }
const std::string& param_buffer() const { return param_buffer_; } const std::string& param_buffer() const { return param_buffer_; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册