未验证 提交 3012088b 编写于 作者: S sangoly 提交者: GitHub

[framework][place] remove prefered_place and kHost in valid_places (#2192)

* [framework][place] remove prefered_place, use place order in valid_place array instead test=develop

* remove kHost from valid_places test=develop
上级 9cc7dfa8
...@@ -145,8 +145,6 @@ inline CxxConfig jcxxconfig_to_cpp_cxxconfig(JNIEnv *env, jobject jcxxconfig) { ...@@ -145,8 +145,6 @@ inline CxxConfig jcxxconfig_to_cpp_cxxconfig(JNIEnv *env, jobject jcxxconfig) {
jmethodID model_dir_method = jmethodID model_dir_method =
env->GetMethodID(cxxconfig_jclazz, "getModelDir", "()Ljava/lang/String;"); env->GetMethodID(cxxconfig_jclazz, "getModelDir", "()Ljava/lang/String;");
jmethodID preferred_place_method = env->GetMethodID(
cxxconfig_jclazz, "getPreferredPlace", "()Lcom/baidu/paddle/lite/Place;");
jmethodID valid_places_method = env->GetMethodID( jmethodID valid_places_method = env->GetMethodID(
cxxconfig_jclazz, "getValidPlaces", "()[Lcom/baidu/paddle/lite/Place;"); cxxconfig_jclazz, "getValidPlaces", "()[Lcom/baidu/paddle/lite/Place;");
...@@ -159,13 +157,6 @@ inline CxxConfig jcxxconfig_to_cpp_cxxconfig(JNIEnv *env, jobject jcxxconfig) { ...@@ -159,13 +157,6 @@ inline CxxConfig jcxxconfig_to_cpp_cxxconfig(JNIEnv *env, jobject jcxxconfig) {
config.set_model_dir(cpp_model_dir); config.set_model_dir(cpp_model_dir);
} }
jobject java_preferred_place =
env->CallObjectMethod(jcxxconfig, preferred_place_method);
if (java_preferred_place != nullptr) {
Place cpp_preferred_place = jplace_to_cpp_place(env, java_preferred_place);
config.set_preferred_place(cpp_preferred_place);
}
jobject object_valid_places = jobject object_valid_places =
env->CallObjectMethod(jcxxconfig, valid_places_method); env->CallObjectMethod(jcxxconfig, valid_places_method);
jobjectArray *java_valid_places = jobjectArray *java_valid_places =
......
...@@ -18,17 +18,8 @@ package com.baidu.paddle.lite; ...@@ -18,17 +18,8 @@ package com.baidu.paddle.lite;
*/ */
public class CxxConfig extends ConfigBase { public class CxxConfig extends ConfigBase {
protected Place preferredPlace;
protected Place[] validPlaces; protected Place[] validPlaces;
public Place getPreferredPlace() {
return preferredPlace;
}
public void setPreferredPlace(Place preferredPlace) {
this.preferredPlace = preferredPlace;
}
public Place[] getValidPlaces() { public Place[] getValidPlaces() {
return validPlaces; return validPlaces;
} }
......
...@@ -51,17 +51,12 @@ bool CompareTensors(const std::string& name, ...@@ -51,17 +51,12 @@ bool CompareTensors(const std::string& name,
TEST(CXXApi_LightApi, optim_model) { TEST(CXXApi_LightApi, optim_model) {
lite::Predictor cxx_api; lite::Predictor cxx_api;
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kX86), PRECISION(kFloat)}, Place{TARGET(kX86), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, // Both works on X86 and ARM Place{TARGET(kARM), PRECISION(kFloat)}, // Both works on X86 and ARM
}); });
// On ARM devices, the preferred X86 target not works, but it can still // On ARM devices, the preferred X86 target not works, but it can still
// select ARM kernels. // select ARM kernels.
cxx_api.Build(FLAGS_model_dir, cxx_api.Build(FLAGS_model_dir, "", "", valid_places);
"",
"",
Place{TARGET(kX86), PRECISION(kFloat)},
valid_places);
cxx_api.SaveModel(FLAGS_optimized_model); cxx_api.SaveModel(FLAGS_optimized_model);
} }
...@@ -72,17 +67,12 @@ TEST(CXXApi_LightApi, save_and_load_model) { ...@@ -72,17 +67,12 @@ TEST(CXXApi_LightApi, save_and_load_model) {
// CXXAPi // CXXAPi
{ {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kX86), PRECISION(kFloat)}, Place{TARGET(kX86), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, // Both works on X86 and ARM Place{TARGET(kARM), PRECISION(kFloat)}, // Both works on X86 and ARM
}); });
// On ARM devices, the preferred X86 target not works, but it can still // On ARM devices, the preferred X86 target not works, but it can still
// select ARM kernels. // select ARM kernels.
cxx_api.Build(FLAGS_model_dir, cxx_api.Build(FLAGS_model_dir, "", "", valid_places);
"",
"",
Place{TARGET(kX86), PRECISION(kFloat)},
valid_places);
auto* x = cxx_api.GetInput(0); auto* x = cxx_api.GetInput(0);
SetConstInput(x); SetConstInput(x);
......
...@@ -47,9 +47,7 @@ void OutputOptModel(const std::string& load_model_dir, ...@@ -47,9 +47,7 @@ void OutputOptModel(const std::string& load_model_dir,
Place{TARGET(kARM), PRECISION(kInt8)}, Place{TARGET(kARM), PRECISION(kInt8)},
Place{TARGET(kX86), PRECISION(kFloat)}, Place{TARGET(kX86), PRECISION(kFloat)},
Place{TARGET(kOpenCL), PRECISION(kFloat)}, Place{TARGET(kOpenCL), PRECISION(kFloat)},
Place{TARGET(kHost), PRECISION(kFloat)},
}); });
config.set_preferred_place(Place{TARGET(kARM), PRECISION(kFloat)});
auto predictor = lite_api::CreatePaddlePredictor(config); auto predictor = lite_api::CreatePaddlePredictor(config);
int ret = system( int ret = system(
......
...@@ -110,14 +110,12 @@ void Predictor::Build(const lite_api::CxxConfig &config, ...@@ -110,14 +110,12 @@ void Predictor::Build(const lite_api::CxxConfig &config,
const std::string &model_path = config.model_dir(); const std::string &model_path = config.model_dir();
const std::string &model_file = config.model_file(); const std::string &model_file = config.model_file();
const std::string &param_file = config.param_file(); const std::string &param_file = config.param_file();
const Place prefer_place = config.preferred_place();
const bool model_from_memory = config.model_from_memory(); const bool model_from_memory = config.model_from_memory();
LOG(INFO) << "load from memory " << model_from_memory; LOG(INFO) << "load from memory " << model_from_memory;
Build(model_path, Build(model_path,
model_file, model_file,
param_file, param_file,
prefer_place,
valid_places, valid_places,
passes, passes,
model_type, model_type,
...@@ -126,7 +124,6 @@ void Predictor::Build(const lite_api::CxxConfig &config, ...@@ -126,7 +124,6 @@ void Predictor::Build(const lite_api::CxxConfig &config,
void Predictor::Build(const std::string &model_path, void Predictor::Build(const std::string &model_path,
const std::string &model_file, const std::string &model_file,
const std::string &param_file, const std::string &param_file,
const Place &prefer_place,
const std::vector<Place> &valid_places, const std::vector<Place> &valid_places,
const std::vector<std::string> &passes, const std::vector<std::string> &passes,
lite_api::LiteModelType model_type, lite_api::LiteModelType model_type,
...@@ -153,21 +150,24 @@ void Predictor::Build(const std::string &model_path, ...@@ -153,21 +150,24 @@ void Predictor::Build(const std::string &model_path,
default: default:
LOG(FATAL) << "Unknown model type"; LOG(FATAL) << "Unknown model type";
} }
Build(program_desc_, prefer_place, valid_places, passes); Build(program_desc_, valid_places, passes);
} }
void Predictor::Build(const cpp::ProgramDesc &desc, void Predictor::Build(const cpp::ProgramDesc &desc,
const Place &prefer_place,
const std::vector<Place> &valid_places, const std::vector<Place> &valid_places,
const std::vector<std::string> &passes) { const std::vector<std::string> &passes) {
program_desc_ = desc; program_desc_ = desc;
Program program(desc, scope_, valid_places); std::vector<Place> inner_places = valid_places;
optimizer_.KernelPickPreferPlace(prefer_place); inner_places.emplace_back(TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny));
inner_places.emplace_back(
TARGET(kHost), PRECISION(kFloat), DATALAYOUT(kNCHW));
Program program(desc, scope_, inner_places);
/// The first place in valid_places is
core::KernelPickFactor factor; core::KernelPickFactor factor;
factor.ConsiderTarget(); factor.ConsiderTarget();
factor.ConsiderPrecision(); factor.ConsiderPrecision();
factor.ConsiderDataLayout(); factor.ConsiderDataLayout();
optimizer_.Run(std::move(program), valid_places, factor, passes); optimizer_.Run(std::move(program), inner_places, factor, passes);
exec_scope_ = optimizer_.exec_scope(); exec_scope_ = optimizer_.exec_scope();
} }
......
...@@ -50,14 +50,12 @@ class LITE_API Predictor { ...@@ -50,14 +50,12 @@ class LITE_API Predictor {
const std::string& model_path, const std::string& model_path,
const std::string& model_file_path, const std::string& model_file_path,
const std::string& param_file_path, const std::string& param_file_path,
const Place& prefer_place,
const std::vector<Place>& valid_places, const std::vector<Place>& valid_places,
const std::vector<std::string>& passes = {}, const std::vector<std::string>& passes = {},
lite_api::LiteModelType model_type = lite_api::LiteModelType::kProtobuf, lite_api::LiteModelType model_type = lite_api::LiteModelType::kProtobuf,
bool memory_from_memory = false); bool memory_from_memory = false);
void Build(const cpp::ProgramDesc& desc, void Build(const cpp::ProgramDesc& desc,
const Place& prefer_place,
const std::vector<Place>& valid_places, const std::vector<Place>& valid_places,
const std::vector<std::string>& passes = {}); const std::vector<std::string>& passes = {});
...@@ -132,10 +130,8 @@ class LITE_API Predictor { ...@@ -132,10 +130,8 @@ class LITE_API Predictor {
class LITE_API CXXTrainer { class LITE_API CXXTrainer {
public: public:
CXXTrainer(const std::shared_ptr<lite::Scope>& root_scope, CXXTrainer(const std::shared_ptr<lite::Scope>& root_scope,
const Place& preferred_place,
const std::vector<Place>& valid_places) const std::vector<Place>& valid_places)
: scope_(root_scope), : scope_(root_scope),
preferred_place_(preferred_place),
valid_places_(valid_places), valid_places_(valid_places),
main_program_executor_(Predictor(scope_)) {} main_program_executor_(Predictor(scope_)) {}
...@@ -144,7 +140,7 @@ class LITE_API CXXTrainer { ...@@ -144,7 +140,7 @@ class LITE_API CXXTrainer {
// NOTE Just support to execute the 0-th block currently. // NOTE Just support to execute the 0-th block currently.
Predictor& BuildMainProgramExecutor(const framework::proto::ProgramDesc& desc, Predictor& BuildMainProgramExecutor(const framework::proto::ProgramDesc& desc,
int block_id = 0) { int block_id = 0) {
main_program_executor_.Build(desc, preferred_place_, valid_places_); main_program_executor_.Build(desc, valid_places_);
return main_program_executor_; return main_program_executor_;
} }
...@@ -162,14 +158,12 @@ class LITE_API CXXTrainer { ...@@ -162,14 +158,12 @@ class LITE_API CXXTrainer {
void RunStartupProgram(const framework::proto::ProgramDesc& desc, void RunStartupProgram(const framework::proto::ProgramDesc& desc,
int block_id = 0) { int block_id = 0) {
Predictor exe(scope_); Predictor exe(scope_);
exe.Build(desc, preferred_place_, valid_places_); exe.Build(desc, valid_places_);
exe.Run(); exe.Run();
} }
private: private:
std::shared_ptr<lite::Scope> scope_; std::shared_ptr<lite::Scope> scope_;
Place preferred_place_;
std::vector<Place> valid_places_; std::vector<Place> valid_places_;
// The training program. // The training program.
......
...@@ -35,13 +35,11 @@ void Run(const char* model_dir, int repeat) { ...@@ -35,13 +35,11 @@ void Run(const char* model_dir, int repeat) {
#endif #endif
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kInt8)}, Place{TARGET(kARM), PRECISION(kInt8)},
Place{TARGET(kARM), PRECISION(kFloat)},
}); });
predictor.Build( predictor.Build(model_dir, "", "", valid_places);
model_dir, "", "", Place{TARGET(kARM), PRECISION(kInt8)}, valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
......
...@@ -62,7 +62,6 @@ void CxxPaddleApiImpl::Init(const lite_api::CxxConfig &config) { ...@@ -62,7 +62,6 @@ void CxxPaddleApiImpl::Init(const lite_api::CxxConfig &config) {
Env<TARGET(kCUDA)>::Init(); Env<TARGET(kCUDA)>::Init();
#endif #endif
auto places = config.valid_places(); auto places = config.valid_places();
places.emplace_back(TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny));
raw_predictor_.Build(config, places); raw_predictor_.Build(config, places);
raw_predictor_.PrepareFeedFetch(); raw_predictor_.PrepareFeedFetch();
} }
......
...@@ -43,13 +43,8 @@ TEST(CXXApi, test) { ...@@ -43,13 +43,8 @@ TEST(CXXApi, test) {
TEST(CXXApi, save_model) { TEST(CXXApi, save_model) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kX86), PRECISION(kFloat)}});
Place{TARGET(kX86), PRECISION(kFloat)}}); predictor.Build(FLAGS_model_dir, "", "", valid_places);
predictor.Build(FLAGS_model_dir,
"",
"",
Place{TARGET(kCUDA), PRECISION(kFloat)},
valid_places);
LOG(INFO) << "Save optimized model to " << FLAGS_optimized_model; LOG(INFO) << "Save optimized model to " << FLAGS_optimized_model;
predictor.SaveModel(FLAGS_optimized_model, predictor.SaveModel(FLAGS_optimized_model,
...@@ -59,11 +54,11 @@ TEST(CXXApi, save_model) { ...@@ -59,11 +54,11 @@ TEST(CXXApi, save_model) {
} }
/*TEST(CXXTrainer, train) { /*TEST(CXXTrainer, train) {
Place prefer_place({TARGET(kHost), PRECISION(kFloat), DATALAYOUT(kNCHW)}); Place place({TARGET(kHost), PRECISION(kFloat), DATALAYOUT(kNCHW)});
std::vector<Place> valid_places({prefer_place}); std::vector<Place> valid_places({place});
auto scope = std::make_shared<lite::Scope>(); auto scope = std::make_shared<lite::Scope>();
CXXTrainer trainer(scope, prefer_place, valid_places); CXXTrainer trainer(scope, valid_places);
std::string main_program_pb, startup_program_pb; std::string main_program_pb, startup_program_pb;
ReadBinaryFile(FLAGS_main_program_path, &main_program_pb); ReadBinaryFile(FLAGS_main_program_path, &main_program_pb);
...@@ -94,13 +89,8 @@ TEST(CXXApi, save_model) { ...@@ -94,13 +89,8 @@ TEST(CXXApi, save_model) {
#ifdef LITE_WITH_ARM #ifdef LITE_WITH_ARM
TEST(CXXApi, save_model) { TEST(CXXApi, save_model) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kARM), PRECISION(kFloat)}});
Place{TARGET(kARM), PRECISION(kFloat)}}); predictor.Build(FLAGS_model_dir, "", "", valid_places);
predictor.Build(FLAGS_model_dir,
"",
"",
Place{TARGET(kARM), PRECISION(kFloat)},
valid_places);
LOG(INFO) << "Save optimized model to " << FLAGS_optimized_model; LOG(INFO) << "Save optimized model to " << FLAGS_optimized_model;
predictor.SaveModel(FLAGS_optimized_model); predictor.SaveModel(FLAGS_optimized_model);
...@@ -110,12 +100,10 @@ TEST(CXXApi, save_model) { ...@@ -110,12 +100,10 @@ TEST(CXXApi, save_model) {
TEST(CXXApi, load_model_naive) { TEST(CXXApi, load_model_naive) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kARM), PRECISION(kFloat)}});
Place{TARGET(kARM), PRECISION(kFloat)}});
predictor.Build(FLAGS_optimized_model + ".naive", predictor.Build(FLAGS_optimized_model + ".naive",
"", "",
"", "",
Place{TARGET(kARM), PRECISION(kFloat)},
valid_places, valid_places,
{}, {},
lite_api::LiteModelType::kNaiveBuffer); lite_api::LiteModelType::kNaiveBuffer);
......
...@@ -34,7 +34,6 @@ void OutputOptModel(const std::string& load_model_dir, ...@@ -34,7 +34,6 @@ void OutputOptModel(const std::string& load_model_dir,
const std::string& save_optimized_model_dir) { const std::string& save_optimized_model_dir) {
lite_api::CxxConfig config; lite_api::CxxConfig config;
config.set_model_dir(load_model_dir); config.set_model_dir(load_model_dir);
config.set_preferred_place(Place{TARGET(kX86), PRECISION(kFloat)});
config.set_valid_places({ config.set_valid_places({
Place{TARGET(kX86), PRECISION(kFloat)}, Place{TARGET(kX86), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
......
...@@ -25,13 +25,12 @@ ...@@ -25,13 +25,12 @@
namespace paddle { namespace paddle {
namespace lite { namespace lite {
void TestModel(const std::vector<Place> &valid_places, void TestModel(const std::vector<Place> &valid_places) {
const Place &preferred_place) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); predictor.Build(FLAGS_model_dir, "", "", valid_places);
auto *input_tensor = predictor.GetInput(0); auto *input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
...@@ -80,22 +79,20 @@ void TestModel(const std::vector<Place> &valid_places, ...@@ -80,22 +79,20 @@ void TestModel(const std::vector<Place> &valid_places,
TEST(EfficientNetB0, test_arm) { TEST(EfficientNetB0, test_arm) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
// Place{TARGET(kOpenCL), PRECISION(kFloat)}, // Place{TARGET(kOpenCL), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kARM), PRECISION(kFloat)})); TestModel(valid_places);
} }
TEST(EfficientNetB0, test_opencl) { TEST(EfficientNetB0, test_opencl) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kOpenCL), PRECISION(kFloat)}, Place{TARGET(kOpenCL), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kOpenCL), PRECISION(kFloat)})); TestModel(valid_places);
} }
} // namespace lite } // namespace lite
......
...@@ -30,14 +30,9 @@ TEST(InceptionV4, test) { ...@@ -30,14 +30,9 @@ TEST(InceptionV4, test) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kARM), PRECISION(kFloat)}});
Place{TARGET(kARM), PRECISION(kFloat)}});
predictor.Build(FLAGS_model_dir, predictor.Build(FLAGS_model_dir, "", "", valid_places);
"",
"",
Place{TARGET(kARM), PRECISION(kFloat)},
valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
......
...@@ -24,24 +24,16 @@ namespace lite { ...@@ -24,24 +24,16 @@ namespace lite {
const lite::Tensor* RunHvyModel() { const lite::Tensor* RunHvyModel() {
lite::Predictor predictor; lite::Predictor predictor;
#ifndef LITE_WITH_CUDA #ifndef LITE_WITH_CUDA
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kX86), PRECISION(kFloat)}});
Place{TARGET(kX86), PRECISION(kFloat)}});
#else #else
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat), DATALAYOUT(kNCHW)},
Place{TARGET(kCUDA), PRECISION(kFloat), DATALAYOUT(kNCHW)}, Place{TARGET(kCUDA), PRECISION(kFloat), DATALAYOUT(kNCHW)},
Place{TARGET(kCUDA), PRECISION(kAny), DATALAYOUT(kNCHW)}, Place{TARGET(kCUDA), PRECISION(kAny), DATALAYOUT(kNCHW)},
Place{TARGET(kHost), PRECISION(kAny), DATALAYOUT(kNCHW)},
Place{TARGET(kCUDA), PRECISION(kAny), DATALAYOUT(kAny)}, Place{TARGET(kCUDA), PRECISION(kAny), DATALAYOUT(kAny)},
Place{TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny)},
}); });
#endif #endif
predictor.Build(FLAGS_model_dir, predictor.Build(FLAGS_model_dir, "", "", valid_places);
"",
"",
Place{TARGET(kX86), PRECISION(kFloat)}, // origin cuda
valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({100, 100}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({100, 100})));
......
...@@ -25,13 +25,12 @@ ...@@ -25,13 +25,12 @@
namespace paddle { namespace paddle {
namespace lite { namespace lite {
void TestModel(const std::vector<Place>& valid_places, void TestModel(const std::vector<Place>& valid_places) {
const Place& preferred_place) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); predictor.Build(FLAGS_model_dir, "", "", valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
...@@ -93,12 +92,11 @@ void TestModel(const std::vector<Place>& valid_places, ...@@ -93,12 +92,11 @@ void TestModel(const std::vector<Place>& valid_places,
TEST(MobileNetV1, test_arm) { TEST(MobileNetV1, test_arm) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kInt8)}, Place{TARGET(kARM), PRECISION(kInt8)},
Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kARM), PRECISION(kInt8)})); TestModel(valid_places);
} }
} // namespace lite } // namespace lite
......
...@@ -26,13 +26,12 @@ namespace paddle { ...@@ -26,13 +26,12 @@ namespace paddle {
namespace lite { namespace lite {
#ifdef LITE_WITH_ARM #ifdef LITE_WITH_ARM
void TestModel(const std::vector<Place>& valid_places, void TestModel(const std::vector<Place>& valid_places) {
const Place& preferred_place) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); predictor.Build(FLAGS_model_dir, "", "", valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 300, 300}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 300, 300})));
...@@ -99,7 +98,6 @@ void TestModel(const std::vector<Place>& valid_places, ...@@ -99,7 +98,6 @@ void TestModel(const std::vector<Place>& valid_places,
TEST(MobileNetV1_SSD, test_arm) { TEST(MobileNetV1_SSD, test_arm) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
}); });
......
...@@ -28,14 +28,13 @@ namespace paddle { ...@@ -28,14 +28,13 @@ namespace paddle {
namespace lite { namespace lite {
void TestModel(const std::vector<Place>& valid_places, void TestModel(const std::vector<Place>& valid_places,
const Place& preferred_place,
const std::string& model_dir = FLAGS_model_dir, const std::string& model_dir = FLAGS_model_dir,
bool save_model = false) { bool save_model = false) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
predictor.Build(model_dir, "", "", preferred_place, valid_places); predictor.Build(model_dir, "", "", valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
...@@ -103,41 +102,32 @@ void TestModel(const std::vector<Place>& valid_places, ...@@ -103,41 +102,32 @@ void TestModel(const std::vector<Place>& valid_places,
#ifdef LITE_WITH_NPU #ifdef LITE_WITH_NPU
TEST(MobileNetV1, test_npu) { TEST(MobileNetV1, test_npu) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kNPU), PRECISION(kFloat)}, Place{TARGET(kNPU), PRECISION(kFloat)},
}); });
TestModel(valid_places, TestModel(valid_places, FLAGS_model_dir, true /* save_model*/);
Place({TARGET(kARM), PRECISION(kFloat)}),
FLAGS_model_dir,
true /* save_model*/);
TestModel(valid_places, TestModel(valid_places, FLAGS_optimized_model, false /* save model */);
Place({TARGET(kARM), PRECISION(kFloat)}),
FLAGS_optimized_model,
false /* save model */);
} }
#endif // LITE_WITH_NPU #endif // LITE_WITH_NPU
TEST(MobileNetV1, test_arm) { TEST(MobileNetV1, test_arm) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kARM), PRECISION(kFloat)})); TestModel(valid_places);
} }
#ifdef LITE_WITH_OPENCL #ifdef LITE_WITH_OPENCL
TEST(MobileNetV1, test_opencl) { TEST(MobileNetV1, test_opencl) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kOpenCL), PRECISION(kFloat)}, Place{TARGET(kOpenCL), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kOpenCL), PRECISION(kFloat)})); TestModel(valid_places);
} }
#endif // LITE_WITH_OPENCL #endif // LITE_WITH_OPENCL
......
...@@ -26,13 +26,12 @@ namespace paddle { ...@@ -26,13 +26,12 @@ namespace paddle {
namespace lite { namespace lite {
#ifdef LITE_WITH_ARM #ifdef LITE_WITH_ARM
void TestModel(const std::vector<Place>& valid_places, void TestModel(const std::vector<Place>& valid_places) {
const Place& preferred_place) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); predictor.Build(FLAGS_model_dir, "", "", valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 608, 608}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 608, 608})));
...@@ -106,11 +105,10 @@ void TestModel(const std::vector<Place>& valid_places, ...@@ -106,11 +105,10 @@ void TestModel(const std::vector<Place>& valid_places,
TEST(MobileNetV1_YoloV3, test_arm) { TEST(MobileNetV1_YoloV3, test_arm) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kARM), PRECISION(kFloat)})); TestModel(valid_places);
} }
#endif // LITE_WITH_ARM #endif // LITE_WITH_ARM
......
...@@ -29,14 +29,13 @@ namespace lite { ...@@ -29,14 +29,13 @@ namespace lite {
#ifdef LITE_WITH_ARM #ifdef LITE_WITH_ARM
void TestModel(const std::vector<Place>& valid_places, void TestModel(const std::vector<Place>& valid_places,
const Place& preferred_place,
const std::string& model_dir = FLAGS_model_dir, const std::string& model_dir = FLAGS_model_dir,
bool save_model = false) { bool save_model = false) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_NO_BIND, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
predictor.Build(model_dir, "", "", preferred_place, valid_places); predictor.Build(model_dir, "", "", valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
...@@ -103,41 +102,32 @@ void TestModel(const std::vector<Place>& valid_places, ...@@ -103,41 +102,32 @@ void TestModel(const std::vector<Place>& valid_places,
#ifdef LITE_WITH_NPU #ifdef LITE_WITH_NPU
TEST(MobileNetV2, test_npu) { TEST(MobileNetV2, test_npu) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kNPU), PRECISION(kFloat)}, Place{TARGET(kNPU), PRECISION(kFloat)},
}); });
TestModel(valid_places, TestModel(valid_places, FLAGS_model_dir, true /* save_model*/);
Place({TARGET(kARM), PRECISION(kFloat)}),
FLAGS_model_dir,
true /* save_model*/);
TestModel(valid_places, TestModel(valid_places, FLAGS_optimized_model, false /* save model */);
Place({TARGET(kARM), PRECISION(kFloat)}),
FLAGS_optimized_model,
false /* save model */);
} }
#endif // LITE_WITH_NPU #endif // LITE_WITH_NPU
TEST(MobileNetV2, test_arm) { TEST(MobileNetV2, test_arm) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kARM), PRECISION(kFloat)})); TestModel(valid_places);
} }
#ifdef LITE_WITH_OPENCL #ifdef LITE_WITH_OPENCL
TEST(MobileNetV2, test_opencl) { TEST(MobileNetV2, test_opencl) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kOpenCL), PRECISION(kFloat)}, Place{TARGET(kOpenCL), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kOpenCL), PRECISION(kFloat)})); TestModel(valid_places);
} }
#endif // LITE_WITH_OPENCL #endif // LITE_WITH_OPENCL
......
...@@ -82,7 +82,6 @@ void Main() { ...@@ -82,7 +82,6 @@ void Main() {
target_repr.c_str()); target_repr.c_str());
} }
} }
valid_places.emplace_back(TARGET(kHost));
CHECK(!valid_places.empty()) CHECK(!valid_places.empty())
<< "At least one target should be set, should set the " << "At least one target should be set, should set the "
...@@ -90,8 +89,8 @@ void Main() { ...@@ -90,8 +89,8 @@ void Main() {
if (FLAGS_prefer_int8_kernel) { if (FLAGS_prefer_int8_kernel) {
LOG(WARNING) << "Int8 mode is only support by ARM target"; LOG(WARNING) << "Int8 mode is only support by ARM target";
valid_places.push_back(Place{TARGET(kARM), PRECISION(kInt8)}); valid_places.insert(valid_places.begin(),
config.set_preferred_place(Place{TARGET(kARM), PRECISION(kInt8)}); Place{TARGET(kARM), PRECISION(kInt8)});
} }
config.set_valid_places(valid_places); config.set_valid_places(valid_places);
......
...@@ -30,16 +30,14 @@ TEST(model, test) { ...@@ -30,16 +30,14 @@ TEST(model, test) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kInt8)}}); Place{TARGET(kARM), PRECISION(kInt8)}});
auto precision = PRECISION(kFloat); auto precision = PRECISION(kFloat);
if (FLAGS_int8) { if (FLAGS_int8) {
precision = PRECISION(kInt8); precision = PRECISION(kInt8);
} }
predictor.Build( predictor.Build(FLAGS_model_dir, "", "", valid_places);
FLAGS_model_dir, "", "", Place{TARGET(kARM), precision}, valid_places);
int im_width = FLAGS_im_width; int im_width = FLAGS_im_width;
int im_height = FLAGS_im_height; int im_height = FLAGS_im_height;
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
......
...@@ -36,11 +36,9 @@ void OutputOptModel(const std::string& load_model_dir, ...@@ -36,11 +36,9 @@ void OutputOptModel(const std::string& load_model_dir,
const std::vector<std::vector<int64_t>>& input_shapes) { const std::vector<std::vector<int64_t>>& input_shapes) {
lite_api::CxxConfig config; lite_api::CxxConfig config;
config.set_model_dir(load_model_dir); config.set_model_dir(load_model_dir);
config.set_preferred_place(Place{TARGET(kX86), PRECISION(kFloat)});
config.set_valid_places({ config.set_valid_places({
Place{TARGET(kX86), PRECISION(kFloat)}, Place{TARGET(kX86), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kHost), PRECISION(kFloat)},
}); });
auto predictor = lite_api::CreatePaddlePredictor(config); auto predictor = lite_api::CreatePaddlePredictor(config);
......
...@@ -25,14 +25,12 @@ ...@@ -25,14 +25,12 @@
namespace paddle { namespace paddle {
namespace lite { namespace lite {
void TestModel(const std::vector<Place>& valid_places, void TestModel(const std::vector<Place>& valid_places, bool use_npu = false) {
const Place& preferred_place,
bool use_npu = false) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); predictor.Build(FLAGS_model_dir, "", "", valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 1, 48, 512}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 1, 48, 512})));
...@@ -104,11 +102,10 @@ void TestModel(const std::vector<Place>& valid_places, ...@@ -104,11 +102,10 @@ void TestModel(const std::vector<Place>& valid_places,
TEST(OcrAttention, test_arm) { TEST(OcrAttention, test_arm) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kARM), PRECISION(kFloat)})); TestModel(valid_places);
} }
} // namespace lite } // namespace lite
......
...@@ -116,14 +116,12 @@ class LITE_API ConfigBase { ...@@ -116,14 +116,12 @@ class LITE_API ConfigBase {
/// CxxConfig is the config for the Full feature predictor. /// CxxConfig is the config for the Full feature predictor.
class LITE_API CxxConfig : public ConfigBase { class LITE_API CxxConfig : public ConfigBase {
Place preferred_place_;
std::vector<Place> valid_places_; std::vector<Place> valid_places_;
std::string model_file_; std::string model_file_;
std::string param_file_; std::string param_file_;
bool model_from_memory_{false}; bool model_from_memory_{false};
public: public:
void set_preferred_place(const Place& x) { preferred_place_ = x; }
void set_valid_places(const std::vector<Place>& x) { valid_places_ = x; } void set_valid_places(const std::vector<Place>& x) { valid_places_ = x; }
void set_model_file(const std::string& path) { model_file_ = path; } void set_model_file(const std::string& path) { model_file_ = path; }
void set_param_file(const std::string& path) { param_file_ = path; } void set_param_file(const std::string& path) { param_file_ = path; }
...@@ -136,7 +134,6 @@ class LITE_API CxxConfig : public ConfigBase { ...@@ -136,7 +134,6 @@ class LITE_API CxxConfig : public ConfigBase {
model_from_memory_ = true; model_from_memory_ = true;
} }
const Place& preferred_place() const { return preferred_place_; }
const std::vector<Place>& valid_places() const { return valid_places_; } const std::vector<Place>& valid_places() const { return valid_places_; }
std::string model_file() const { return model_file_; } std::string model_file() const { return model_file_; }
std::string param_file() const { return param_file_; } std::string param_file() const { return param_file_; }
......
...@@ -28,7 +28,6 @@ namespace lite_api { ...@@ -28,7 +28,6 @@ namespace lite_api {
TEST(CxxApi, run) { TEST(CxxApi, run) {
lite_api::CxxConfig config; lite_api::CxxConfig config;
config.set_model_dir(FLAGS_model_dir); config.set_model_dir(FLAGS_model_dir);
config.set_preferred_place(Place{TARGET(kX86), PRECISION(kFloat)});
config.set_valid_places({ config.set_valid_places({
Place{TARGET(kX86), PRECISION(kFloat)}, Place{TARGET(kX86), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
......
...@@ -28,14 +28,9 @@ namespace lite { ...@@ -28,14 +28,9 @@ namespace lite {
#ifdef LITE_WITH_ARM #ifdef LITE_WITH_ARM
TEST(ResNet18, test) { TEST(ResNet18, test) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kARM), PRECISION(kFloat)}});
Place{TARGET(kARM), PRECISION(kFloat)}});
predictor.Build(FLAGS_model_dir, predictor.Build(FLAGS_model_dir, "", "", valid_places);
"",
"",
Place{TARGET(kARM), PRECISION(kFloat)},
valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
......
...@@ -26,13 +26,12 @@ namespace paddle { ...@@ -26,13 +26,12 @@ namespace paddle {
namespace lite { namespace lite {
#ifdef LITE_WITH_ARM #ifdef LITE_WITH_ARM
void TestModel(const std::vector<Place>& valid_places, void TestModel(const std::vector<Place>& valid_places) {
const Place& preferred_place) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); predictor.Build(FLAGS_model_dir, "", "", valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
...@@ -82,22 +81,20 @@ void TestModel(const std::vector<Place>& valid_places, ...@@ -82,22 +81,20 @@ void TestModel(const std::vector<Place>& valid_places,
TEST(ResNet50, test_arm) { TEST(ResNet50, test_arm) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kARM), PRECISION(kFloat)})); TestModel(valid_places);
} }
#ifdef LITE_WITH_OPENCL #ifdef LITE_WITH_OPENCL
TEST(ResNet50, test_opencl) { TEST(ResNet50, test_opencl) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
Place{TARGET(kOpenCL), PRECISION(kFloat)}, Place{TARGET(kOpenCL), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kOpenCL), PRECISION(kFloat)})); TestModel(valid_places);
} }
#endif // LITE_WITH_OPENCL #endif // LITE_WITH_OPENCL
......
...@@ -29,8 +29,7 @@ namespace lite { ...@@ -29,8 +29,7 @@ namespace lite {
TEST(ResNet50, test) { TEST(ResNet50, test) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places( std::vector<Place> valid_places(
{Place{TARGET(kFPGA), PRECISION(kFP16), DATALAYOUT(kNHWC)}, {Place{TARGET(kFPGA), PRECISION(kFP16), DATALAYOUT(kNHWC)}});
Place{TARGET(kHost), PRECISION(kFloat), DATALAYOUT(kNHWC)}});
predictor.Build(FLAGS_model_dir, predictor.Build(FLAGS_model_dir,
"", "",
......
...@@ -25,13 +25,12 @@ ...@@ -25,13 +25,12 @@
namespace paddle { namespace paddle {
namespace lite { namespace lite {
void TestModel(const std::vector<Place>& valid_places, void TestModel(const std::vector<Place>& valid_places) {
const Place& preferred_place) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
predictor.Build(FLAGS_model_dir, "", "", preferred_place, valid_places); predictor.Build(FLAGS_model_dir, "", "", valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim((std::vector<DDim::value_type>({1, 3, 224, 224})))); input_tensor->Resize(DDim((std::vector<DDim::value_type>({1, 3, 224, 224}))));
...@@ -80,12 +79,11 @@ void TestModel(const std::vector<Place>& valid_places, ...@@ -80,12 +79,11 @@ void TestModel(const std::vector<Place>& valid_places,
TEST(ShuffleNetV2, test_arm) { TEST(ShuffleNetV2, test_arm) {
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
// Place{TARGET(kOpenCL), PRECISION(kFloat)}, // Place{TARGET(kOpenCL), PRECISION(kFloat)},
}); });
TestModel(valid_places, Place({TARGET(kARM), PRECISION(kFloat)})); TestModel(valid_places);
} }
} // namespace lite } // namespace lite
......
...@@ -45,13 +45,11 @@ namespace lite { ...@@ -45,13 +45,11 @@ namespace lite {
#ifdef LITE_WITH_X86 #ifdef LITE_WITH_X86
TEST(CXXApi, test_lite_googlenet) { TEST(CXXApi, test_lite_googlenet) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kX86), PRECISION(kFloat)}});
Place{TARGET(kX86), PRECISION(kFloat)}});
// LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<<FLAGS_test_lite_googlenet_dir; // LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<<FLAGS_test_lite_googlenet_dir;
std::string model_dir = FLAGS_model_dir; std::string model_dir = FLAGS_model_dir;
predictor.Build( predictor.Build(model_dir, "", "", valid_places);
model_dir, "", "", Place{TARGET(kX86), PRECISION(kFloat)}, valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
......
...@@ -43,8 +43,7 @@ namespace lite { ...@@ -43,8 +43,7 @@ namespace lite {
TEST(InceptionV4, test_inceptionv4_lite_x86) { TEST(InceptionV4, test_inceptionv4_lite_x86) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kX86), PRECISION(kFloat)}});
Place{TARGET(kX86), PRECISION(kFloat)}});
// LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<<FLAGS_test_lite_googlenet_dir; // LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<<FLAGS_test_lite_googlenet_dir;
std::string model_dir = FLAGS_model_dir; std::string model_dir = FLAGS_model_dir;
...@@ -55,12 +54,7 @@ TEST(InceptionV4, test_inceptionv4_lite_x86) { ...@@ -55,12 +54,7 @@ TEST(InceptionV4, test_inceptionv4_lite_x86) {
"io_copy_kernel_pick_pass", "io_copy_kernel_pick_pass",
"variable_place_inference_pass", "variable_place_inference_pass",
"runtime_context_assign_pass"}); "runtime_context_assign_pass"});
predictor.Build(model_dir, predictor.Build(model_dir, "", "", valid_places, passes);
"",
"",
Place{TARGET(kX86), PRECISION(kFloat)},
valid_places,
passes);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
......
...@@ -43,8 +43,7 @@ namespace lite { ...@@ -43,8 +43,7 @@ namespace lite {
TEST(Mobilenet_v1, test_mobilenetv1_lite_x86) { TEST(Mobilenet_v1, test_mobilenetv1_lite_x86) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kX86), PRECISION(kFloat)}});
Place{TARGET(kX86), PRECISION(kFloat)}});
std::string model_dir = FLAGS_model_dir; std::string model_dir = FLAGS_model_dir;
std::vector<std::string> passes({"static_kernel_pick_pass", std::vector<std::string> passes({"static_kernel_pick_pass",
...@@ -54,12 +53,7 @@ TEST(Mobilenet_v1, test_mobilenetv1_lite_x86) { ...@@ -54,12 +53,7 @@ TEST(Mobilenet_v1, test_mobilenetv1_lite_x86) {
"io_copy_kernel_pick_pass", "io_copy_kernel_pick_pass",
"variable_place_inference_pass", "variable_place_inference_pass",
"runtime_context_assign_pass"}); "runtime_context_assign_pass"});
predictor.Build(model_dir, predictor.Build(model_dir, "", "", valid_places, passes);
"",
"",
Place{TARGET(kX86), PRECISION(kFloat)},
valid_places,
passes);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
auto* data = input_tensor->mutable_data<float>(); auto* data = input_tensor->mutable_data<float>();
......
...@@ -44,8 +44,8 @@ namespace lite { ...@@ -44,8 +44,8 @@ namespace lite {
TEST(Mobilenet_v2, test_mobilenetv2_lite_x86) { TEST(Mobilenet_v2, test_mobilenetv2_lite_x86) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kX86), PRECISION(kFloat)},
Place{TARGET(kX86), PRECISION(kFloat)}}); Place{TARGET(kHost), PRECISION(kFloat)}});
// LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<<FLAGS_test_lite_googlenet_dir; // LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<<FLAGS_test_lite_googlenet_dir;
std::string model_dir = FLAGS_model_dir; std::string model_dir = FLAGS_model_dir;
...@@ -56,12 +56,7 @@ TEST(Mobilenet_v2, test_mobilenetv2_lite_x86) { ...@@ -56,12 +56,7 @@ TEST(Mobilenet_v2, test_mobilenetv2_lite_x86) {
"io_copy_kernel_pick_pass", "io_copy_kernel_pick_pass",
"variable_place_inference_pass", "variable_place_inference_pass",
"runtime_context_assign_pass"}); "runtime_context_assign_pass"});
predictor.Build(model_dir, predictor.Build(model_dir, "", "", valid_places, passes);
"",
"",
Place{TARGET(kX86), PRECISION(kFloat)},
valid_places,
passes);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 224, 224})));
......
...@@ -30,14 +30,9 @@ TEST(unet, test) { ...@@ -30,14 +30,9 @@ TEST(unet, test) {
DeviceInfo::Init(); DeviceInfo::Init();
DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads); DeviceInfo::Global().SetRunMode(lite_api::LITE_POWER_HIGH, FLAGS_threads);
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kARM), PRECISION(kFloat)}});
Place{TARGET(kARM), PRECISION(kFloat)}});
predictor.Build(FLAGS_model_dir, predictor.Build(FLAGS_model_dir, "", "", valid_places);
"",
"",
Place{TARGET(kARM), PRECISION(kFloat)},
valid_places);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 512, 512}))); input_tensor->Resize(DDim(std::vector<DDim::value_type>({1, 3, 512, 512})));
......
...@@ -30,16 +30,12 @@ namespace mir { ...@@ -30,16 +30,12 @@ namespace mir {
TEST(fc_fuse_pass, fuse_test) { TEST(fc_fuse_pass, fuse_test) {
lite::Predictor predictor; lite::Predictor predictor;
#ifndef LITE_WITH_CUDA #ifndef LITE_WITH_CUDA
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kX86), PRECISION(kFloat)}});
Place{TARGET(kX86), PRECISION(kFloat)}});
#else #else
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat), DATALAYOUT(kNCHW)},
Place{TARGET(kCUDA), PRECISION(kFloat), DATALAYOUT(kNCHW)}, Place{TARGET(kCUDA), PRECISION(kFloat), DATALAYOUT(kNCHW)},
Place{TARGET(kCUDA), PRECISION(kAny), DATALAYOUT(kNCHW)}, Place{TARGET(kCUDA), PRECISION(kAny), DATALAYOUT(kNCHW)},
Place{TARGET(kHost), PRECISION(kAny), DATALAYOUT(kNCHW)},
Place{TARGET(kCUDA), PRECISION(kAny), DATALAYOUT(kAny)}, Place{TARGET(kCUDA), PRECISION(kAny), DATALAYOUT(kAny)},
Place{TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny)},
}); });
#endif #endif
...@@ -72,8 +68,7 @@ TEST(fc_fuse_pass, fuse_test) { ...@@ -72,8 +68,7 @@ TEST(fc_fuse_pass, fuse_test) {
#ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK #ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK
TEST(fc_fuse_pass, save_model_test) { TEST(fc_fuse_pass, save_model_test) {
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, std::vector<Place> valid_places({Place{TARGET(kX86), PRECISION(kFloat)}});
Place{TARGET(kX86), PRECISION(kFloat)}});
predictor.Build(FLAGS_model_dir, predictor.Build(FLAGS_model_dir,
"", "",
"", "",
......
...@@ -24,8 +24,8 @@ namespace paddle { ...@@ -24,8 +24,8 @@ namespace paddle {
namespace lite { namespace lite {
namespace mir { namespace mir {
bool KernelScoreCmp(const std::pair<size_t, std::unique_ptr<KernelBase>>& a, bool KernelScoreCmp(const std::pair<float, std::unique_ptr<KernelBase>>& a,
const std::pair<size_t, std::unique_ptr<KernelBase>>& b) { const std::pair<float, std::unique_ptr<KernelBase>>& b) {
return a.first > b.first; return a.first > b.first;
} }
...@@ -44,12 +44,12 @@ void StaticKernelPickPass::Apply(const std::unique_ptr<SSAGraph>& graph) { ...@@ -44,12 +44,12 @@ void StaticKernelPickPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
auto& instruct = node.AsStmt(); auto& instruct = node.AsStmt();
// Get candidate kernels // Get candidate kernels
std::vector<std::pair<size_t, std::unique_ptr<KernelBase>>> scored; std::vector<std::pair<float, std::unique_ptr<KernelBase>>> scored;
CHECK(!instruct.kernels().empty()) << "No kernels found for " CHECK(!instruct.kernels().empty()) << "No kernels found for "
<< instruct.op_type(); << instruct.op_type();
VLOG(4) << "instruct.kernels().size():" << instruct.kernels().size(); VLOG(4) << "instruct.kernels().size():" << instruct.kernels().size();
for (auto&& kernel : instruct.kernels()) { for (auto&& kernel : instruct.kernels()) {
size_t score = KernelGrade(*kernel); float score = KernelGrade(*kernel, graph->valid_places());
VLOG(4) << "kernel->summary():" << kernel->summary() VLOG(4) << "kernel->summary():" << kernel->summary()
<< " score:" << score; << " score:" << score;
scored.emplace_back(score, std::move(kernel)); scored.emplace_back(score, std::move(kernel));
...@@ -99,7 +99,7 @@ void StaticKernelPickPass::Apply(const std::unique_ptr<SSAGraph>& graph) { ...@@ -99,7 +99,7 @@ void StaticKernelPickPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
instruct.ResetOp(update_desc, graph->valid_places()); instruct.ResetOp(update_desc, graph->valid_places());
scored.clear(); scored.clear();
for (auto&& kernel : instruct.kernels()) { for (auto&& kernel : instruct.kernels()) {
size_t score = KernelGrade(*kernel); float score = KernelGrade(*kernel, graph->valid_places());
scored.emplace_back(score, std::move(kernel)); scored.emplace_back(score, std::move(kernel));
} }
std::sort(scored.begin(), scored.end(), KernelScoreCmp); std::sort(scored.begin(), scored.end(), KernelScoreCmp);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <vector>
#include "lite/core/mir/pass.h" #include "lite/core/mir/pass.h"
#include "lite/core/types.h" #include "lite/core/types.h"
...@@ -38,8 +39,6 @@ class StaticKernelPickPass : public mir::StmtPass { ...@@ -38,8 +39,6 @@ class StaticKernelPickPass : public mir::StmtPass {
public: public:
void Apply(const std::unique_ptr<SSAGraph>& graph) override; void Apply(const std::unique_ptr<SSAGraph>& graph) override;
void SetPreferPlace(const Place& place) { place_ = place; }
const Place& place() const { return place_; }
const core::KernelPickFactor& kernel_pick_factors() const { const core::KernelPickFactor& kernel_pick_factors() const {
return kernel_pick_factors_; return kernel_pick_factors_;
} }
...@@ -49,39 +48,63 @@ class StaticKernelPickPass : public mir::StmtPass { ...@@ -49,39 +48,63 @@ class StaticKernelPickPass : public mir::StmtPass {
private: private:
// Score the kernel. // Score the kernel.
size_t KernelGrade(const lite::KernelBase& kernel) { size_t KernelGrade(const lite::KernelBase& kernel,
size_t score{}; const std::vector<Place>& places) {
CHECK_GT(places.size(), 0) << "valid_places is empty.";
float final_score{-1.};
Place winner_place{places[0]};
const int kMax = const int kMax =
std::numeric_limits<core::KernelPickFactor::value_type>::max(); std::numeric_limits<core::KernelPickFactor::value_type>::max();
VLOG(4) << "[score s1]:" << score; size_t place_size = places.size();
// The more important factor comes first
if (kernel_pick_factors_.IsTargetConsidered() && // NOTE: We compare kernel's place with place in valid_places to select the
(place().target == kernel.target() || kernel.target() == TARGET(kAny) || // best match place
place().target == TARGET(kAny))) { // The place's order in valid_places array decide the user's
score += // preference
kMax / static_cast<int>(core::KernelPickFactor::Factor::TargetFirst); // final_score = weight * socre
} // weight: The weight is compute with (valid_places.size() - i) /
VLOG(4) << "[score s2]:" << score; // valid_places.size() as default.
if (kernel_pick_factors_.IsPrecisionConsidered() && // where i is the place's index in valid_places array.
(place().precision == kernel.precision() || // score: score is the weighted sum of target、percision and layout
kernel.precision() == PRECISION(kAny) || for (int i = 0; i < place_size; ++i) {
place().precision == PRECISION(kAny))) { const auto& place = places[i];
score += kMax / float weight = static_cast<float>(place_size - i) / place_size;
static_cast<int>(core::KernelPickFactor::Factor::PrecisionFirst); size_t score{};
} // The more important factor comes first
VLOG(4) << "[score s3]:" << score; if (kernel_pick_factors_.IsTargetConsidered() &&
if (kernel_pick_factors_.IsDataLayoutConsidered() && (place.target == kernel.target() || kernel.target() == TARGET(kAny) ||
(place().layout == kernel.layout() || place.target == TARGET(kAny))) {
kernel.layout() == DATALAYOUT(kAny) || score += kMax /
place().layout == DATALAYOUT(kAny))) { static_cast<int>(core::KernelPickFactor::Factor::TargetFirst);
score += kMax / static_cast<int>( }
core::KernelPickFactor::Factor::DataLayoutFirst); VLOG(4) << "[score s1]:" << score;
if (kernel_pick_factors_.IsPrecisionConsidered() &&
(place.precision == kernel.precision() ||
kernel.precision() == PRECISION(kAny) ||
place.precision == PRECISION(kAny))) {
score += kMax / static_cast<int>(
core::KernelPickFactor::Factor::PrecisionFirst);
}
VLOG(4) << "[score s2]:" << score;
if (kernel_pick_factors_.IsDataLayoutConsidered() &&
(place.layout == kernel.layout() ||
kernel.layout() == DATALAYOUT(kAny) ||
place.layout == DATALAYOUT(kAny))) {
score += kMax / static_cast<int>(
core::KernelPickFactor::Factor::DataLayoutFirst);
}
VLOG(4) << "[score s3]:" << score;
if (weight * score > final_score) {
final_score = weight * score;
winner_place = place;
}
} }
VLOG(4) << "[score s4(final)]:" << score;
VLOG(4) << "[score(final)]:" << final_score;
VLOG(4) << "-------- pick summary --------"; VLOG(4) << "-------- pick summary --------";
VLOG(4) << " ===> place():" << PrecisionToStr(place().precision) << " " VLOG(4) << " ===> place():" << PrecisionToStr(winner_place.precision) << " "
<< DataLayoutToStr(place().layout) << " " << DataLayoutToStr(winner_place.layout) << " "
<< TargetToStr(place().target); << TargetToStr(winner_place.target);
VLOG(4) << " ===> kernel.place():" VLOG(4) << " ===> kernel.place():"
<< PrecisionToStr(kernel.place().precision) << " " << PrecisionToStr(kernel.place().precision) << " "
<< DataLayoutToStr(kernel.place().layout) << " " << DataLayoutToStr(kernel.place().layout) << " "
...@@ -89,20 +112,18 @@ class StaticKernelPickPass : public mir::StmtPass { ...@@ -89,20 +112,18 @@ class StaticKernelPickPass : public mir::StmtPass {
VLOG(4) << "kernel.op_type():" << kernel.op_type(); VLOG(4) << "kernel.op_type():" << kernel.op_type();
VLOG(4) << "picker tactic " << kernel_pick_factors_; VLOG(4) << "picker tactic " << kernel_pick_factors_;
VLOG(4) << "kernel place " << kernel.place().DebugString(); VLOG(4) << "kernel place " << kernel.place().DebugString();
VLOG(4) << "picker place " << place().DebugString(); VLOG(4) << "picker place " << winner_place.DebugString();
VLOG(4) << "score " << score;
VLOG(4) << "------------------------------"; VLOG(4) << "------------------------------";
// The data layout is not considered, for the input and output arguments // The data layout is not considered, for the input and output arguments
// might have different data layout. // might have different data layout.
// TODO(Superjomn) reconsider the idea of taking the data layout as a kernel // TODO(Superjomn) reconsider the idea of taking the data layout as a kernel
// specification. // specification.
return score; return final_score;
} }
private: private:
core::KernelPickFactor kernel_pick_factors_; core::KernelPickFactor kernel_pick_factors_;
Place place_;
}; };
} // namespace mir } // namespace mir
......
...@@ -106,7 +106,6 @@ std::shared_ptr<lite_api::PaddlePredictor> TestModel( ...@@ -106,7 +106,6 @@ std::shared_ptr<lite_api::PaddlePredictor> TestModel(
const std::string& model_dir, const std::string& model_dir,
const std::string& model_file, const std::string& model_file,
const std::string& params_file, const std::string& params_file,
const lite_api::Place& preferred_place,
const std::vector<lite_api::Place>& valid_places, const std::vector<lite_api::Place>& valid_places,
const std::vector<std::vector<int64_t>>& input_tensor_shape, const std::vector<std::vector<int64_t>>& input_tensor_shape,
const std::string& optimized_model_dir) { const std::string& optimized_model_dir) {
...@@ -115,7 +114,6 @@ std::shared_ptr<lite_api::PaddlePredictor> TestModel( ...@@ -115,7 +114,6 @@ std::shared_ptr<lite_api::PaddlePredictor> TestModel(
cxx_config.set_model_dir(model_dir); cxx_config.set_model_dir(model_dir);
cxx_config.set_model_file(model_file); cxx_config.set_model_file(model_file);
cxx_config.set_param_file(params_file); cxx_config.set_param_file(params_file);
cxx_config.set_preferred_place(preferred_place);
cxx_config.set_valid_places(valid_places); cxx_config.set_valid_places(valid_places);
auto predictor = lite_api::CreatePaddlePredictor(cxx_config); auto predictor = lite_api::CreatePaddlePredictor(cxx_config);
FillInputTensor(predictor, input_tensor_shape, 1); FillInputTensor(predictor, input_tensor_shape, 1);
...@@ -151,9 +149,7 @@ TEST(NPUSubgraph, compare) { ...@@ -151,9 +149,7 @@ TEST(NPUSubgraph, compare) {
TestModel(FLAGS_model_dir, TestModel(FLAGS_model_dir,
FLAGS_model_file, FLAGS_model_file,
FLAGS_params_file, FLAGS_params_file,
lite_api::Place{TARGET(kARM), PRECISION(kFloat)}, {lite_api::Place{TARGET(kARM), PRECISION(kFloat)}},
{lite_api::Place{TARGET(kHost), PRECISION(kFloat)},
lite_api::Place{TARGET(kARM), PRECISION(kFloat)}},
input_tensor_shape, input_tensor_shape,
FLAGS_optimized_model_dir + "/CPU"); FLAGS_optimized_model_dir + "/CPU");
// generate and run optimized NPU model // generate and run optimized NPU model
...@@ -162,9 +158,7 @@ TEST(NPUSubgraph, compare) { ...@@ -162,9 +158,7 @@ TEST(NPUSubgraph, compare) {
TestModel(FLAGS_model_dir, TestModel(FLAGS_model_dir,
FLAGS_model_file, FLAGS_model_file,
FLAGS_params_file, FLAGS_params_file,
lite_api::Place{TARGET(kARM), PRECISION(kFloat)}, {lite_api::Place{TARGET(kARM), PRECISION(kFloat)},
{lite_api::Place{TARGET(kHost), PRECISION(kFloat)},
lite_api::Place{TARGET(kARM), PRECISION(kFloat)},
lite_api::Place{TARGET(kNPU), PRECISION(kFloat)}}, lite_api::Place{TARGET(kNPU), PRECISION(kFloat)}},
input_tensor_shape, input_tensor_shape,
FLAGS_optimized_model_dir + "/NPU"); FLAGS_optimized_model_dir + "/NPU");
......
...@@ -63,18 +63,6 @@ TEST(variable_place_inference_pass, test) { ...@@ -63,18 +63,6 @@ TEST(variable_place_inference_pass, test) {
"type_target_cast_pass", // "type_target_cast_pass", //
}); });
Place prefered_place{
#ifdef PADDLE_WITH_CUDA
TARGET(kCUDA), PRECISION(kFloat), DATALAYOUT(kNCHW),
#else
#ifdef PADDLE_WITH_ARM
TARGET(kARM), PRECISION(kFloat), DATALAYOUT(kNCHW),
#else // X86
TARGET(kX86), PRECISION(kFloat), DATALAYOUT(kNCHW),
#endif // ARM
#endif
};
optimizer.KernelPickPreferPlace(prefered_place);
optimizer.Run(std::move(program), places, factor, passes); optimizer.Run(std::move(program), places, factor, passes);
} }
......
...@@ -117,13 +117,6 @@ class Optimizer { ...@@ -117,13 +117,6 @@ class Optimizer {
exec_scope_ = program.exec_scope(); exec_scope_ = program.exec_scope();
} }
void KernelPickPreferPlace(const Place& place) {
auto* pass = mir::PassManager::Global().LookUp<mir::StaticKernelPickPass>(
"static_kernel_pick_pass");
CHECK(pass);
pass->SetPreferPlace(place);
}
const lite::Scope* exec_scope() const { return exec_scope_; } const lite::Scope* exec_scope() const { return exec_scope_; }
// Generate a new program based on the mir graph. // Generate a new program based on the mir graph.
......
...@@ -38,10 +38,8 @@ void RunModel() { ...@@ -38,10 +38,8 @@ void RunModel() {
config.set_model_dir(FLAGS_model_dir); config.set_model_dir(FLAGS_model_dir);
std::vector<Place> valid_places{Place{TARGET(kARM), PRECISION(kFloat)}}; std::vector<Place> valid_places{Place{TARGET(kARM), PRECISION(kFloat)}};
if (FLAGS_prefer_int8_kernel) { if (FLAGS_prefer_int8_kernel) {
valid_places.push_back(Place{TARGET(kARM), PRECISION(kInt8)}); valid_places.insert(valid_places.begin(),
config.set_preferred_place(Place{TARGET(kARM), PRECISION(kInt8)}); Place{TARGET(kARM), PRECISION(kInt8)});
} else {
config.set_preferred_place(Place{TARGET(kARM), PRECISION(kFloat)});
} }
config.set_valid_places(valid_places); config.set_valid_places(valid_places);
......
...@@ -102,7 +102,7 @@ class Module { ...@@ -102,7 +102,7 @@ class Module {
void AddValidPlaceDecl() { void AddValidPlaceDecl() {
// clang-format off // clang-format off
Line("std::vector<lite::Place> valid_places({lite::Place({TARGET(kX86), PRECISION(kFloat), DATALAYOUT(kNCHW)}), lite::Place({TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny)})});"); // NOLINT Line("std::vector<lite::Place> valid_places({lite::Place({TARGET(kX86), PRECISION(kFloat), DATALAYOUT(kNCHW)})});"); // NOLINT
// clang-format on // clang-format on
} }
......
...@@ -35,7 +35,6 @@ void Run(DebugConfig* conf) { ...@@ -35,7 +35,6 @@ void Run(DebugConfig* conf) {
#endif #endif
lite::Predictor predictor; lite::Predictor predictor;
std::vector<Place> valid_places({ std::vector<Place> valid_places({
Place{TARGET(kHost), PRECISION(kFloat)},
#ifdef LITE_WITH_ARM #ifdef LITE_WITH_ARM
Place{TARGET(kARM), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)},
#endif #endif
...@@ -60,23 +59,7 @@ void Run(DebugConfig* conf) { ...@@ -60,23 +59,7 @@ void Run(DebugConfig* conf) {
"runtime_context_assign_pass", "runtime_context_assign_pass",
}}; }};
predictor.Build(conf->model_dir, predictor.Build(conf->model_dir, "", "", valid_places, passes);
"",
"",
#ifdef LITE_WITH_ARM
Place{TARGET(kARM), PRECISION(kFloat)},
#endif
#ifdef LITE_WITH_X86
Place{TARGET(kX86), PRECISION(kFloat)},
#endif
#ifdef LITE_WITH_FPGA
Place{TARGET(kFPGA), PRECISION(kFloat)},
#endif
#ifdef LITE_WITH_CUDA
Place{TARGET(kCUDA), PRECISION(kFloat)},
#endif
valid_places,
passes);
predictor.GenRuntimeProgram(); predictor.GenRuntimeProgram();
auto& instructions = predictor.runtime_program().instructions(); auto& instructions = predictor.runtime_program().instructions();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册