MNN icon indicating copy to clipboard operation
MNN copied to clipboard

每次运行时间差异很大,运行也比较慢

Open liushuan opened this issue 7 years ago • 16 comments

我在 RK3399 上面编译 MNN , 使用测试程序 发现 程序的推理时间很慢,每次运行时间也很不稳定差异很大 是怎么回事呢?

liushuan avatar Jun 04 '19 09:06 liushuan

是不是只在 Android 和 ISO 上面运行的较快呢?

liushuan avatar Jun 04 '19 09:06 liushuan

Release编译?多线程怎么设置的?OpenMP开了么?线程数?绑核了么?

li-qing avatar Jun 04 '19 10:06 li-qing

你好,你说的这些我不知道怎么设置,有没有什么文档帮助呢?我是直接按照 install指导安装的。非常感谢------------------ 原始邮件 ------------------ 发件人: "li-qing"[email protected] 发送时间: 2019年6月4日(星期二) 晚上6:59 收件人: "alibaba/MNN"[email protected]; 抄送: "liushuan"[email protected];"Author"[email protected]; 主题: Re: [alibaba/MNN] 每次运行时间差异很大,运行也比较慢 (#104)

Release编译?多线程怎么设置的?OpenMP开了么?线程数?绑核了么?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

liushuan avatar Jun 04 '19 11:06 liushuan

我同时也编译了 OPENCL版本,如何使用呢?------------------ 原始邮件 ------------------ 发件人: "li-qing"[email protected] 发送时间: 2019年6月4日(星期二) 晚上6:59 收件人: "alibaba/MNN"[email protected]; 抄送: "liushuan"[email protected];"Author"[email protected]; 主题: Re: [alibaba/MNN] 每次运行时间差异很大,运行也比较慢 (#104)

Release编译?多线程怎么设置的?OpenMP开了么?线程数?绑核了么?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

liushuan avatar Jun 04 '19 11:06 liushuan

如何使用 opencl 参考 tools/cpp/MNNV2Basic.cpp 以及 doc/Tools_CN.md

你的编译和测试方法是什么?看描述情况估计是没有打开汇编。

jxt1234 avatar Jun 04 '19 11:06 jxt1234

编译 我是直接用的 cmake && make 没有修改 CMakeList.txt 文件。 测试是用的 demo/exec/pictureRecognition.cpp 文件,测试的是 sessionRun 的运行时间。

你好,请问如何打开汇编呢?

liushuan avatar Jun 04 '19 12:06 liushuan

  1. 性能不稳定可能是cpu、gpu频率降频原因:cpu可以通过taskset绑定大小核,然后设置cpu保持最高频。gpu可以通过命令(echo "performance" >/sys/devices/platform/ff9a0000.gpu/devfreq/ff9a0000.gpu/governor cat /sys/devices/platform/ff9a0000.gpu/devfreq/ff9a0000.gpu/cur_freq)把gpu固定到最高频。

  2. rk3399端。如果是android系统。使用方法跟手机端一致。直接参考文档。如果是ubuntu系统,需要用你本地的交叉编译工具链编译(arm-linux-*),然后push进去。

hacker-joe avatar Jun 04 '19 12:06 hacker-joe

我的 rk3399 是 aarch64 GNU/Linux 系統, 我直接在该系统编译的库,然后测试,你的意思是必须要进行交叉编译才行吗? 本地编译又为什么会速度慢呢?

liushuan avatar Jun 05 '19 00:06 liushuan

我的 rk3399 是 aarch64 GNU/Linux 系統, 我直接在该系统编译的库,然后测试,你的意思是必须要进行交叉编译才行吗? 本地编译又为什么会速度慢呢?

liushuan avatar Jun 05 '19 00:06 liushuan

root@firefly:~/work_space/source_code/mnn_face_extract/mnn_face_extract_cpu# ~/work_space/software/MNN-master/build_gl/timeProfile.out ./model/face_extract.mnn 10 3 13128*128 Use extra forward type: 3 1 Open Model ./model/face_extract.mnn Can't Find type=3 backend, use 0 instead Resize error for conv1a, code=3 Sort by node type ! Node Type Avg(ms) % Called times Flops Rate Eltwise 1.573900 0.023736 11.000000 0.039205 Pooling 3.003800 0.045301 2.000000 0.067740 PReLU 5.509998 0.083097 28.000000 0.189252 Convolution 6620.683105 99.847847 28.000000 99.703819 total time : 6630.771973 ms, total mflops : 1391.167847 main, 108, cost time: 66309.242188 ms

这个是模型耗时 情况 用timeProfile.out 测试的, 改模型用 NCNN 耗时是220ms

我编译的时候 打开了 OPENCL 现在测试的时候 使用 3 会提示 Can't Find type=3 backend, use 0 instead

liushuan avatar Jun 05 '19 01:06 liushuan

使用 大模型做测试99M 会 出现错误 root@firefly:~/work_space/source_code/mnn_face_extract/mnn_face_extract_gpu# ~/work_space/software/MNN-master/build_gl/timeProfile.out ./model/512_face_extract.mnn 1 0 13128*128 Use extra forward type: 0 1 Open Model ./model/512_face_extract.mnn Resize error for conv1a, code=3 Segmentation fault (core dumped)

liushuan avatar Jun 05 '19 02:06 liushuan

1、参考 doc/Install_CN.md ,和 ./project/cross-compile/arm.toolchain.cmake, 需要设定 arm processer ,否则不会开启汇编,看你这数据很明显是没开的,另外 cmake 时指定为 Release

OpenCL 的话需要看你的 opencl 库的 位置,可以看下 opencl runtime 中的路径是否覆盖了

2、13128*128 改成 1x3x128x128

jxt1234 avatar Jun 05 '19 02:06 jxt1234

如果是标准的linux系统的话。opencl的路径可能在arm64:/usr/lib/aarch64-linux-gnu/libOpenCL.so, arm32:/usr/lib/arm-linux-gnueabihf/libOpenCL.so

hacker-joe avatar Jun 05 '19 03:06 hacker-joe

这是我的 编译信息: -- >>>>>>>>>>>>> -- MNN BUILD INFO: -- System: Linux -- Processor: aarch64 -- DEBUG: OFF -- Metal: OFF -- OpenCL: ON -- OpenGL: OFF -- Vulkan: OFF -- OpenMP: ON -- Hideen: FALSE -- [*] searching .c -- [] searching .cc -- [] searching .cpp -- [] searching .s .S -- Looking for CL_VERSION_2_0 -- Looking for CL_VERSION_2_0 - not found -- Looking for CL_VERSION_1_2 -- Looking for CL_VERSION_1_2 - not found -- Looking for CL_VERSION_1_1 -- Looking for CL_VERSION_1_1 - not found -- Looking for CL_VERSION_1_0 -- Looking for CL_VERSION_1_0 - not found -- Could NOT find OpenCL (missing: OpenCL_INCLUDE_DIR) -- [] linking MNN with OpenCL done -- [] Checking OpenMP -- Try OpenMP C flag = [-fopenmp] -- Performing Test OpenMP_FLAG_DETECTED -- Performing Test OpenMP_FLAG_DETECTED - Success -- Try OpenMP CXX flag = [-fopenmp] -- Performing Test OpenMP_FLAG_DETECTED -- Performing Test OpenMP_FLAG_DETECTED - Success -- Found OpenMP: -fopenmp
-- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - not found -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE
-- /root/work_space/software/MNN-master/build/benchmark -- Configuring done -- Generating done -- Build files have been written to: /root/work_space/software/MNN-master/build root@firefly:~/work_space/software/MNN-master/build# ls CMakeCache.txt CMakeFiles Makefile

build 产生了 ./libMNN.so ./source/backend/opencl/libMNN_CL.so

liushuan avatar Jun 05 '19 03:06 liushuan

我目前已经 将 libOpenCL.so 和 libMNN_CL.so的目录配置的so的运行环境里面, 但是还是会报 Can't Find type=3 backend, use 0 instead 该如何解决呢?

liushuan avatar Jun 05 '19 04:06 liushuan

opencl 这个问题说明你的opencl 驱动是一个空的 so 库,修改 source/backend/opencl/CMakeLists.txt 选用 wrapper 方式(24-31行选择前半部分分支)

jxt1234 avatar Jun 05 '19 06:06 jxt1234