pycoram (高位合成友の会@ドワンゴ, 2015年1月16日)

52
PyCoRAM 高前田(山崎) 伸也 (@shtaxxx) 奈良先端科学技術大学院大学 情報科学研究科 E-mail: shinya_at_is_naist_jp 201511621:00-21:30 高位合成友の会@ドワンゴ #fpgax

Upload: shinya-takamaeda-yamazaki

Post on 17-Jul-2015

1.228 views

Category:

Technology


7 download

TRANSCRIPT

Page 1: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAM

高前田(山崎) 伸也 (@shtaxxx)

奈良先端科学技術大学院大学 情報科学研究科

E-mail: shinya_at_is_naist_jp

2015年1月16日 21:00-21:30 高位合成友の会@ドワンゴ #fpgax

Page 2: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

研究分野

n コンピュータアーキテクチャ l プロセッサアーキテクチャ

•  メモリシステム・ニアデータプロセッシング

l プロセッサシミュレーション •  メニーコアCPUの高速シミュレーション・プロトタイピング

•  プロトタイピングのFPGA抽象化フレームワーク (flipSyrup)

l  FPGAコンピューティング •  FPGA向け高位合成コンパイラ・フレームワーク (PyCoRAM)

2015-01-16 Shinya T-Y, NAIST 2

Page 3: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

今日の話: PyCoRAMについて n 高位合成技術とメモリシステム抽象化を用いた アクセラレータIPコア開発のためのフレームワーク l キーワード: FPGAアクセラレータ・IPコア設計・Python-Verilog高位合成・メモリシステム抽象化・AXI4インターコネクト

PyCoRAM IP User I/O

User Logic

CoRAM Channel

CoRAM Register

Control Thread

Master DMAC

CoRAM Memory

Master DMAC

CoRAM Stream

FSM

GPIO

Slave DMAC

CoRAM IoChannel

Modeled in RTL (Verilog HDL)

Memory Access Pattern

in Python

2015-01-16 Shinya T-Y, NAIST 3

Page 4: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAM and Pyverilog are available! n PyCoRAM

l https://pypi.python.org/pypi/pycoram l http://shtaxxx.github.io/PyCoRAM/

n Pyverilog l https://pypi.python.org/pypi/pyverilog l http://shtaxxx.github.io/Pyverilog/

$ pip install pyverilog�$ pip install pycoram�

2015-01-16 Shinya T-Y, NAIST 4

Page 5: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

はじめに

2015-01-16 Shinya T-Y, NAIST 5

Page 6: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

Digilent Atlys FPGA: Xilinx Spartan-6 LX45 Size: Pipelined CPU ×4 Price: 20,000yen (Academic)

Digilent ZedBoard FPGA: Xilinx Zynq-7020 Size: Pipelined CPU ×8 (+ ARM DualCore) Price: 50,000yen (Academic)

2015-01-16 Shinya T-Y, NAIST 6

Page 7: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

ScalableCore System FPGA: Xilinx Spartan-6 ×100 Size: Pipelined CPU x200? Price: 1,000,000yen?

2015-01-16 Shinya T-Y, NAIST 7

Page 8: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

アプリケーションのポータビリティ n どうやって様々なプラットフォームをサポートするか?

l プラットフォーム毎に特性が違うL •  ロジックサイズ・メモリサイズ・ メモリインターフェース・I/O・・・

Digilent Atlys (Xilinx Spartan-6 LX45)

Xilinx ML605 (Xilinx Virtex-6 LX240T)

ScalableCore System (our FPGA system) (Xilinx Spartan-6 LX16 × 128-node)

2015-01-16 Shinya T-Y, NAIST 8

Page 9: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

IPコアベースのシステム開発 n  IPコアを開発・追加して繋げばシステム完成J

l 標準的なインターコネクトでIPコア達を接続

l  EDAツールが自動的にインターコネクトと(いくつかの) デバイス依存のインターフェースを生成してくれるから楽ちん

Xilinx Platform Studio (XPS)

IP-core List

Interconnect

FPGA

CPU HW Acc

DRAM I/F Ether PCI-E

Interconnect

HW Acc

DRAM

IP-core Instances

2015-01-16 Shinya T-Y, NAIST 9

Page 10: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

どうやってアクセラレータIPを実装するか? n 普通にHDLでアクセラレータを実装するのは大変

l 演算とメモリアクセスのスケジューリングロジック •  ダブルバッファリングとか面倒

l メモリシステムの制御回路 •  HDLでステートマシンを書くのは面倒だし間違えやすい

l デバッグが面倒

n パイプラインの振る舞いはサイクルレベルで定義したい l  FPGAで性能を出すには高稼働率のパイプラインが重要

•  だから計算ロジックはHDLで書きたい

•  (OSSな)高位合成系だとチューンがイマイチ難しい(?)

n データ転送を抽象化すれば幸せ?

CoRAMメモリアーキテクチャ 2015-01-16 Shinya T-Y, NAIST 10

Page 11: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAM

2015-01-16 Shinya T-Y, NAIST 11

Page 12: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

CoRAM [Chung+,FPGA’11] n  FPGAアクセラレータのためのメモリ抽象化

l 高位モデルによるメモリ管理でアクセラレータをポータブルに •  計算カーネルとメモリアクセスの分離

•  ソフトウェアのモデルによるメモリアクセスパターンの記述

HW Kernels (Computing Logics)

CoR

AM

M

emor

y

Read Write

Manage

Control Threads (Memory Access

Pattern)

CoRAM Channel

Read/Write Read/Write

Communication FIFOs (Registers)

Abstracted On-chip Memories

Off-chip Memory

2015-01-16 Shinya T-Y, NAIST 12

Page 13: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAM [Takamaeda+,CARL’13]: CoRAM for Modern EDKs n  CoRAMのメモリ抽象化を今時のEDKで使いたい

l 標準的なインターコネクト(AXI4/Avalon)に繋ぎたい

l そうすれば他の普通のIPコアとも簡単に共存できそう

Standard On-chip Interconnect

CoRAM Abstraction

Accelerator logic Standard IP-core

Device-dependent Interfaces

CPU core

Portable application design with CoRAM Cooperation with standard IP-cores

2015-01-16 Shinya T-Y, NAIST 13

Page 14: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMマイクロアーキテクチャ PyCoRAM IP

User I/O

User Logic

CoRAM Channel

CoRAM Register

Control Thread

Master DMAC

CoRAM Memory

Master DMAC

CoRAM Stream

FSM

GPIO

Slave DMAC

CoRAM IoChannel

2015-01-16 Shinya T-Y, NAIST 14

Page 15: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAM IP User I/O

User Logic

CoRAM Channel

CoRAM Register

Control Thread

Master DMAC

CoRAM Memory

Master DMAC

CoRAM Stream

FSM

GPIO

Slave DMAC

CoRAM IoChannel

PyCoRAMマイクロアーキテクチャ

Modeled in RTL (Verilog HDL)

Memory Access Pattern

in Python

2015-01-16 Shinya T-Y, NAIST 15

Page 16: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMマイクロアーキテクチャの実装 PyCoRAM IP

Interconnect (AXI4/Avalon)

DRAM Controller FPGA

User I/O

User Logic

CoRAM Channel

CoRAM Register

Control Thread

Master DMAC

Master I/F

CoRAM Memory

Master DMAC

Master I/F

CoRAM Stream

Slave I/F

FSM

GPIO

Slave DMAC

CoRAM IoChannel

2015-01-16 Shinya T-Y, NAIST 16

Page 17: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMマイクロアーキテクチャの実装 PyCoRAM IP

Interconnect (AXI4/Avalon)

DRAM Controller FPGA

User I/O

User Logic

CoRAM Channel

CoRAM Register

Control Thread

Master DMAC

Master I/F

CoRAM Memory

Master DMAC

Master I/F

CoRAM Stream

Slave I/F

FSM

GPIO

Slave DMAC

CoRAM IoChannel Master:

メモリ等へ能動的にアクセス

Slave: プロセッサ等から読み書きされる

2015-01-16 Shinya T-Y, NAIST 17

Page 18: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMにおける開発フロー n 計算カーネルのRTLとPythonでのコントロールスレッド記述からIPコアパッケージを生成 l 生成されたIPコアは通常のEDAフローで利用可能

User-logic (Verilog HDL)

Control Threads (Python)

Logic Hierarchy Analysis

Python-to-Verilog

Compilation

Control Signal

Insertion IP-core Packing

(RTL, .mpd, and

.pao)

IP-core Integration

on EDK

Synthesis Control

Signal Port Addition

FPGA Bit File

Portable Application

Design

PyCoRAM Tool-chain Vendor EDA Flow Python-to-Verilog HLS

RTL Conversion IP-core

generation with AXI4 Interface

Top design synthesis with

AXI4

2015-01-16 Shinya T-Y, NAIST 18

Page 19: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMの使い方

2015-01-16 Shinya T-Y, NAIST 19

Page 20: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMにおけるIPコアの作り方・でき方 n  2種類のファイルを用意する

l  Verilog HDL: 計算ロジック

l  Python: コントロールスレッド(メモリアクセスパターン)

n  PyCoRAMが自動的にIPコアのパッケージを作成 l  Python-Verilog高位合成とRTL変換を自動で行う

CoramMemory1P�#(� .CORAM_THREAD_NAME("thread_name"),� .CORAM_ID(0),� .CORAM_ADDR_LEN(ADDR_LEN),� .CORAM_DATA_WIDTH(DATA_WIDTH)� )�inst_memory�(.CLK(CLK),� .ADDR(mem_addr),� .D(mem_d),� .WE(mem_we),� .Q(mem_q)� );�

def calc_sum(times):� ram = CoramMemory(idx=0, datawidth=32, size=1024)� channel = CoramChannel(idx=0, datawidth=32)� addr = 0� sum = 0� for i in range(times):� ram.write(0, addr, 128)� channel.write(addr)� sum += channel.read()� addr += 128 * (32/8)� print(‘sum=’, sum)�calc_sum(8)�

2015-01-16 Shinya T-Y, NAIST 20

Page 21: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

計算ロジックにおけるCoRAMオブジェクト n  CoRAMオブジェクトはブロックRAMやFIFOとして扱う

l 一般的なメモリとよく似たインターフェース •  CoRAMと外部を接続するインターフェースは自動的に追加される

l いくつかのパラメータで特性を指定 •  スレッド名,ID,データ幅,アドレス幅,スキャッターギャザー等

CoramMemory1P�#(� .CORAM_THREAD_NAME("thread_name"),� .CORAM_ID(0),� .CORAM_ADDR_LEN(ADDR_LEN),� .CORAM_DATA_WIDTH(DATA_WIDTH)� )�inst_memory�(.CLK(CLK),� .ADDR(mem_addr),� .D(mem_d),� .WE(mem_we),� .Q(mem_q)� );�

(a) CoRAM Memory

CoramChannel�#(� .CORAM_THREAD_NAME("thread_name"),� .CORAM_ID(0),� .CORAM_ADDR_LEN(CHANNEL_ADDR_LEN),� .CORAM_DATA_WIDTH(CHANNEL_DATA_WIDTH)� )�inst_channel�(.CLK(CLK),� .RST(RST),� .D(comm_d),� .ENQ(comm_enq),� .FULL(comm_full),� .Q(comm_q),� .DEQ(comm_deq),� .EMPTY(comm_empty)� );�

(b) CoRAM Channel 2015-01-16 Shinya T-Y, NAIST 21

Page 22: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

Pythonによるコントロールスレッド n  CoRAMオブジェクトに対する処理を記述する

l  CoRAMメモリ(read/write) •  オンチップCoRAMメモリとオフチップDRAM との間のDMA転送によるデータ移動

l  CoRAMチャネル(read/write) •  ユーザロジックとコントロールスレッド との間のトークンのやりとり

def calc_sum(times):� ram = CoramMemory(idx=0, datawidth=32, size=1024)� channel = CoramChannel(idx=0, datawidth=32)� addr = 0� sum = 0� for i in range(times):� ram.write(0, addr, 128)� channel.write(addr)� sum += channel.read()� addr += 128 * (32/8)� print(‘sum=’, sum)�calc_sum(8)�

# Transfer (off-chip DRAM to BRAM) # Notification to User-logic # Wait for Notification from User-logic # $display Verilog system task �

User I/O

User Logic

CoRAM Channel

Control Thread

DMAC

CoRAM Memory FSM

0�1�2�3�4�5�6�7�8�9�10�11�

2015-01-16 Shinya T-Y, NAIST 22

Page 23: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

例: 配列の和を求めるアクセラレータ n  1-CoRAM+1-Threadの簡単なハードウェア

l  CoRAMメモリにDRAM(など)からデータを読み込む

l コントロールスレッドでオンチップ-オフチップ間のデータ転送パターンを表現

Computing Logic (Verilog HDL)

Control Thread

(Python) sum

CoRAM Memory 0

+

Control Logic CoRAM Channel 0

A

2015-01-16 Shinya T-Y, NAIST 23

Page 24: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

計算ロジック (1): I/Oポート

クロック(CLK)とリセット(RST) 以外に専用のI/Oは不要

CoRAMメモリのための信号 (BRAMと同じインターフェース)

CoRAMチャネルのための信号 (FIFOと同じインターフェース)

ステートマシン用変数

2015-01-16 Shinya T-Y, NAIST 24

Page 25: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

計算ロジック (2): パイプライン/FSM

CoRAMチャネルに書き込み (コントロールスレッドに通知)

CoRAMチャネルから読み出し (コントロールスレッドから受信)

2015-01-16 Shinya T-Y, NAIST 25

Page 26: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

計算ロジック (3): 子インスタンス CoRAMメモリ

(BRAMと同じインターフェース)

CoRAMチャネル (FIFOと同じインターフェース)

2015-01-16 Shinya T-Y, NAIST 26

Page 27: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

コントロールスレッド (Python)

ram (CoRAMメモリ)とchannel (CoRAMチャネル)の宣言

CoRAMメモリにDMA転送したり CoRAMチャネルから読んだり書いたり

2015-01-16 Shinya T-Y, NAIST 27

Page 28: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

コンパイル

2015-01-16 Shinya T-Y, NAIST 28

Page 29: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

シミュレーション結果

2015-01-16 Shinya T-Y, NAIST 29

Page 30: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

シミュレーション結果(波形)

2015-01-16 Shinya T-Y, NAIST 30

Page 31: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

サポートされているPyCoRAMオブジェクト

n  データ置き場(メモリ・ストリーム) l  CoramMemory

•  Block RAM that the data is replaced by the control thread

l  CoramInStream •  Input FIFO from off-chip DRAM

l  CoramOutStream •  Output FIFO to off-chip DRAM

n  ユーザロジックとコンロールスレッド間のチャネル l  CoramChannel

•  FIFO between user-logic and control-thread

l  CoramRegister •  Latch between user-logic and control-thread

n  他のIPコア・プロセッサからアクセスできるスレーブチャネル l  CoramIoChannel

•  (AXI4/Avalon) Slave interface

2015-01-16 Shinya T-Y, NAIST 31

Page 32: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

応用その1 行列積・ステンシル計算 アクセラレータ

2015-01-16 Shinya T-Y, NAIST 32

Page 33: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

行列積・ステンシルアクセラレータ n  PyCoRAMでIPコア2種を実装

l  MicroblazeからはAXI4スレーブ経由でメモリマップドI/Oで制御

Matrix-Mult Accelerator

CoRAM Abstraction

MM Logic

Cthread MM

UART Loader

CoRAM Abstraction

UART Loader Logic

Control Thread

Microblaze 5-stage

32KB Local memory 8KB D-Cache

AXI4 Interconnect (128-bit, Crossbar)

DRAM Controller (DDR2-800 16-bit (1.6GB/s))

exStick

FPGA (Spartan-6 LX45)

DRAM (128MB)

Stencil Accelerator

CoRAM Abstraction

Stencil Logic

Cthread Stencil

AXI4-lite Interconnect (32-bit, Shared bus)

2015-01-16 Shinya T-Y, NAIST 33

Page 34: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

行列積アクセラレータIPコア n 行列A・B・Cの各行をCoRAMメモリに格納

l  DRAMとの間のデータ転送をコントロールスレッドが担当

l 毎サイクル乗算パイプラインにデータを投入

l 行列Bの転送と演算をダブルバッファリング

l  SIMD幅をメモリバンド幅を使い切るようにチューニング

Computing Logic (Verilog HDL) Control Thread

(Python)

sum

CoRAM Memory 0

B × +

CoRAM Memory 1

CoRAM Memory 2

Control Logic CoRAM Channel 0

8-stage Multiply Pipeline A

C

check sum +

I/O Channel

2015-01-16 Shinya T-Y, NAIST 34

Page 35: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

応用その1 グラフ処理 アクセラレータ

2015-01-16 Shinya T-Y, NAIST 35

Page 36: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

ダイクストラアクセラレータ n ホストからUART経由で制御・グラフ構築にMicroblaze

Dijkstra Accelerator

CoRAM Abstraction

Read Node

CThread

Dijkstra Logic

Read Node

Read Edge

Update Node

Mark Visited

Read Edge

CThread

Update Node

CThread

Mark Visited

CThread

Main Control Tread

Priority Queue

Priority Queue

CThread

UART Loader

CoRAM Abstraction

UART Loader Logic

Control Thread

Microblaze 3-stage

16KB Local memory 2KB I-Cache 2KB D-Cache

AXI4 Interconnect (128-bit, Crossbar)

DRAM Controller (DDR2-800 16-bit (1.6GB/s))

AXI4-lite Interconnect (32-bit, Shared bus)

Host PC

FPGA (Spartan-6 LX45)

DRAM (128MB) 2015-01-16 Shinya T-Y, NAIST 36

Page 37: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMを用いたダイクストラIPコア n  PyCoRAMを使って演算モジュールはVerilog HDLで実装 メモリアクセス制御はPythonで実装

Read Node

InStream

Read Edge

InStream

Update Node

OutStream

Mark Visited

OutStream

Priority Queue

InStream OutStream Edge Page Addr

Cost

+

Next Node Addr

Node Addr

Next Node Cost

Node Addr Next Node Addr

Next Node Cost

FSM

DMAC DMAC DMAC DMAC DMAC DMAC Slave I/F

AXI4 Master Interfaces AXI4-lite

Slave Interfaces

Dijkstra Logic

(Modeled in Verilog HDL)

Mark Visited Cthread

Read Node Cthread

Read Edge Cthread Priority Queue Cthread Mark Visited

Cthread Main

CThread

Control Threads (Modeled in Python)

Use

r Def

initi

on (M

odel

ed in

Ver

ilog

HD

L an

d P

ytho

n)

Gen

erat

ed b

y

PyC

oRA

M

2015-01-16 Shinya T-Y, NAIST 37

Page 38: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMを用いたダイクストラIPコア n ステージ1: 最小コストノード取り出し

Read Node

InStream

Read Edge

InStream

Update Node

OutStream

Mark Visited

OutStream

Priority Queue

InStream OutStream Edge Page Addr

Cost

+

Next Node Addr

Node Addr

Next Node Cost

Node Addr Next Node Addr

Next Node Cost

FSM

DMAC DMAC DMAC DMAC DMAC DMAC Slave I/F

AXI4 Master Interfaces AXI4-lite

Slave Interfaces

Dijkstra Logic

(Modeled in Verilog HDL)

Mark Visited Cthread

Read Node Cthread

Read Edge Cthread Priority Queue Cthread Mark Visited

Cthread Main

CThread

Control Threads (Modeled in Python)

Use

r Def

initi

on (M

odel

ed in

Ver

ilog

HD

L an

d P

ytho

n)

Gen

erat

ed b

y

PyC

oRA

M

2015-01-16 Shinya T-Y, NAIST 38

Page 39: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMを用いたダイクストラIPコア n ステージ2:ノード情報読み出し

Read Node

InStream

Read Edge

InStream

Update Node

OutStream

Mark Visited

OutStream

Priority Queue

InStream OutStream Edge Page Addr

Cost

+

Next Node Addr

Node Addr

Next Node Cost

Node Addr Next Node Addr

Next Node Cost

FSM

DMAC DMAC DMAC DMAC DMAC DMAC Slave I/F

AXI4 Master Interfaces AXI4-lite

Slave Interfaces

Dijkstra Logic

(Modeled in Verilog HDL)

Mark Visited Cthread

Read Node Cthread

Read Edge Cthread Priority Queue Cthread Mark Visited

Cthread Main

CThread

Control Threads (Modeled in Python)

Use

r Def

initi

on (M

odel

ed in

Ver

ilog

HD

L an

d P

ytho

n)

Gen

erat

ed b

y

PyC

oRA

M

2015-01-16 Shinya T-Y, NAIST 39

Page 40: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMを用いたダイクストラIPコア n ステージ3:ノードに訪問済みフラグ書き込み

Read Node

InStream

Read Edge

InStream

Update Node

OutStream

Mark Visited

OutStream

Priority Queue

InStream OutStream Edge Page Addr

Cost

+

Next Node Addr

Node Addr

Next Node Cost

Node Addr Next Node Addr

Next Node Cost

FSM

DMAC DMAC DMAC DMAC DMAC DMAC Slave I/F

AXI4 Master Interfaces AXI4-lite

Slave Interfaces

Dijkstra Logic

(Modeled in Verilog HDL)

Mark Visited Cthread

Read Node Cthread

Read Edge Cthread Priority Queue Cthread Mark Visited

Cthread Main

CThread

Control Threads (Modeled in Python)

Use

r Def

initi

on (M

odel

ed in

Ver

ilog

HD

L an

d P

ytho

n)

Gen

erat

ed b

y

PyC

oRA

M

2015-01-16 Shinya T-Y, NAIST 40

Page 41: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyCoRAMを用いたダイクストラIPコア n パイプライン動作:(1)エッジ読み出し→ (2)隣接ノード読み出し→(3)隣接ノード更新

Read Node

InStream

Read Edge

InStream

Update Node

OutStream

Mark Visited

OutStream

Priority Queue

InStream OutStream Edge Page Addr

Cost

+

Next Node Addr

Node Addr

Next Node Cost

Node Addr Next Node Addr

Next Node Cost

FSM

DMAC DMAC DMAC DMAC DMAC DMAC Slave I/F

AXI4 Master Interfaces AXI4-lite

Slave Interfaces

Dijkstra Logic

(Modeled in Verilog HDL)

Mark Visited Cthread

Read Node Cthread

Read Edge Cthread Priority Queue Cthread Mark Visited

Cthread Main

CThread

Control Threads (Modeled in Python)

Use

r Def

initi

on (M

odel

ed in

Ver

ilog

HD

L an

d P

ytho

n)

Gen

erat

ed b

y

PyC

oRA

M

1 2 3

2015-01-16 Shinya T-Y, NAIST 41

Page 42: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

実行時間 n  FPGA上の実装は汎用PCと比べて25倍程度低速L

l メモリバンド幅あたりの性能でも1.5倍程度悪い・・・ l なぜか?

•  データセットが小さい・OoOプロセッサのMLP抽出能力は凄い

498.9 492.7

413.4 404.3

16.2 0.0

100.0

200.0

300.0

400.0

500.0

600.0

C128 C32 S128 S32 x86

Exe

cutio

n Ti

me

[mse

c]�

25x

2015-01-16 Shinya T-Y, NAIST 42

Page 43: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

実行時間

n  FPGAでの実行時間を比べてみると直感と真逆の結果 l クロスバーよりも共有バスの方が高性能!

l バス幅が狭い方が高性能!

n なぜか? l 共有バスの方が レイテンシが短い

l バス幅が短い方が レイテンシが短い

l 必要なモノ: 高バンド幅ではなく 短レイテンシ

498.9 492.7

413.4 404.3

16.2 0.0

100.0

200.0

300.0

400.0

500.0

600.0

C128 C32 S128 S32 x86

Exe

cutio

n Ti

me

[mse

c]�

2015-01-16 Shinya T-Y, NAIST 43

Page 44: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

Pyverilog

2015-01-16 Shinya T-Y, NAIST 44

Page 45: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

Pyverilog: Python-based Hardware Design Processing Tool-kit for Verilog HDL

Module Analyzer�

Syntax Analyzer

Lexical Analyzer

AST

Signal Analyzer�

Bind Analyzer�

Dataflow

State Machine Pattern Matcher�

Control-flow

Optimizer�

Code Generator�

Active Condition Analyzer�

Visualizer�

Verilog HDL Code

module TOP (input CLK, input RST, output rslt, …�

Graphical Output

Verilog HDL Code

module TOP (input CLK, input RST, output rslt, …�

Parser

Dataflow Analyzer

Control-flow Analyzer

Input�

Output�

AST

2015-01-16 Shinya T-Y, NAIST 45

Page 46: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PythonでVerilog HDLのコード生成 1 import pyverilog.vparser.ast as vast2 from pyverilog.ast_code_generator.codegen import ASTCodeGenerator34 params = vast.Paramlist(())5 clk = vast.Ioport( vast.Input(’CLK’) )6 rst = vast.Ioport( vast.Input(’RST’) )7 width = vast.Width( vast.IntConst(’7’), vast.IntConst(’0’) )8 led = vast.Ioport( vast.Output(’led’, width=width) )9 ports = vast.Portlist( (clk, rst, led) )

10 items = ( vast.Assign( vast.Identifier(’led’), vast.IntConst(’8’) ) ,)11 ast = vast.ModuleDef("top", params, ports, items)1213 codegen = ASTCodeGenerator()14 rslt = codegen.visit(ast)15 print(rslt)

11 19, 14 13:53 Page 1/1codegen.pyPrinted by

æ°´æM−^[M−^\æM−^W¥ 11æM−^\M−^H 19, 2014 codegen.py

1 module top2 (3 input [0:0] CLK, 4 input [0:0] RST, 5 output [7:0] led6 );7 assign led = 8;8 endmodule

11 19, 14 14:15 Page 1/1generated.vPrinted by

æ°´æM−^[M−^\æM−^W¥ 11æM−^\M−^H 19, 2014 generated.v

Python

Verilog HDL

Execute

これをベースに 抽象度の高いHDLを作りたい

2015-01-16 Shinya T-Y, NAIST 46

Page 47: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

flipSyrup: RTL Modeling with Abstract Objects n  In advance, RAM objects and logic segments are

identified by using abstract objects of flipSyrup

ReConFig2014 Shinya T-Y. NAIST 47

Read Write

RAM

1-cycle RAMs w/o Capacity Limits

RAM RAM

Logic

Read Write

Sub-logic 0

Syrup Memory

Syrup Memory

Syrup Channel

Syrup Channel

Read Write

Virtual Connection

Region 0

Sub-logic N-1

Syrup Memory

Syrup Channel

Region N-1

= Entire Original Logic Replacing RAMs and I/Os with abstract objects

(a) Original Target Design (b) RTL Design with Abstract Objects

Page 48: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

Complete Cycle-Accurate Simulation System n  The tool-chain generates a complete IP-core for cycle-

accurate simulation of the target hardware

ReConFig2014 Shinya T-Y. NAIST 48

Memory I/F

Memory I/F

Channel I/F

Channel I/F

Stall

I/O In

terfa

ce

(Ser

/Des

) Off-chip DRAM

On-chip Bus Interface (AXI4 or Handshake)

Cache

FIFO

Controlled Simulation

Target

Cycle-Accuracy Manager

Cache

FIFO

On-chip Interconnect

Other IP-core

or CPU

(If needed)

flipSyrup IP-core (Region 0) (Automatically Generated)

FPGA Region 0

I/O

flipSyrup System

Sub-logic 0

FPGA Region N-1

Connected to Other FPGAs

Page 49: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

今後の展望とまとめ

2015-01-16 Shinya T-Y, NAIST 49

Page 50: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

今後の展望 n 諸事情により開発があまり進んでいません(´・ω・`) n ロジックのモデリング方式は何とかしたい

l コンピューティングロジックもHDLで書きたくない l 計算カーネルに特化したマルチパラダイム処理系・DSL?

•  MyHDL (Python), Chisel (Scala), Synthesijer.Scala (Scala)

•  PyMTL: この後で紹介

n 他の言語で高位合成系 l  Go言語のgoroutineとかchannelはいいよね

n 高位合成系におけるLLVM的環境の実現 l  LLVM: LLVM-IRを入力に最適化したり機械語を吐いたり l データフローを入力したらスケジューリング・最適化

•  DFGレベルのスケジューリング・最適化を対象

•  粗粒度・スレッドレベルなスケジューリングは自分で

2015-01-16 Shinya T-Y, NAIST 50

Page 51: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

PyMTL [Lockhart+,MICRO’14]

Derek Lockhart+: PyMTL: A Unified Framework for Vertically Integrated Computer Architecture Research, ACM/IEEE MICRO-47 (2014)

Pythonでハードウェアを記述 3つのパラダイムをサポート •  Functional Level (FL) •  Cycle Level (CL) •  Register Transfer Level (RTL)

これって書きやすい?

2015-01-16 Shinya T-Y, NAIST 51

Page 52: PyCoRAM (高位合成友の会@ドワンゴ, 2015年1月16日)

まとめ n  PyCoRAM: 高位合成技術とメモリシステム抽象化を用いたアクセラレータIPコア開発のためのフレームワーク

n 開発したツール・フレームワークは公開中

PyCoRAM IP User I/O

User Logic

CoRAM Channel

CoRAM Register

Control Thread

Master DMAC

CoRAM Memory

Master DMAC

CoRAM Stream

FSM

GPIO

Slave DMAC

CoRAM IoChannel

Modeled in RTL (Verilog HDL)

Memory Access Pattern

in Python

$ pip install pyverilog�$ pip install pycoram�

2015-01-16 Shinya T-Y, NAIST 52