MNN性能测试笔记

MNN 性能测试笔记

作者:Shengjie

更新日期:2020/01/02

版本记录:

初版 2019/12/31

添加hi3516cv500Linux的编译方式 2020/01/02


MNN 是什么?

MNN 是阿里巴巴开源的一个轻量级深度神经网络推理引擎。

需要测试 MNN 的什么?

MNN 的性能,也就是运行模型的速度。

如何测试?

因为要和 Tengine(OPEN AI LAB) 进行对比,所以限定了几个测试的条件:

  • 同一批模型文件;

  • 同样的主板;

  • 同样的 CPU 频率。

在确定测试的条件后,就可以分几个步骤走:

  1. 模型转换,从原模型转换成 MNN 模型,包含 FP32 和 INT8;
  2. 性能测试程序编译,包括 Linux 和 Android;
  3. 测试运行和结果收集与整理。

模型转换

首先,需要下载 MNN 的开源代码。可以克隆 MNN 放在 GITHUB 上的仓库。为了方便测试过程中的修改一些代码,我将 MNN 克隆到本地后,在 GITLAB 上新建了一个仓库,上传了 MNN 的代码。以下就基于 GITLAB 的这个仓库进行讲解。

注意:模型转换需要在 X86 上进行

1、克隆代码

git clone git@github.com:liushengjiezj/perf_test_mnn.git

2、编译

cd MNN/ 
./schema/generate.sh 
mkdir build 
cd build 
cmake .. -DMNN_BUILD_CONVERTER=true && make -j4

3、转换模型

cd build
**转换FP32格式的模型**
bash convert_mnn.sh -c -o -tf -tflite
**转换INT8格式的模型**
bash convert_mnn_quan.sh

测试程序编译

Linux

cd MNN
mkdir build
cd build
cmake .. -DMNN_BUILD_BENCHMARK=true && make -j4

**hi3516cv500Linux**
cd MNN
bash project/cross-compile/build.sh hi3516cv500Linux

Android

cd MNN
cd benchmark
**编译ARM64的测试程序**
bash bench_android.sh -b -64 -c 
**编译ARM32的测试程序**
bash bench_android.sh -b -c

运行测试程序

Linux

cd MNN
cd build
./benchmark.out models_folter [loop_count] [forwardtype] [numberThread] [precision] [power]

Android

**env init**
cd MNN
cd benchmark
# modify ip addr of Android Device 
vim bench_android.sh
# push files(include models, test program, so file) to ARM64 device
bash bench_android.sh -64 -p
# push files(include models, test program, so file) to ARM32 device
bash bench_adnroid.sh -p

**start testing**
adb -s 10.11.5.* shell < tmp > log 2>&1
tmp file:
cd /data/local/tmp/benchmark_mnn
chmod +x benchmark.out
export LD_LIBRARY_PATH=.
./benchmark.out models_folter [loop_count] [forwardtype] [numberThread] [precision] [power]
Example:
./benchmark.out benchmark_models 10 0 1 2 1
./benchmark.out benchmark_models 10 0 2 2 1
./benchmark.out benchmark_models 10 0 1 2 2
./benchmark.out benchmark_models 10 0 4 2 2
./benchmark.out benchmark_quant_models 10 0 1 2 1
./benchmark.out benchmark_quant_models 10 0 2 2 1
./benchmark.out benchmark_quant_models 10 0 1 2 2
./benchmark.out benchmark_quant_models 10 0 4 2 2

收集&整理结果

1、保存所有 Log 到本机

2、运行结果收集脚本

bash filter_log.sh [log file]

3、将结果写入 Excel

原文地址:https://www.cnblogs.com/liushengchieh/p/14572602.html