- 構建可用的環境
由於瑞芯微提供的bsp中的內核版本為4.4,所以各個開發板的廠家提供的長期維護的內核版本也是4.4,
在5.3.x的環境下只是跑起來了opengl 但是opencl始終無法運行起來,
因為手里面只有rockpi4b的板子,rockpi目前沒有找到支持opencl的系統,我在網上找到了firefly的ubuntu18.04的系統,這個系統已經移植好了opencl1.2,可以直接使用,
只是后面想進行一些個性化的更改可能會受限,不過目前可以用於進行一些測試
如下在上面進行了glmark2的測試,
opencl1.2也顯示是可用的
- 部署 Tengine AI 框架(GPU)
Tengine的編譯看
這里
編譯Tengine with ACL
Tengine是通過調用Arm Compute Library(ACL)進行GPU加速。
首先編譯ACL
#編譯ACL
root@firefly:/home/gpu# git clone https://github.com/ARM-software/ComputeLibrary.git
#切換19.02分支
root@firefly:/home/gpu/ComputeLibrary# git checkout -b v19.02 v19.02
#編譯
scons Werror=1 -j4 debug=0 asserts=0 neon=0 opencl=1 embed_kernels=1 os=linux arch=arm64-v8a
然后在Tengine中使能ACL
#修改default/arm64_linux_native.config文件
root@firefly:/home/gpu/tengine# vi default_config/arm64_linux_native.config
#The following option is used for building acl or not. [y/n]
#option value [y/n]
BUILD_ACL=y
#The following option are used for setting acl only if turning on the BUILD_ACL option
ACL_ROOT=/home/gpu/ComputeLibrary
#注意ACL的路徑
#執行編譯
root@firefly:/home/gpu/tengine# ./linux_build.sh default_config/arm64_linux_native.config
測試!
首先來看一下沒有GPU的情況下,tengine默認使用的是2*A72的大核進行測試的,以mobilenet_ssd的模型進行測試
可以看到CPU的占用情況,以及執行50次的平均耗時為170.881ms
然后以GPU+1*A53的情況下進行測試
#設置gpu的頻率未固定的最大值
root@firefly:/home/gpu/tengine/examples/build# echo "performance" > /sys/devices/platform/ff9a0000.gpu/devfreq/ff9a0000.gpu/governor
#查看一下
root@firefly:/home/gpu/tengine/examples/build# cat /sys/devices/platform/ff9a0000.gpu/devfreq/ff9a0000.gpu/cur_freq
800000000
root@firefly:/home/gpu/tengine/examples/build#
# disable gpu run concat, avoid frequent data transfer between cpu and gpu
root@firefly:/home/gpu/tengine/examples/build# export GPU_CONCAT=0
# enable gpu fp16
root@firefly:/home/gpu/tengine/examples/build# export ACL_FP16=1
# repeat count to run mssd, get avg time
root@firefly:/home/gpu/tengine/examples/build# export REPEAT_COUNT=50
# run acl graph on NHWC layout
root@firefly:/home/gpu/tengine/examples/build# export ACL_NHWC=1
#把opencl的系統庫添加到系統環境中
root@firefly:/home/gpu/tengine/install/lib# export LD_LIBRARY_PATH=/home/gpu/tengine/install/lib/
#執行 -d acl_opencl to use gpu, taskset 0x1 to bind CPU0(A53)
root@firefly:/home/gpu/tengine/examples/build# taskset 0x1 ./mobilenet_ssd/MSSD -d acl_opencl