Transcript
Page 1: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Linux Runs on the SoCKitBoard with the GPGPU

AJ (張仁傑)<[email protected]>

2015.1.31

Page 2: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Outline

• Nyuzi processor

• Global System Reference Design (GSRD)

Page 3: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

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

Page 4: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Nyuzi Processor特色

• 同時抓4個指令,切換執行

Page 5: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

對Nyuzi processor看法:如果在Nyuzi processor上面加上OS,context switch感覺是個悲劇不過作者為了3D render,有在上面實作一個小型OS來切換(?)

Page 6: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

如何讓Nyuzi processor開始執行,需要手動boot 與載入code

Page 7: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

$ jload boot.hex

$ bin/serial_boot program.elf

GPGPU

Niso II

The DE2-115 Board

Ubutun14.10

USB Blaster-JTAG Clock rate: ~60 Mhz

Page 8: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

如何實現?

Page 9: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Niso II

The DE2-115 Board

GPGPU

Memory

UART

00xffffffff

serial_boot.c

解譯program.ELF

4. boot.c等待serial_boot.c的command並開始寫入hex code至memory

5. serial_boot.c告知boot.c,code已經搬移結束.跳至start.s

stack

0x2000

code

JTAG Loader

PC

start.sboot.c stack

0x200000

1. GPGPU reset後從address 0開始執行

2. start.s 設定sp = 0x20003. 跳至boot.c

6. 設置PC開始執行,並把sp設置0x200000 (?)

boot.hex

Ubutun14.10

step1 step6 step4

告知GPGPU把HEX code 寫至board memory

start.s boot.c

Page 10: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

$ jload boot.hex$ bin/serial_boot program.elf

怎那麼麻煩?

作者沒有在板子上使用OS(提供服務)

Page 11: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

我們有什麼?

• 硬體: the SoCKit board

• RocketBoards.org組織提供的GSRD 14.1 for the SoCKit board

我怎會有這個板子?• 開放原始碼專案協作 (2014 年暑期)

Page 12: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

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

Page 13: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

來看Altera Hard Process System (HPS)

Page 14: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

• H2F

• High bandwidth

• Light weight

• F2H (FPGA to HPS system)

• F2S (FPGA-to-HPS SDRAM Interface)

Page 15: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Cyclone V HPS Memory Map

• 在SoCKit版中,Cortex-A9可主動透過H2F傳資料給software IP • LWAXI

• 0xFF200000 ~0xFF3FFFFF(2MB)• HPS2FPGA (high bandwidth)

• 0xC000000開始

Page 16: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Golden Hardware Reference Design (GHRD)

• On-Chip RAM需高頻寬傳輸,控制周邊就不須使用高頻寬

Page 17: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

F2HF2S

在SoCKit版中,software IP可透過F2H、F2S主動傳資料到memory與Cortex-A9溝通

Page 18: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

如何設計software IP與memory溝通

Page 19: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

參考SoCKit Video Server and Video IP (VIP) Reference Design設計

LWAXI

F2H

使用Qsys連接AXI master/slave

Page 20: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

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元件

Page 21: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Software IP開發者角度

+0xff20 0000

軟體開發者角度

Page 22: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

有了GSRD我們可以怎修改

Qsys會自動產生

LWAXIF2H

自動忽略XD

Page 23: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU
Page 24: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

經過下列步驟,就可以撰寫程式來測試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

過程與細節可參考我的研究紀錄

Page 25: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

這流程是對於GDRD,如果是VIP RD就不行

Page 26: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Niso II

The DE2-115 Board

GPGPU

Memory

UART

00xffffffff

serial_boot.c

解譯program.ELF

4. boot.c等待serial_boot.c的command並開始寫入hex code至memory

5. serial_boot.c告知boot.c,code已經搬移結束.跳至start.s

stack

0x2000

code

JTAG Loader

PC

start.sboot.c stack

0x200000

1. GPGPU reset後從address 0開始執行

2. start.s 設定sp = 0x20003. 跳至boot.c

6. 設置PC開始執行,並把sp設置0x200000 (?)

boot.hex

Ubutun14.04

step1 step6 step4

告知GPGPU把HEX code 寫至board memory

start.s boot.c

Page 27: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Cortex-A9

The SoCKit Board

GPGPU

Memory

0 0xffffffff

stackcode

PC

Ubutun14.04

LINUX

HPS

SD card

Program.hex produced by elf2hex

LWAXI

Address data

0xFF200000 RESET

0xFF200004 Code base address

0xFF200008 Stack address(*highest* stack)

0xFF20000C Heap address

0xFF200010 Frame address

1. 透過Linux宣告code空間,並設置code base address、stack address• fd = open(“/dev/mem”,..)• used_ptr = mmap(..,fd,0xff200000)

2. cortex-A9從SD card搬code至指定memory3. 透過cortex-A9來控制GPGPU RESET signal

step 1

step 2

F2H

LWAXI

F2H

Page 28: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

boot.hex

• How to build

• Elf2hex is as a loader

• Tutorial: Creating an LLVM Backend for the Cpu0 Architecture

Page 29: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

LLVM-nyuzi is built to the target

Page 30: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

Cortex-A9

The Sockit Board

LINUX

HPS

SD card

ld.mcld

llvm-ar

elf2hex

clang

.s, .c, .cpp .o

.a.o

.elf

.hex

.hex

Page 31: [MOSUT20150131] Linux Runs on SoCKit Board with the GPGPU

整個流程打通之後,越來越像…..

實現CPU/GPU無縫切換運算,HSA催生下世代處理器 CUDA LLVM Compiler