本来计划基于官方教程(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_TOOLCHAIN_FILE = /media/rv1126/ncnn/toolchains/arm-linux-gnueabihf.toolchain.cmake
-- CMAKE_INSTALL_PREFIX = /media/rv1126/ncnn/build-arm-linux-gnueabihf/install
-- NCNN_VERSION_STRING = 1.0.20221102
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /usr/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /usr/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test NCNN_COMPILER_SUPPORT_ARM_VFPV4
-- Performing Test NCNN_COMPILER_SUPPORT_ARM_VFPV4 - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM_VFPV4_FP16
-- Performing Test NCNN_COMPILER_SUPPORT_ARM_VFPV4_FP16 - Success
-- Performing Test NCNN_COMPILER_SUPPORT_ARM82_FP16
-- Performing Test NCNN_COMPILER_SUPPORT_ARM82_FP16 - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM82_DOTPROD
-- Performing Test NCNN_COMPILER_SUPPORT_ARM82_DOTPROD - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM82_FP16FML
-- Performing Test NCNN_COMPILER_SUPPORT_ARM82_FP16FML - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM84_BF16
-- Performing Test NCNN_COMPILER_SUPPORT_ARM84_BF16 - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM84_I8MM
-- Performing Test NCNN_COMPILER_SUPPORT_ARM84_I8MM - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVE
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVE - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVE2
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVE2 - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVEBF16
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVEBF16 - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVEI8MM
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVEI8MM - Failed
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVEF32MM
-- Performing Test NCNN_COMPILER_SUPPORT_ARM86_SVEF32MM - Failed
CMake Warning at CMakeLists.txt:269 (message):
The compiler does not support armv8.2 fp16. NCNN_ARM82 will be OFF.
-- Target arch: arm
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /media/rv1126/ncnn/build-arm-linux-gnueabihf
然后就是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,跑分还不错。
##感谢阅读##
更多回帖