提交 5c98e002 编写于 作者: X Xiaoyang LI 提交者: Yan Chunwei

fix MobileConfig get mode and threads error (#2134)

上级 845af6e0
...@@ -176,22 +176,6 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING) ...@@ -176,22 +176,6 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING)
# FPGA_DEPS ${fpga_kernels}) # FPGA_DEPS ${fpga_kernels})
endif() endif()
# These tests needs CLI arguments, and is not supported in ARM CI.
# TODO(Superjomn) support latter.
lite_cc_test(test_light_api SRCS light_api_test.cc
DEPS light_api program mir_passes
CL_DEPS ${opencl_kernels}
FPGA_DEPS ${fpga_kernels}
ARGS --optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL)
lite_cc_test(test_apis SRCS apis_test.cc
DEPS cxx_api light_api ${ops}
CL_DEPS ${opencl_kernels}
X86_DEPS ${x86_kernels}
FPGA_DEPS ${fpga_kernels}
ARGS --model_dir=${LITE_MODEL_DIR}/lite_naive_model
--optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL)
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)
#----------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------
...@@ -216,6 +200,22 @@ endif() ...@@ -216,6 +200,22 @@ endif()
bundle_static_library(paddle_api_light paddle_api_light_bundled bundle_light_api) bundle_static_library(paddle_api_light paddle_api_light_bundled bundle_light_api)
#----------------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------------
# These tests needs CLI arguments, and is not supported in ARM CI.
# TODO(Superjomn) support latter.
lite_cc_test(test_light_api SRCS light_api_test.cc
DEPS light_api program mir_passes paddle_api_light
CL_DEPS ${opencl_kernels}
FPGA_DEPS ${fpga_kernels}
ARGS --optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL)
lite_cc_test(test_apis SRCS apis_test.cc
DEPS cxx_api light_api ${ops} paddle_api_light
CL_DEPS ${opencl_kernels}
X86_DEPS ${x86_kernels}
FPGA_DEPS ${fpga_kernels}
ARGS --model_dir=${LITE_MODEL_DIR}/lite_naive_model
--optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL)
if (LITE_WITH_JAVA AND LITE_WITH_ARM) if (LITE_WITH_JAVA AND LITE_WITH_ARM)
add_subdirectory(android) add_subdirectory(android)
endif() endif()
......
...@@ -43,11 +43,7 @@ class LightPredictorImpl : public PaddlePredictor { ...@@ -43,11 +43,7 @@ class LightPredictorImpl : public PaddlePredictor {
}; };
void LightPredictorImpl::Init(const MobileConfig& config) { void LightPredictorImpl::Init(const MobileConfig& config) {
// LightPredictor Only support NaiveBuffer backend in publish lib // LightPredictor Only support NaiveBuffer backend in publish lib
#ifdef LITE_WITH_ARM
lite::DeviceInfo::Init();
lite::DeviceInfo::Global().SetRunMode(config.power_mode(), config.threads());
#endif
raw_predictor_.reset(new lite::LightPredictor(config.model_dir(), raw_predictor_.reset(new lite::LightPredictor(config.model_dir(),
config.model_buffer(), config.model_buffer(),
config.param_buffer(), config.param_buffer(),
...@@ -81,5 +77,29 @@ std::shared_ptr<PaddlePredictor> CreatePaddlePredictor( ...@@ -81,5 +77,29 @@ 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
...@@ -136,14 +136,9 @@ class LITE_API MobileConfig : public ConfigBase { ...@@ -136,14 +136,9 @@ class LITE_API MobileConfig : public ConfigBase {
bool model_from_memory_{false}; bool model_from_memory_{false};
public: public:
MobileConfig(Place preferred_place = Place(TARGET(kARM), explicit MobileConfig(PowerMode mode = LITE_POWER_NO_BIND, int threads = 1);
PRECISION(kFloat), void set_power_mode(PowerMode mode);
DATALAYOUT(kNCHW)), void set_threads(int threads);
PowerMode mode = LITE_POWER_HIGH,
int threads = 1)
: mode_(mode), threads_(threads) {}
void set_power_mode(PowerMode mode) { mode_ = mode; }
void set_threads(int threads) { threads_ = 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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册