全志科技在 2021年4月15日釋出了“D1”處理器,是全球首顆搭載平頭哥玄鐵 C906 RISC-V 的應用處理器。同時由其負責開發者社群運營的全資子公司「全志在線」釋出了基於D1晶片的開發板——「哪吒」。D1晶片及開發板為萬物互聯的 AIoT 時代提供了新的可選方案,同時也進一步擴充了 RISC-V 高階應用處理器陣營的力量。
D1晶片簡介
D1開發板「哪吒」
全志在線非常有誠意地公開了開發板的完整原始碼、原理圖、尾號圖和各模組的開發文件等資料,開發者可以基於哪吒開發板做各種AIoT產品的預研和開發。
C906
C906 相容 RV64 架構,且針對算術運算、記憶體訪問等方面進行了增強,同時標配記憶體管理單元,可執行 Linux 作業系統。配有單/雙精度浮點引擎,可進一步選配面向AI加速的向量計算引擎,適用於影片監控、人工智慧等應用領域。
D1開發板&神經網路模型
開放的邊緣 AI 計算框架 Tengine 已經基於平頭哥的 RISC-V Qemu 環境完成了 C910 的 Vector 指令的支援
由於 C910 同 C906 屬於 RV64 的同一系列,指令集相容,因此將 Tengine 移植到 D1 上只需使用 D1 的交叉編譯工具完成“一鍵編譯”即可,Tengine 已經在 v1。4 版本的編譯模組中完成了微調,可無縫切換到對 D1 工具鏈的支援。
工具鏈
版本 riscv64-glibc-gcc-thead_20200702,新增入環境變數後,可見
$ riscv64-unknown-linux-gnu-gcc -v
Using built-in specs。
COLLECT_GCC=riscv64-unknown-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/mnt/d/ubuntu/riscv64-glibc-gcc-thead_20200702/bin/。。/libexec/gcc/riscv64-unknown-linux-gnu/8。1。0/lto-wrapper
Target: riscv64-unknown-linux-gnu
Configured with: /ldhome/software/toolsbuild/slave/workspace/riscv64_build_linux_x86_64/build/。。/source/riscv/riscv-gcc/configure ——target=riscv64-unknown-linux-gnu ——with-mpc=/ldhome/software/toolsbuild/slave/workspace/riscv64_build_linux_x86_64/lib-for-gcc-x86_64-linux/ ——with-mpfr=/ldhome/software/toolsbuild/slave/workspace/riscv64_build_linux_x86_64/lib-for-gcc-x86_64-linux/ ——with-gmp=/ldhome/software/toolsbuild/slave/workspace/riscv64_build_linux_x86_64/lib-for-gcc-x86_64-linux/ ——prefix=/ldhome/software/toolsbuild/slave/workspace/riscv64_build_linux_x86_64/install ——with-sysroot=/ldhome/software/toolsbuild/slave/workspace/riscv64_build_linux_x86_64/install/sysroot ——with-system-zlib ——enable-shared ——enable-tls ——enable-languages=c,c++,fortran ——disable-libmudflap ——disable-libssp ——disable-libquadmath ——disable-nls ——disable-bootstrap ——alt="Tengine支援RISC-V 模型部署-全志在線D1開發板「哪吒」" data-isLoading="0" src="/static/img/blank.gif" data-src=。。/。。/source/riscv/riscv-gcc ——enable-checking=yes ——with-pkgversion=‘C-SKY RISCV Tools V1。8。4 B20200702’ ——enable-multilib ——with-abi=lp64d ——with-arch=rv64gcxthead ‘CFLAGS_FOR_TARGET=-O2 -mcmodel=medany’ ‘CXXFLAGS_FOR_TARGET=-O2 -mcmodel=medany’ CC=gcc CXX=g++
Thread model: posix
gcc version 8。1。0 (C-SKY RISCV Tools V1。8。4 B20200702)
下載並編譯 Tengine D1 版本
$ git clone https://github。com/OAID/Tengine。git tengine-lite
$ cd tengine-lite
$ mkdir build-rv64 && cd build-rv64
$ cmake -DCMAKE_TOOLCHAIN_FILE=。。/toolchains/rv64-c906。toolchain。cmake 。。
$ make && make install
編譯完成後,可在 install 路徑下找到本次演示需要的 libtengine-lite。so 和 tm_classification 物品分類 demo 和 tm_yolofastest 物體檢測 demo:
$ bug1989@DESKTOP-SGN0H2A:/mnt/d/ubuntu/github/tengine-lite-tq/build-riscv$ tree install
install
├── bin
│ ├── tm_classification
│ ├── tm_landmark
│ ├── tm_mobilefacenet
│ ├── tm_mobilenet_ssd
│ ├── tm_retinaface
│ ├── tm_ultraface
│ ├── tm_yolofastest
├── include
│ └── tengine
│ └── c_api。h
└── lib
├── libtengine-lite-static。a
└── libtengine-lite。so
執行
由於我們拿到的 D1 SBC 片上儲存空間有限,需要外擴 SD 卡(不用擔心,插卡即用,自動掛載)。預裝的 Tina Linux 已內建 adb client,可採用 adb shell 進行檔案上傳、下載、控制檯操作。
有個技巧,D1 預裝的系統不支援 RSIC-V 的指令集程式碼執行,需要將工具鏈 sysroot/lib64vxthread 中的庫檔案複製到 D1 根目錄下(這個目前比較麻煩的操作,應該在 D1 後續釋出新的韌體後解決):
將下列檔案透過 adb push 推送到裝置後執行:
root@TinaLinux:/mnt/SDCARD/rv64# 。/tm_classification -m mobilenet。tmfile -i cat。jpg -g 224,224 -s 0。017,0。017,0。017 -r 5
Mean value not specified, use default 104。0, 116。7, 122。7
tengine-lite library version: 1。4-dev
model file : mobilenet。tmfile
image file : cat。jpg
img_h, img_w, scale[3], mean[3] : 224 224 , 0。017 0。017 0。017, 104。0 116。7 122。7
Repeat 2 times, thread 1, avg time 2136。59 ms, max_time 2165。41 ms, min_time 2107。77 ms
————————————————————
8。574153, 282
7。880112, 277
7。812573, 278
7。286447, 263
6。357494, 281
————————————————————
root@TinaLinux:/mnt/SDCARD/rv64# 。/tm_classification -m squeezenet。tmfile -i ca
t。jpg -g 227,227 -r 2
Scale value not specified, use default 1。0, 1。0, 1。0
Mean value not specified, use default 104。0, 116。7, 122。7
tengine-lite library version: 1。4-dev
model file : squeezenet。tmfile
image file : cat。jpg
img_h, img_w, scale[3], mean[3] : 227 227 , 1。000 1。000 1。000, 104。0 116。7 122。7
Repeat 2 times, thread 1, avg time 1354。68 ms, max_time 1383。59 ms, min_time 1325。76 ms
————————————————————
0。273199, 281
0。267553, 282
0。181004, 278
0。081799, 285
0。072406, 151
————————————————————
root@TinaLinux:/mnt/SDCARD/rv64# 。/tm_yolofastest -m yolo-fastest-1。1。tmfile -i
ssd_dog。jpg
tengine-lite library version: 1。4-dev
Repeat 2 times, thread 1, avg time 719。66 ms, max_time 748。44 ms, min_time 690。88 ms
————————————————————
Yolov3DetectionOutput init param[1]
class= 3 score=0。93 left = 454。07,right = 684。29,top = 76。53,bot = 180。31
class=17 score=0。75 left = 121。73,right = 365。81,top = 221。18,bot = 515。53
class= 2 score=0。54 left = 242。91,right = 589。24,top = 187。39,bot = 421。87
class= 3 score=0。53 left = 690。17,right = 728。85,top = 117。04,bot = 154。53
class= 1 score=0。53 left = 64。00,right = 113。62,top = 72。84,bot = 117。60
後記
由於是 Tengine 針對 RV64 指令集的第一個效能最佳化版本,最佳化空間還很大,歡迎對 RISC-V 感興趣的朋友一起來加入,相互學習。
OAID/Tenginegithub。com