未验证 提交 1ae9239e 编写于 作者: 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
上级 77cdbdce
......@@ -176,7 +176,7 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING)
# FPGA_DEPS ${fpga_kernels})
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.
......
......@@ -77,29 +77,5 @@ std::shared_ptr<PaddlePredictor> CreatePaddlePredictor(
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 paddle
......@@ -13,6 +13,7 @@
// limitations under the License.
#include "lite/api/paddle_api.h"
#include "lite/core/device_info.h"
#include "lite/core/tensor.h"
namespace paddle {
......@@ -73,5 +74,30 @@ std::shared_ptr<PaddlePredictor> CreatePaddlePredictor(const ConfigT &) {
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 paddle
......@@ -90,11 +90,20 @@ class LITE_API PaddlePredictor {
/// Base class for all the configs.
class LITE_API ConfigBase {
std::string model_dir_;
int threads_{1};
PowerMode mode_{LITE_POWER_NO_BIND};
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; }
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.
......@@ -129,16 +138,11 @@ class LITE_API CxxConfig : public ConfigBase {
/// MobileConfig is the config for the light weight predictor, it will skip
/// IR optimization or other unnecessary stages.
class LITE_API MobileConfig : public ConfigBase {
PowerMode mode_{LITE_POWER_HIGH};
int threads_{1};
std::string model_buffer_;
std::string param_buffer_;
bool model_from_memory_{false};
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,
size_t model_buffer_size,
const char* param_buffer,
......@@ -148,8 +152,6 @@ class LITE_API MobileConfig : public ConfigBase {
model_from_memory_ = true;
}
PowerMode power_mode() const { return mode_; }
int threads() const { return threads_; }
bool model_from_memory() const { return model_from_memory_; }
const std::string& model_buffer() const { return model_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.
先完成此消息的编辑!
想要评论请 注册