Skip to content

Commit

Permalink
merge the develop branch, test=develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Shixiaowei02 committed Dec 14, 2020
2 parents 1c87749 + 6ff416b commit 70c510c
Show file tree
Hide file tree
Showing 79 changed files with 4,401 additions and 974 deletions.
8 changes: 4 additions & 4 deletions cmake/cross_compiling/postproject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ if(ARMLINUX)
endif()

if(ARMLINUX_ARCH_ABI STREQUAL "armv7")
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon ${CMAKE_C_FLAGS}")
message(STATUS "NEON is enabled on arm-v7a with softfp")
endif()

if(ARMLINUX_ARCH_ABI STREQUAL "armv7hf")
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_C_FLAGS}" )
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon ${CMAKE_C_FLAGS}" )
message(STATUS "NEON is enabled on arm-v7a with hard float")
endif()
endif()
Expand Down
5 changes: 2 additions & 3 deletions docs/demo_guides/x86.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PaddleLite使用X86预测部署

## 一、Docker或者Linux环境
## 一、Docker或者Linux/Mac环境

Paddle-Lite 支持在Docker或Linux环境编译x86预测库。环境搭建参考[编译环境准备](../source_compile/compile_env)

Expand All @@ -26,8 +26,7 @@ cd Paddle-Lite
--build_python=ON/OFF # 编译支持Python API的预测库,默认值 OFF
--with_extra=ON/OFF # 编译支持全量算子的预测库,当Python打开时默认打开,否则为 OFF
--with_static_mkl=ON/OFF # 编译静态链接的MKL库,否则为动态链接,默认值为 OFF
--with_opencl=ON/OFF # 编译支持OpenCL的预测库,默认值 OFF
```
--build_opencl=ON/OFF # 编译支持OpenCL的预测库,默认值为 OFF,如`./lite/tools/build.sh --build_opencl=ON x86`

### 编译结果说明

Expand Down
4 changes: 2 additions & 2 deletions docs/user_guides/opt/opt_bin.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PaddlePaddle模型有两种保存格式:
--param_file=<param_path> \
--optimize_out_type=(protobuf|naive_buffer) \
--optimize_out=<output_optimize_model_dir> \
--valid_targets=(arm|opencl|x86|npu) \
--valid_targets=(arm|opencl|x86|x86_opencl|npu) \
--record_tailoring_info =(true|false) \
--quant_model=(true|false) \
--quant_type=(QUANT_INT8|QUANT_INT16)
Expand All @@ -67,7 +67,7 @@ PaddlePaddle模型有两种保存格式:
| --param_file | 待优化的PaddlePaddle模型(combined形式)的权重文件路径。 |
| --optimize_out_type | 输出模型类型,目前支持两种类型:protobuf和naive_buffer,其中naive_buffer是一种更轻量级的序列化/反序列化实现。若您需要在mobile端执行模型预测,请将此选项设置为naive_buffer。默认为protobuf。 |
| --optimize_out | 优化模型的输出路径。 |
| --valid_targets | 指定模型可执行的backend,默认为arm。目前可支持x86、arm、opencl、npu,可以同时指定多个backend(以空格分隔),Model Optimize Tool将会自动选择最佳方式。如果需要支持华为NPU(Kirin 810/990 Soc搭载的达芬奇架构NPU),应当设置为"npu,arm"。 |
| --valid_targets | 指定模型可执行的backend,默认为arm。目前可支持x86、x86_opencl、arm、opencl、npu,可以同时指定多个backend(以空格分隔),Model Optimize Tool将会自动选择最佳方式。如果需要支持华为NPU(Kirin 810/990 Soc搭载的达芬奇架构NPU),应当设置为"npu,arm"。 |
| --record_tailoring_info | 当使用 [根据模型裁剪库文件](./library_tailoring.html) 功能时,则设置该选项为true,以记录优化后模型含有的kernel和OP信息,默认为false。 |
| --quant_model | 设置是否使用opt中的动态离线量化功能。 |
| --quant_type | 指定opt中动态离线量化功能的量化类型,可以设置为QUANT_INT8和QUANT_INT16,即分别量化为int8和int16。量化为int8对模型精度有一点影响,模型体积大概减小4倍。量化为int16对模型精度基本没有影响,模型体积大概减小2倍。|
Expand Down
4 changes: 2 additions & 2 deletions docs/user_guides/opt/opt_python.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ paddle_lite_opt \
--param_file=<param_path> \
--optimize_out_type=(protobuf|naive_buffer) \
--optimize_out=<output_optimize_model_dir> \
--valid_targets=(arm|opencl|x86|npu) \
--valid_targets=(arm|opencl|x86|x86_opencl|npu) \
--record_tailoring_info =(true|false) \
--quant_model=(true|false) \
--quant_type=(QUANT_INT16|QUANT_INT8)
Expand All @@ -70,7 +70,7 @@ paddle_lite_opt \
| --param_file | 待优化的PaddlePaddle模型(combined形式)的权重文件路径。 |
| --optimize_out_type | 输出模型类型,目前支持两种类型:protobuf和naive_buffer,其中naive_buffer是一种更轻量级的序列化/反序列化实现。若您需要在mobile端执行模型预测,请将此选项设置为naive_buffer。默认为protobuf。 |
| --optimize_out | 优化模型的输出路径。 |
| --valid_targets | 指定模型可执行的backend,默认为arm。目前可支持x86、arm、opencl、npu,可以同时指定多个backend(以空格分隔),Model Optimize Tool将会自动选择最佳方式。如果需要支持华为NPU(Kirin 810/990 Soc搭载的达芬奇架构NPU),应当设置为"npu,arm"。 |
| --valid_targets | 指定模型可执行的backend,默认为arm。目前可支持x86、arm、opencl、x86_opencl、npu,可以同时指定多个backend(以空格分隔),Model Optimize Tool将会自动选择最佳方式。如果需要支持华为NPU(Kirin 810/990 Soc搭载的达芬奇架构NPU),应当设置为"npu,arm"。 |
| --record_tailoring_info | 当使用 [根据模型裁剪库文件](./library_tailoring.html) 功能时,则设置该选项为true,以记录优化后模型含有的kernel和OP信息,默认为false。 |
| --quant_model | 设置是否使用opt中的动态离线量化功能。 |
| --quant_type | 指定opt中动态离线量化功能的量化类型,可以设置为QUANT_INT8和QUANT_INT16,即分别量化为8比特和16比特。 量化为int8对模型精度有一点影响,模型体积大概减小4倍。量化为int16对模型精度基本没有影,模型体积大概减小2倍。|
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guides/opt/x2paddle&opt.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Arguments about x2paddle:
--framework=onnx --model=onnx_model.onnx

Arguments about opt:
--valid_targets=(arm|opencl|x86|npu); valid targets on Paddle-Lite.
--valid_targets=(arm|opencl|x86|x86_opencl|npu); valid targets on Paddle-Lite.
--fluid_save_dir='path to outputed model after x2paddle'
--optimize_out='path to outputed Paddle-Lite model'
----------------------------------------
Expand Down
54 changes: 54 additions & 0 deletions lite/api/cxx_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ void Predictor::Build(const std::shared_ptr<cpp::ProgramDesc> &program_desc,
optimizer_.Run(std::move(program), inner_places, factor, passes);
exec_scope_ = optimizer_.exec_scope();
PrepareFeedFetch();
// Verify if the ops version of current runtime program is
// the same with that in models.
CheckPaddleOpVersions(program_desc);
}

void Predictor::GenRuntimeProgram() {
Expand Down Expand Up @@ -388,6 +391,57 @@ lite::Tensor *Predictor::GetInputByName(const std::string &name) {
}
}

/////////////////////////////////////////////////////////////////////////
// Name: CheckPaddleOpVersions
// Author: DannyIsFunny (github)
// Usage: Compare op versions between inputed fluid model and current
// kernels registry in opt tool.
// Eg. inputed model: Mobilenet_v1, op `conv2d` with version 2.
// opt tool: op version of kernel `conv2d` should be no less than 2.
/////////////////////////////////////////////////////////////////////////
void Predictor::CheckPaddleOpVersions(
const std::shared_ptr<cpp::ProgramDesc> &program_desc) {
// step1. get all the kernels from current programdesc
auto block_size = program_desc->BlocksSize();
for (size_t block_idx = 0; block_idx < block_size; ++block_idx) {
const auto &insts = program_->instructions(block_idx);
for (auto &inst : insts) {
// 1.1 each kernel from inputed fluid model.
const auto &op = inst.op()->op_info();
std::string op_name = op->Type();
if (program_desc->HasOpVersionMap()) {
auto *kernel = inst.kernel();
// Step2. Compared op versions of inputed model and kernel registry.
// 2.1 Get op_version_map from inputed fluid model.
auto *model_op_version =
program_desc->GetOpVersionMap<general::OpVersionMap>();
// 2.1 Get op_version versions from kernel registry.
auto kernel_versions =
ParamTypeRegistry::Global()
.GetKernelVersion(kernel->key_with_alias(), kernel->place())
.OpVersions();
for (auto iter = kernel_versions.begin(); iter != kernel_versions.end();
iter++) {
int32_t model_op_version_index =
model_op_version->GetOpVersionByName(iter->first);
// Step3. Compared op version between inputed model and kernel
// registry.
if ((model_op_version_index > iter->second) &&
(model_op_version_index != -1)) {
LOG(WARNING) << "Error: incompatible paddle op version. Kernel ("
<< kernel->name() << ") requires that op_version("
<< iter->first << ")==" << iter->second
<< ". However, the op_version(" << iter->first
<< ") in this models is " << model_op_version_index
<< ". It's suggested to use PaddlePaddle and "
"Paddle-Lite of the same op_version("
<< iter->first << ").";
}
}
}
}
}
}
// #ifdef LITE_WITH_TRAIN
// void Predictor::FeedVars(const std::vector<framework::Tensor> &tensors) {
// auto var = scope_->FindVar("feed");
Expand Down
8 changes: 8 additions & 0 deletions lite/api/cxx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ class LITE_API Predictor {
bool record_info = false);
void SaveOpKernelInfo(const std::string& model_dir);

/////////////////////////////////////////////////////////////////////////////
// Name: CheckPaddleOpVersions
// Usage: Verify if the ops version of current runtime program is
// the same with that in models.
/////////////////////////////////////////////////////////////////////////////
void CheckPaddleOpVersions(
const std::shared_ptr<cpp::ProgramDesc>& program_desc);

// #ifdef LITE_WITH_TRAIN
// void Run(const std::vector<framework::Tensor>& tensors) {
// FeedVars(tensors);
Expand Down
Loading

0 comments on commit 70c510c

Please sign in to comment.