diff --git a/lite/api/CMakeLists.txt b/lite/api/CMakeLists.txt index 97a6fb3072e6b213810dd4425775f6b7136a917e..173de922f930e8c3aa624c9b8808d6bc0f975926 100644 --- a/lite/api/CMakeLists.txt +++ b/lite/api/CMakeLists.txt @@ -176,22 +176,6 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING) # FPGA_DEPS ${fpga_kernels}) 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) #----------------------------------------------------------------------------------------------------- @@ -216,6 +200,22 @@ endif() 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) add_subdirectory(android) endif() diff --git a/lite/api/light_api_impl.cc b/lite/api/light_api_impl.cc index 69ec5cc496c9ea53cc1206c2706a64ae9b5d434c..5aa9bfb0857050bc0a8a0242249829c0cf59ae83 100644 --- a/lite/api/light_api_impl.cc +++ b/lite/api/light_api_impl.cc @@ -43,11 +43,7 @@ class LightPredictorImpl : public PaddlePredictor { }; void LightPredictorImpl::Init(const MobileConfig& config) { -// 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 + // LightPredictor Only support NaiveBuffer backend in publish lib raw_predictor_.reset(new lite::LightPredictor(config.model_dir(), config.model_buffer(), config.param_buffer(), @@ -81,5 +77,29 @@ std::shared_ptr 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 diff --git a/lite/api/paddle_api.h b/lite/api/paddle_api.h index df51ce84b2d5ea99bfff9e96f96e17d73eec77e8..36a6a16ee52a87560ac9c9239041e54266eb50a7 100644 --- a/lite/api/paddle_api.h +++ b/lite/api/paddle_api.h @@ -136,14 +136,9 @@ class LITE_API MobileConfig : public ConfigBase { bool model_from_memory_{false}; public: - MobileConfig(Place preferred_place = Place(TARGET(kARM), - PRECISION(kFloat), - DATALAYOUT(kNCHW)), - 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; } + 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,