Upload
aj0612
View
751
Download
3
Embed Size (px)
Citation preview
感謝SITCON
參加分享的活動
• MOSUT
• 若渴計畫
Motivation
• 研究在寫CUDA程式
• 開放原始碼專案協作 (2014 年暑期)
• 意外獲得板子,要感謝Jserv大大
CUDA
不滿足
偷用一下圖片XD
跟LLVM有什麼關係?
Outline
• 神人寫的GPGPU: Nyuzi processor, 在DE2-115 board執行• github搜尋
• 概說Nyuzi processor特性
• 如何在DE2-115讓Nyuzi processor開始執行
• 在SoCKit board使用Golden System Reference Design (GSRD)• RocketBoards.org組織提供
• 怎麼去做porting
Nyuzi Processor特色-SIMD
• A custom RISC instruction set (load-store architecture)
• 30 general purpose scalar registers
• 32 vector registers, each with 16 lanes
• Instructions are 32-bit fixed length and must be 32-bit aligneddes op2 op1 mask
add_i_mask v1, s2, v2, v3
total number of registers available per block: 65536
我比較大
需透過LLVM-GPGPU來產生machine code
Nyuzi Processor特色
• 同時抓4個指令,切換執行
如何讓Nyuzi processor開始執行?需要手動boot 與載入code
$ jload boot.hex
$ bin/serial_boot program.elf
GPGPU
Niso II
The DE2-115 Board
Ubutun14.04
USB Blaster-JTAG Clock rate: ~60 Mhz
SuperFish
如何實現?
Niso II
The DE2-115 Board
GPGPU
Memory
UART
0
0xffffffff
5. boot.c等待serial_boot.c的command
stack
0x2000
code
JTAG Loader
PC
start.sboot.c stack
0x200000
2. GPGPU reset後從address 0開始執行3. start.s 設定sp = 0x20004. 跳至boot.c
boot.hex
Ubutun14.04
step1 step6 step4
start.s boot.c
$ jload
NyuziProcessor/tools/serial_boot/serial_boot.c
1.
Niso II
The DE2-115 Board
GPGPU
Memory
UART
00xffffffff
NyuziProcessor/tools/serial_boot/serial_boot.c
解譯program.ELF
8. serial_boot.c告知boot.c,code已經搬移結束.跳至start.s
stack
0x2000
code
JTAG Loader
PC
start.sboot.c stack
0x200000
9. 設置PC開始執行,並把sp設置0x200000 (?)
Ubutun14.04
step1 step6 step4
6.告知GPGPU把HEX code 寫至board memory
boot.c
$ bin/serial_boot program.elf
7.收到HEX code寫至board memory
start.s
$ jload boot.hex$ bin/serial_boot program.elf
怎那麼麻煩? (搬code進板子memory)
因為Niso II在納涼(閒置)
在解決這問題之前,先來介紹GSRD
GSRD• 提供開發者有一個Linux
環境可以操作FPGA• Software IP• Linux Driver• File I/O來操作Software IP
• 開發流程概念:• 先有個Image,先run.再針對各部分update
• 細節可參考• Booting Linux Using
Prebuilt SD Card Image• Creating and Updating SD
Card
Linux如何與FPGA溝通?先來看Altera Hard Process System (HPS)
• H2F(Host to FPGA)
• High bandwidth
• Light weight
• F2H (FPGA to HPS system)
• F2S (FPGA-to-HPS SDRAM Interface)
Cyclone V HPS Memory Map
• 在SoCKit版中,Cortex-A9可主動透過H2F傳資料給software IP • LWAXI
• 0xFF200000 ~0xFF3FFFFF(2MB)• HPS2FPGA (high bandwidth)
• 0xC000000開始
Golden Hardware Reference Design (GHRD)
• On-Chip RAM需高頻寬傳輸,控制周邊就不須使用高頻寬
F2HF2S
在SoCKit版中,software IP可透過F2H、F2S主動傳資料到memory與Cortex-A9溝通
如何設計software IP與memory溝通
參考SoCKit Video Server and Video IP (VIP) Reference Design設計
LWAXI
F2H
使用Qsys連接AXI master/slave
Software IP使用Qsys,有這麼簡單@@?
• 必須了解AXI master slave• AMBA AXI and ACE Protocol Specification AXI3, AXI4, and AXI4-Lite, ACE and ACE-Lite• 我不了解,但我會改 Demo AXI Memory Design Example
• Qsys System Design Tutorial
• 注意細節:• 所有AXI master或者slave的pin都要宣告• AXI slave's ID bit width
• If an AXI slave's ID bit width is smaller than required for your system, the AXI slave response might not reach all AXI
• maximum_master_id_width_in_the_interconnect + log2(number_of_masters_in_the_same_interconnect)
• 所以我把Nyuzi Processor製作成Qsys元件
Software IP開發者角度
+0xff20 0000
軟體開發者角度
有了GSRD我們可以怎修改
Qsys會自動產生
LWAXIF2H
自動忽略XD
經過下列步驟,就可以撰寫程式來測試FPGA是否有加成功? Yes, it works.
• Converting .sof to .rbf
• Device tree generation• 給寫driver用的。概念上就是知道I/O的name,就可以透過查詢
Device Tree得到address來操作[跨板子設計]
• Preloader image generation• 會產生出preloader的source code ,所以有些FPGA初始化設定可以在這裡撰寫編譯
• Configure Pinmux• Preloader and U-Boot Customization - v13.1
• Updating SD card
過程與細節可參考我的研究紀錄
這流程是對於GDRD,如果是VIP RD就不行
還記得
Niso II
The DE2-115 Board
GPGPU
Memory
UART
0
0xffffffff
5. boot.c等待serial_boot.c的command
stack
0x2000
code
JTAG Loader
PC
start.sboot.c stack
0x200000
2. GPGPU reset後從address 0開始執行3. start.s 設定sp = 0x20004. 跳至boot.c
boot.hex
Ubutun14.04
step1 step6 step4
start.s boot.c
$ jload
NyuziProcessor/tools/serial_boot/serial_boot.c
1.
Niso II
The DE2-115 Board
GPGPU
Memory
UART
00xffffffff
NyuziProcessor/tools/serial_boot/serial_boot.c
解譯program.ELF
8. serial_boot.c告知boot.c,code已經搬移結束.跳至start.s
stack
0x2000
code
JTAG Loader
PC
start.sboot.c stack
0x200000
9. 設置PC開始執行,並把sp設置0x200000 (?)
Ubutun14.04
step1 step6 step4
6.告知GPGPU把HEX code 寫至board memory
boot.c
$ bin/serial_boot program.elf
7.收到HEX code寫至board memory
start.s
那現在
Cortex-A9
The SoCKit Board
GPGPU
Memory
0 0xffffffff
stackcode
PC
Ubutun14.04
LINUX
HPS
SD card
Program.hex produced by elf2hex
LWAXI
step 1
step 2
F2H
LWAXI
F2H
1. 透過Linux宣告code空間,並設置code base address、stack address(?)
2. cortex-A9從SD card搬code至指定memory3. 透過cortex-A9來控制GPGPU RESET signal(?)
Address data
0xFF200000 RESET
0xFF200004 Code base address
0xFF200008 Stack address(*highest* stack)
0xFF20000C Heap address
0xFF200010 Frame address
差在哪?搬code透過Cortex-a9來搬,且從SD card到memory
Cortex-A9
The SoCKit Board
GPGPU
Memory
0 0xffffffff
stackcode
PC
Ubutun14.04
LINUX
HPS
SD card
Program.hex produced by elf2hex
LWAXI
1. 透過Linux宣告code空間,並設置code base address、stack address(?)
2. cortex-A9從SD card搬code至指定memory3. 透過cortex-A9來控制GPGPU RESET signal(?)
step 1
step 2
LWAXI
F2H 主動
Address data
0xFF200000 RESET
0xFF200004 Code base address
0xFF200008 Stack address(*highest* stack)
0xFF20000C Heap address
0xFF200010 Frame address
PC
step 3
• 設計了memory I/O
• 你想要存取0xff200000你需要使用mmap• fd = open(“/dev/mem”,..)
• used_ptr = mmap(..,fd,0xff200000)
• 透過LWAXI設定GPGPU的初始狀態, 且GPGPU透過F2H主動抓code來執行• 透過LWAXI設定Reset signal
上圖work之後的幾個概念整理
boot.hex
• How to build
• Elf2hex is as a loader• Tutorial: Creating an LLVM Backend for the Cpu0 Architecture
LLVM-nyuzi is built to the target
Cortex-A9
The SoCKit Board
LINUX
HPS
SD card
ld.mcld
llvm-ar
elf2hex
clang
.s, .c, .cpp .o
.a.o
.elf
.hex
.hex
整個流程打通之後, 越來越像…..
實現CPU/GPU無縫切換運算,HSA催生下世代處理器 CUDA LLVM Compiler
有興趣email給我, 因為還很多還沒做XDAJ (張仁傑)
最近跑去研究Xvisor在ARMv8-A
Q&A我不是神人, 所以如果有問題我當下沒辦法回答,
我會記錄下來並更新在此投影片上