天天看点

树莓派4B(RPI 4B) 编译NCNN - Ubuntu(x64)在树莓派4B-Ubuntu上编译NCNNDone

在树莓派4B-Ubuntu上编译NCNN

官方文档安装教程

需要的一些环境

git
g++
cmake
protocol buffer (protobuf) headers files and protobuf compiler
vulkan header files and loader library
glslang
(可选) opencv # 用于编译测试用例
           

用以下命令安装以下一些依赖包:

sudo apt install build-essential git cmake libprotobuf-dev protobuf-compiler libvulkan-dev vulkan-utils libopencv-dev
           

如果需要装vulkan支持,请自行阅读文档部分内容。文档内有部分描述,目前vulkan在树莓派上的驱动还不完善,但是作者提到仍然是可用的,读者可自行尝试。

$ cd ncnn
$ mkdir -p build
$ cd build                                          # ↓从ON改成OFF了
build$ cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_VULKAN=OFF -DNCNN_SYSTEM_GLSLANG=ON -DNCNN_BUILD_EXAMPLES=ON -DCMAKE_TOOLCHAIN_FILE=../toolchains/jetson.toolchain.cmake ..
build$ make -j$(nproc)
           

../src/CMakeLists.txt

306-309

行做一些修改:

if(PI3)                                                # ↓后面注释掉                                                                                                    	
	target_compile_options(ncnn PRIVATE -march=native) #-mfpu=neon -mfloat-abi=hard)
	target_compile_definitions(ncnn PRIVATE __ARM_NEON __ANDROID__)
endif()
           

否则会出现如下错误:

g++: error: unrecognized command line option ‘-mfpu=neon’
g++: error: unrecognized command line option ‘-mfpu=neon’
g++: error: unrecognized command line option ‘-mfloat-abi=hard’
           

原因很简单,因为当前安装的是64位的系统,默认就是neon和硬浮点,官方安装文档貌似是32位系统为前提。

详情参考stackoverflow。

以下摘自:https://stackoverflow.com/a/29891469

Advanced SIMD (aka NEON) is mandatory for AArch64, so no command line option is needed to instruct the compiler to use NEON.

If you want to enable auto vectorization optimisations so that the compiler automatically uses NEON instructions, then compile with -O3 or -O2 -ftree-vectorize.

The AArch64 and ARM backends are completely separate in gcc. The ARM back end only targets the traditional 32 bit ARM instructions sets (ARM, Thumb, Thumb-2). This is in contrast to the situation with x86, where the 32 bit and 64 bit code generation is combined into a single GCC back end.

最后跑一下测试,结果如下图所示:

树莓派4B(RPI 4B) 编译NCNN - Ubuntu(x64)在树莓派4B-Ubuntu上编译NCNNDone

总的来看速度很可以,yolov4-tiny也能跑到4fps。

Done

继续阅读