本来计划基于官方教程(EASY EAI灵眸科技 | 让边缘AI落地更简单 (easy-eai.com))来移植NCNN,后来因为总是遇到问题,如下图,悲催的99%:
索性一不做二不休,直接去NCNN的github(github.com/Tencent/ncnn)拉源码来编。
一、下载源码
$ git clone https://github.com/Tencent/ncnn.git
$ cd ncnn
$ git submodule update --init
来个log
root@EliteDesk:/media/rv1126/ncnn$ git submodule update --init
Submodule 'glslang' (https://github.com/KhronosGroup/glslang) registered for path 'glslang'
Submodule 'python/pybind11' (https://github.com/pybind/pybind11.git) registered for path 'python/pybind11'
Cloning into '/media/rv1126/ncnn/glslang'...
Cloning into '/media/rv1126/ncnn/python/pybind11'...
Submodule path 'glslang': checked out '86ff4bca1ddc7e2262f119c16e7228d0efb67610'
Submodule path 'python/pybind11': checked out '70a58c577eaf067748c2ec31bfd0b0a614cffba6'
二、编译环境
因为我的开发环境是Ubuntu,对于依赖库直接一步到位,全部装上:
sudo apt install build-essential git cmake libprotobuf-dev protobuf-compiler libvulkan-dev vulkan-utils libopencv-dev
交叉编译器,也是一起来:
`sudo apt install g++-arm-linux-gnueabi g++-arm-linux-gnueabihf g++-aarch64-linux-gnu`
忍下,等一会就好。
三、编译
【坑】对于ARM A7 SoC,使用硬浮点功能,不要软件浮点!!!
如果选择了soft float,各种诸如ld-linux.so.3和ld-linux-armhf.so.3等问题都出来了,当然这个可以修改设置相关配置。
为了方便,直接如下操作:
root@EliteDesk:/media/rv1126/ncnn$ mkdir -p build-arm-linux-gnueabihf
root@EliteDesk:/media/rv1126/ncnn$ cd build-arm-linux-gnueabihf
root@EliteDesk:/media/rv1126/ncnn/build-arm-linux-gnueabihf$ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.lchain.cmake ..
CMake Warning at CMakeLists.txt:269 (message):
The compiler does not support armv8.2 fp16. NCNN_ARM82 will be OFF.
然后就是make -j,后面nproc是编译平台的CPU核数。
root@EliteDesk:/media/rv1126/ncnn/build-arm-linux-gnueabihf$ make -j$(nproc)
Scanning dependencies of target ncnn-generate-spirv
[ 0%] Built target ncnn-generate-spirv
Scanning dependencies of target ncnn
[ 1%] Building CXX object src/CMakeFiles/ncnn.dir/allocator.cpp.o
[ 1%] Building CXX object src/CMakeFiles/ncnn.dir/benchmark.cpp.o
[ 1%] Building CXX object src/CMakeFiles/ncnn.dir/blob.cpp.o
[ 2%] Building CXX object
...
[ 97%] Building CXX object src/CMakeFiles/ncnn.dir/layer/einsum.cpp.o
[ 97%] Building CXX object src/CMakeFiles/ncnn.dir/layer/deformableconv2d.cpp.o
[ 98%] Building CXX object src/CMakeFiles/ncnn.dir/layer/glu.cpp.o
[ 99%] Linking CXX static library libncnn.a
[ 99%] Built target ncnn
Scanning dependencies of target benchncnn
[ 99%] Building CXX object benchmark/CMakeFiles/benchncnn.dir/benchncnn.cpp.o
[100%] Linking CXX executable benchncnn
[100%] Built target benchncnn
看看生成的文件:
root@EliteDesk:/media/rv1126/ncnn/build-arm-linux-gnueabihf/benchmark$ file benchncnn
benchncnn: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=c061f0b93db095fd2794afc64e18b4495c3a4467, for GNU/Linux 3.2.0, not stripped
将benchncnn拷贝下来,连同NCNN目录下的param文件。
ncnn/benchmark$ ls
alexnet.param googlenet.param mobilenet_v3.param resnet50_int8.param vgg16_int8.param
benchncnn.cpp mnasnet.param mobilenet_yolo.param resnet50.param vgg16.param
blazeface.param mobilenet_int8.param nanodet_m.param shufflenet.param vision_transformer.param
CMakeLists.txt mobilenet.param proxylessnasnet.param shufflenet_v2.param yolo-fastest-1.1.param
efficientnet_b0.param mobilenet_ssd_int8.param README.md squeezenet_int8.param yolo-fastestv2.param
efficientnetv2_b0.param mobilenet_ssd.param regnety_400m.param squeezenet.param yolov4-tiny.param
FastestDet.param mobilenet_v2.param resnet18_int8.param squeezenet_ssd_int8.param
googlenet_int8.param mobilenetv2_yolov3.param resnet18.param squeezenet_ssd.param
四、测试运行
将benchncnn和param文件全部adb push到板子上。
修改benchncnn的属性,chmod 777 benchncnn
。
然后运行benchncnn,四核ARM A7,跑分还不错。
##感谢阅读##