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

在树莓派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.txt306-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.

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

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

Done

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值