2022年7月版——在“哪吒”上跑AI 全志D1 ncnn框架移植笔记
-
ncnn框架是当前边缘计算的主流框架,关于全志D1运行ncnn框架的笔记,nihui大佬曾经于2021年发表了相关的帖子。但是目前工具链和ncnn版本有所变化,因此在大佬的基础上将,完整过程记录如下。
相关链接:
1.https://bbs.aw-ol.com/topic/705/
2.https://zhuanlan.zhihu.com/p/386312071?utm_source=qq&utm_medium=social&utm_oi=8729554043201413121 准备交叉编译工具链
目前使用的交叉工具链是v2.2.6版本,具体下载链接见:https://occ.t-head.cn/community/download?id=4046947553902661632
下载这个文件:Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.2.6-20220516.tar.gz
tar -xf Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.2.6-20220516.tar.gz export RISCV_ROOT_PATH=/home/{你的用户名}/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.2.6
2 下载和编译ncnn
这边的toolchain file选用c906-v226.toolchain.cmake,其余的不用修改,在toolchain file里面都已经改好了。其中可能有路径问题,根据ncnn文件夹,实际所在的路径修改即可。
git clone https://github.com/Tencent/ncnn.git cd ncnn mkdir build-c906 cd build-c906 cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c906-v226.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_OPENMP=OFF -DNCNN_THREADS=OFF -DNCNN_RUNTIME_CPU=OFF -DNCNN_RVV=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON .. make -j4
3 测试benchncnn
目前2.0版本的TinaLinux 执行 ncnn 程序已经不会有问题
将
ncnn/build-c906/benchmark/benchncnn
和ncnn/benchmark/*.param
拷贝到 d1开发板上,路径结构如下:chmod 0777 benchncnn ./benchncnn 4 1 0 -1 0
oot@TinaLinux:~/ncnn# ./benchncnn 4 1 0 -1 0 syscall error -1 loop_count = 4 num_threads = 1 powersave = 0 gpu_device = -1 cooling_down = 0 fopen squeezenet.param failed network graph not ready Segmentation fault root@TinaLinux:~/ncnn# ./benchncnn 4 1 0 -1 0 syscall error -1 loop_count = 4 num_threads = 1 powersave = 0 gpu_device = -1 cooling_down = 0 squeezenet min = 382.77 max = 385.92 avg = 384.66 squeezenet_int8 min = 8975.18 max = 8979.84 avg = 8977.72 mobilenet min = 702.76 max = 704.76 avg = 703.74 mobilenet_int8 min = 29501.19 max = 29546.07 avg = 29514.59 mobilenet_v2 min = 451.34 max = 452.27 avg = 451.78 mobilenet_v3 min = 358.12 max = 359.24 avg = 358.42 shufflenet min = 527.04 max = 528.48 avg = 527.69 shufflenet_v2 min = 310.96 max = 312.30 avg = 311.59 mnasnet min = 435.13 max = 437.02 avg = 435.94 proxylessnasnet min = 473.05 max = 476.37 avg = 475.19 efficientnet_b0 min = 601.75 max = 610.41 avg = 606.18 efficientnetv2_b0 min = 859.37 max = 861.75 avg = 860.67 regnety_400m min = 653.71 max = 654.24 avg = 653.88 blazeface min = 154.08 max = 154.67 avg = 154.38 googlenet min = 1404.80 max = 1409.50 avg = 1407.33 googlenet_int8 min = 42586.56 max = 42608.04 avg = 42597.36 resnet18 min = 1047.81 max = 1050.59 avg = 1049.40 resnet18_int8 min = 45011.41 max = 45185.10 avg = 45098.12 alexnet min = 955.34 max = 956.98 avg = 956.06 vgg16 min = 5355.40 max = 5356.05 avg = 5355.75
如果一切运行正常,则会出现上述信息。
4 测试example
将
ncnn/build-c906/examples/nanodet
和测试图片拷贝到 d1开发板上从这里下载 nanodet 模型文件并拷贝到 d1开发板上
nihui/ncnn-assetsgithub.com/nihui/ncnn-assets/tree/master/models
目录结构如下:
注意,进过测试,jpg格式的图像读取时会报错,png格式没有问题
./nanodet test.png
-
@yanmingjian 在 2022年7月版——在“哪吒”上跑AI 全志D1 ncnn框架移植笔记 中说:
交叉工具链
跟之前版本的不同点:交叉边缘工具链升级?(v2.2.6)
能测到性能上有提升吗? -
-
@yanmingjian 前辈,请问下,可以用Tina2.0的sdk的交叉编译器去编译码?会有什么问题出现呢?
-
@yanmingjian 前辈你好,我用编译器版本为240的取编译,cmake的时候出现这样的问题,Test NCNN_COMPILER_USE_VFREDSUM - Failed
-- Check for working CXX compiler: /home/zcm/linux/tool/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.4.0/bin/riscv64-unknown-linux-gnu-g++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Performing Test NCNN_COMPILER_SUPPORT_RVV -- Performing Test NCNN_COMPILER_SUPPORT_RVV - Success -- Performing Test NCNN_COMPILER_SUPPORT_RVV_ZFH -- Performing Test NCNN_COMPILER_SUPPORT_RVV_ZFH - Success -- Performing Test NCNN_COMPILER_USE_VFREDSUM -- Performing Test NCNN_COMPILER_USE_VFREDSUM - Failed -- Performing Test NCNN_COMPILER_USE_VFREDUSUM -- Performing Test NCNN_COMPILER_USE_VFREDUSUM - Success -- Performing Test NCNN_COMPILER_USE_RVV_PLAIN_SEG -- Performing Test NCNN_COMPILER_USE_RVV_PLAIN_SEG - Success -- Target arch: riscv
然后编译的时候,没办法正常通过,前辈知道是什么问题吗?
In file included from /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/riscv_activation.h:22, from /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/convolution_riscv.cpp:25: /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h: In function 'vfloat32m1_t sigmoid_ps(vfloat32m1_t, size_t)': /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h:362:43: error: 'vfrec7_v_f32m1' was not declared in this scope; did you mean 'vfneg_v_f32m1'? 362 | vfloat32m##LMUL##_t _reciprocal = vfrec7_v_f32m##LMUL(_v, vl); \ | ^~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h:368:1: note: in expansion of macro '_RVV_FLOAT32_SIGMOID_OP' 368 | _RVV_FLOAT32_SIGMOID_OP(1, 32) | ^~~~~~~~~~~~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h: In function 'vfloat32m2_t sigmoid_ps(vfloat32m2_t, size_t)': /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h:362:43: error: 'vfrec7_v_f32m2' was not declared in this scope; did you mean 'vfneg_v_f32m2'? 362 | vfloat32m##LMUL##_t _reciprocal = vfrec7_v_f32m##LMUL(_v, vl); \ | ^~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h:369:1: note: in expansion of macro '_RVV_FLOAT32_SIGMOID_OP' 369 | _RVV_FLOAT32_SIGMOID_OP(2, 16) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/bin/cmake: /usr/local/lib/libcurl.so.4: no version information available (required by /usr/bin/cmake) [ 21%] Building CXX object src/CMakeFiles/ncnn.dir/layer/elu.cpp.o /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h: In function 'vfloat32m4_t sigmoid_ps(vfloat32m4_t, size_t)': /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h:362:43: error: 'vfrec7_v_f32m4' was not declared in this scope; did you mean 'vfneg_v_f32m4'? 362 | vfloat32m##LMUL##_t _reciprocal = vfrec7_v_f32m##LMUL(_v, vl); \ | ^~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h:370:1: note: in expansion of macro '_RVV_FLOAT32_SIGMOID_OP' 370 | _RVV_FLOAT32_SIGMOID_OP(4, 8) | ^~~~~~~~~~~~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h: In function 'vfloat32m8_t sigmoid_ps(vfloat32m8_t, size_t)': /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h:362:43: error: 'vfrec7_v_f32m8' was not declared in this scope; did you mean 'vfneg_v_f32m8'? 362 | vfloat32m##LMUL##_t _reciprocal = vfrec7_v_f32m##LMUL(_v, vl); \ | ^~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun.h:371:1: note: in expansion of macro '_RVV_FLOAT32_SIGMOID_OP' 371 | _RVV_FLOAT32_SIGMOID_OP(8, 4) | ^~~~~~~~~~~~~~~~~~~~~~~ In file included from /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/riscv_activation.h:23, from /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/convolution_riscv.cpp:25: /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h: In function 'vfloat16m1_t sigmoid_ps(vfloat16m1_t, size_t)': /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h:362:43: error: 'vfrec7_v_f16m1' was not declared in this scope; did you mean 'vfneg_v_f16m1'? 362 | vfloat16m##LMUL##_t _reciprocal = vfrec7_v_f16m##LMUL(_v, vl); \ | ^~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h:368:1: note: in expansion of macro '_RVV_FLOAT16_SIGMOID_OP' 368 | _RVV_FLOAT16_SIGMOID_OP(1, 16) | ^~~~~~~~~~~~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h: In function 'vfloat16m2_t sigmoid_ps(vfloat16m2_t, size_t)': /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h:362:43: error: 'vfrec7_v_f16m2' was not declared in this scope; did you mean 'vfneg_v_f16m2'? 362 | vfloat16m##LMUL##_t _reciprocal = vfrec7_v_f16m##LMUL(_v, vl); \ | ^~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h:369:1: note: in expansion of macro '_RVV_FLOAT16_SIGMOID_OP' 369 | _RVV_FLOAT16_SIGMOID_OP(2, 8) | ^~~~~~~~~~~~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h: In function 'vfloat16m4_t sigmoid_ps(vfloat16m4_t, size_t)': /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h:362:43: error: 'vfrec7_v_f16m4' was not declared in this scope; did you mean 'vfneg_v_f16m4'? 362 | vfloat16m##LMUL##_t _reciprocal = vfrec7_v_f16m##LMUL(_v, vl); \ | ^~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h:370:1: note: in expansion of macro '_RVV_FLOAT16_SIGMOID_OP' 370 | _RVV_FLOAT16_SIGMOID_OP(4, 4) | ^~~~~~~~~~~~~~~~~~~~~~~ /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h: In function 'vfloat16m8_t sigmoid_ps(vfloat16m8_t, size_t)': /home/zcm/linux/Open_lib/ncnn/src/layer/riscv/rvv_mathfun_fp16s.h:362:43: error: 'vfrec7_v_f16m8' was not declared in this scope; did you mean 'vfneg_v_f16m8'? 362 | vfloat16m##LMUL##_t _reciprocal = vfrec7_v_f16m##LMUL(_v, vl); \ | ^~~~~~~~~~~~~
-
@yanmingjian
lz,看帖子内容,可以说,Xuantie-900-gcc-linux-5.10.4-glibc这种对linux-5.10.4进行编译的,构建出来的可执行文件在5.4的内核上也能跑,这个对么? -
@copper 这个真是不清楚,应该是不可以的?没试过
-
@yanmingjian
这个帖子跑的时候不就是我说的那种,工具链是“xxx-linux-5.10.4-yyy”,可执行文件跑在tina上,而tina是5.4.10版本的内核啊。
Copyright © 2023 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号