diff --git a/paddle/fluid/lite/api/cxx_api_bin.cc b/paddle/fluid/lite/api/cxx_api_bin.cc index 0cc786c024f6d7447ec57bb4a539ddf8bcdb1c25..f17f7a7d5faf31e453a5759320884399abdbc47f 100644 --- a/paddle/fluid/lite/api/cxx_api_bin.cc +++ b/paddle/fluid/lite/api/cxx_api_bin.cc @@ -14,9 +14,9 @@ #include "paddle/fluid/lite/api/cxx_api.h" -#ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK +// #ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK #include "paddle/fluid/lite/core/mir/passes.h" -#endif +// #endif #include "paddle/fluid/lite/core/op_registry.h" @@ -24,6 +24,9 @@ namespace paddle { namespace lite { void Run(const char* model_dir) { +#ifdef LITE_WITH_ARM + DeviceInfo::Init(); +#endif lite::ExecutorLite predictor; std::vector valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, Place{TARGET(kARM), PRECISION(kFloat)}}); @@ -32,9 +35,9 @@ void Run(const char* model_dir) { valid_places); auto* input_tensor = predictor.GetInput(0); - input_tensor->Resize(DDim(std::vector({3, 224, 224}))); + input_tensor->Resize(DDim(std::vector({1, 3, 224, 224}))); auto* data = input_tensor->mutable_data(); - for (int i = 0; i < 3 * 224 * 224; i++) { + for (int i = 0; i < input_tensor->dims().production(); i++) { data[i] = i; } @@ -65,7 +68,7 @@ USE_LITE_OP(feed); USE_LITE_OP(fetch); USE_LITE_OP(io_copy); -USE_LITE_OP(con2d); +USE_LITE_OP(conv2d); // USE_LITE_OP(batch_norm); USE_LITE_OP(relu); USE_LITE_OP(depthwise_conv2d); @@ -81,10 +84,10 @@ USE_LITE_KERNEL(fc, kARM, kFloat, kNCHW, def); USE_LITE_KERNEL(mul, kARM, kFloat, kNCHW, def); USE_LITE_KERNEL(scale, kARM, kFloat, kNCHW, def); -USE_LITE_KERNEL(con2d, kARM, kFloat, kNCHW, def); +USE_LITE_KERNEL(conv2d, kARM, kFloat, kNCHW, def); USE_LITE_KERNEL(batch_norm, kARM, kFloat, kNCHW, def); USE_LITE_KERNEL(relu, kARM, kFloat, kNCHW, def); -USE_LITE_KERNEL(depthwise_con2d, kARM, kFloat, kNCHW, def); +USE_LITE_KERNEL(depthwise_conv2d, kARM, kFloat, kNCHW, def); USE_LITE_KERNEL(pool2d, kARM, kFloat, kNCHW, def); USE_LITE_KERNEL(elementwise_add, kARM, kFloat, kNCHW, def); USE_LITE_KERNEL(softmax, kARM, kFloat, kNCHW, def); diff --git a/paddle/fluid/lite/core/optimizer.h b/paddle/fluid/lite/core/optimizer.h index 161e765a98ba54bfaee11fb7b6f3ae1b4bde23d4..63d0ffbc6b8abc7a3ed6361860c6f419236fa876 100644 --- a/paddle/fluid/lite/core/optimizer.h +++ b/paddle/fluid/lite/core/optimizer.h @@ -46,24 +46,24 @@ class Optimizer { SpecifyKernelPickTactic(kernel_pick_factor); InitTargetTypeTransformPass(); -#ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK + // #ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK if (passes.empty()) { RunPasses(std::vector{{ - "static_kernel_pick_pass", // - "variable_place_inference_pass", // - "argument_type_display_pass", // - "type_target_transform_pass", // - "argument_type_display_pass", // - "variable_place_inference_pass", // - "argument_type_display_pass", // - "io_copy_kernel_pick_pass", // - "variable_place_inference_pass", // - "runtime_context_assign_pass", // + // "static_kernel_pick_pass", // + // "variable_place_inference_pass", // + // "argument_type_display_pass", // + // "type_target_transform_pass", // + // "argument_type_display_pass", // + // "variable_place_inference_pass", // + // "argument_type_display_pass", // + // "io_copy_kernel_pick_pass", // + // "variable_place_inference_pass", // + "runtime_context_assign_pass", // }}); } else { RunPasses(passes); } -#endif + // #endif exec_scope_ = program.exec_scope(); } diff --git a/paddle/fluid/lite/kernels/arm/conv_compute.cc b/paddle/fluid/lite/kernels/arm/conv_compute.cc index 0b464a5df0b0c33e76d2a31db183a515fea7a015..5e9ddb6271684120c8cab68e6e10bade3a3ab015 100644 --- a/paddle/fluid/lite/kernels/arm/conv_compute.cc +++ b/paddle/fluid/lite/kernels/arm/conv_compute.cc @@ -102,7 +102,7 @@ REGISTER_LITE_KERNEL(conv2d, kARM, kFloat, kNCHW, .BindInput("Input", {LiteType::GetTensorTy(TARGET(kARM))}) .BindInput("Bias", {LiteType::GetTensorTy(TARGET(kARM))}) .BindInput("Filter", {LiteType::GetTensorTy(TARGET(kARM))}) - .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kARM))}) + .BindOutput("Output", {LiteType::GetTensorTy(TARGET(kARM))}) .Finalize(); REGISTER_LITE_KERNEL(depthwise_conv2d, kARM, kFloat, kNCHW, @@ -110,5 +110,5 @@ REGISTER_LITE_KERNEL(depthwise_conv2d, kARM, kFloat, kNCHW, .BindInput("Input", {LiteType::GetTensorTy(TARGET(kARM))}) .BindInput("Bias", {LiteType::GetTensorTy(TARGET(kARM))}) .BindInput("Filter", {LiteType::GetTensorTy(TARGET(kARM))}) - .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kARM))}) + .BindOutput("Output", {LiteType::GetTensorTy(TARGET(kARM))}) .Finalize(); diff --git a/paddle/fluid/lite/kernels/arm/elementwise_add_compute.cc b/paddle/fluid/lite/kernels/arm/elementwise_add_compute.cc index 310cde17bbd2f235789250fa02f8e8f82f672ff0..3c11451ce576f203794fdf4857832886b88477cb 100644 --- a/paddle/fluid/lite/kernels/arm/elementwise_add_compute.cc +++ b/paddle/fluid/lite/kernels/arm/elementwise_add_compute.cc @@ -26,7 +26,7 @@ void ElementwiseAddCompute::Run() { const float* y_data = param.Y->data(); float* out_data = param.Out->mutable_data(); int n = param.X->dims().production(); - lite::arm::math::elementwise_add(x_data, y_data, out_data, n); + // lite::arm::math::elementwise_add(x_data, y_data, out_data, n); } } // namespace arm diff --git a/paddle/fluid/lite/kernels/arm/pool_compute.cc b/paddle/fluid/lite/kernels/arm/pool_compute.cc index 6a7716fae6bfc3aa52dad7c8b8192191e986b6f3..168b0e50c98bcf8eab324b627478a7790e665b82 100644 --- a/paddle/fluid/lite/kernels/arm/pool_compute.cc +++ b/paddle/fluid/lite/kernels/arm/pool_compute.cc @@ -163,7 +163,7 @@ PrecisionType PoolCompute::precision() const { return PRECISION(kFloat); } } // namespace lite } // namespace paddle -REGISTER_LITE_KERNEL(pool, kARM, kFloat, kNCHW, +REGISTER_LITE_KERNEL(pool2d, kARM, kFloat, kNCHW, paddle::lite::kernels::arm::PoolCompute, def) .BindInput("X", {LiteType::GetTensorTy(TARGET(kARM))}) .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kARM))}) diff --git a/paddle/fluid/lite/kernels/arm/relu_compute.h b/paddle/fluid/lite/kernels/arm/relu_compute.h index 29d17bf5918e112dfd065c9cc11910703ab5e92d..def3f02c5046c8f60fb5c6d518361ae8456253a4 100644 --- a/paddle/fluid/lite/kernels/arm/relu_compute.h +++ b/paddle/fluid/lite/kernels/arm/relu_compute.h @@ -45,4 +45,6 @@ class ReluCompute : public KernelLite { REGISTER_LITE_KERNEL(relu, kARM, kFloat, kNCHW, paddle::lite::kernels::arm::ReluCompute, def) + .BindInput("X", {LiteType::GetTensorTy(TARGET(kARM))}) + .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kARM))}) .Finalize(); diff --git a/paddle/fluid/lite/operators/conv_op.h b/paddle/fluid/lite/operators/conv_op.h index 393b5dc2a8e5e9aa8d94784bc4f5a8d041414200..ceb80456312f8bd208807f1c1ef74c055a709181 100644 --- a/paddle/fluid/lite/operators/conv_op.h +++ b/paddle/fluid/lite/operators/conv_op.h @@ -40,11 +40,11 @@ class ConvOpLite : public OpLite { bool AttachImpl(const cpp::OpDesc &op_desc, lite::Scope *scope) override { auto input = op_desc.Input("Input").front(); auto filter = op_desc.Input("Filter").front(); - auto out = op_desc.Output("Out").front(); + auto output = op_desc.Output("Output").front(); param_.x = scope->FindVar(input)->GetMutable(); param_.filter = scope->FindVar(filter)->GetMutable(); - CHECK(scope->FindVar(out)); - param_.output = scope->FindVar(out)->GetMutable(); + CHECK(scope->FindVar(output)); + param_.output = scope->FindVar(output)->GetMutable(); param_.strides = op_desc.GetAttr>("strides"); param_.paddings = op_desc.GetAttr>("paddings"); param_.groups = op_desc.GetAttr("groups"); @@ -53,19 +53,24 @@ class ConvOpLite : public OpLite { std::vector input_arg_names = op_desc.InputArgumentNames(); if (std::find(input_arg_names.begin(), input_arg_names.end(), "Bias") != input_arg_names.end()) { - auto bias_var = scope->FindVar(op_desc.Input("Bias").front()); - if (bias_var != nullptr) { - param_.bias = - const_cast(&(bias_var->Get())); + auto bias_arguments = op_desc.Input("Bias"); + if (bias_arguments.size() > 0) { + auto bias_var = scope->FindVar(bias_arguments.front()); + if (bias_var != nullptr) { + param_.bias = + const_cast(&(bias_var->Get())); + } } } if (std::find(input_arg_names.begin(), input_arg_names.end(), "ResidualData") != input_arg_names.end()) { - auto residual_data_var = - scope->FindVar(op_desc.Input("ResidualData").front()); - if (residual_data_var != nullptr) { - param_.residualData = const_cast( - &(residual_data_var->Get())); + auto res_data_arguments = op_desc.Input("ResidualData"); + if (res_data_arguments.size() > 0) { + auto residual_data_var = scope->FindVar(res_data_arguments.front()); + if (residual_data_var != nullptr) { + param_.residualData = const_cast( + &(residual_data_var->Get())); + } } } return true; diff --git a/paddle/fluid/lite/operators/pool_op.h b/paddle/fluid/lite/operators/pool_op.h index 2e9a02eec189599ba2fc23da8e7bcc9ebd0ea8b3..bb9963a70e36a6d070fb85e2cddfa39edde58e48 100644 --- a/paddle/fluid/lite/operators/pool_op.h +++ b/paddle/fluid/lite/operators/pool_op.h @@ -53,10 +53,18 @@ class PoolOpLite : public OpLite { param_.strides = op_desc.GetAttr>("strides"); param_.paddings = op_desc.GetAttr>("paddings"); - param_.exclusive = op_desc.GetAttr("exclusive"); - param_.adaptive = op_desc.GetAttr("adaptive"); - param_.ceil_mode = op_desc.GetAttr("ceil_mode"); - param_.use_quantizer = op_desc.GetAttr("use_quantizer"); + if (op_desc.HasAttr("exclusive")) { + param_.exclusive = op_desc.GetAttr("exclusive"); + } + if (op_desc.HasAttr("adaptive")) { + param_.adaptive = op_desc.GetAttr("adaptive"); + } + if (op_desc.HasAttr("ceil_mode")) { + param_.ceil_mode = op_desc.GetAttr("ceil_mode"); + } + if (op_desc.HasAttr("use_quantizer")) { + param_.use_quantizer = op_desc.GetAttr("use_quantizer"); + } // param_.data_format = op_desc.GetAttr("data_format"); return true; } diff --git a/paddle/fluid/lite/operators/relu_op.cc b/paddle/fluid/lite/operators/relu_op.cc index b073e2db43a4891defeb95750424941969323ba0..47251c72dfa5183e19ace3e36a1d3a9dd27a6bb0 100644 --- a/paddle/fluid/lite/operators/relu_op.cc +++ b/paddle/fluid/lite/operators/relu_op.cc @@ -32,12 +32,11 @@ bool ReluOp::InferShape() const { bool ReluOp::AttachImpl(const cpp::OpDesc &opdesc, lite::Scope *scope) { param_.input = const_cast( - &scope->FindVar(opdesc.Input("Input").front())->Get()); + &scope->FindVar(opdesc.Input("X").front())->Get()); param_.output = scope->FindVar(opdesc.Output("Out").front())->GetMutable(); CHECK(param_.input); CHECK(param_.output); - kernel_->SetParam(param_); return true; } diff --git a/paddle/fluid/lite/operators/split_op.cc b/paddle/fluid/lite/operators/split_op.cc index 0d5075b0971e4bd98de8aac9810bbe7514c1a562..58768276377edd9ea92356a808a6f46c3b5c6a80 100644 --- a/paddle/fluid/lite/operators/split_op.cc +++ b/paddle/fluid/lite/operators/split_op.cc @@ -37,7 +37,7 @@ bool SplitOp::InferShape() const { const auto §ions = param_.sections; const int outs_number = outs.size(); - std::vector outs_dims; + std::vector outs_dims; outs_dims.reserve(outs_number); if (num > 0) {