助教が吼える!...
TRANSCRIPT
ハードウェアはやわらかい(SlideShare向けフォント妥協版)
高前田伸也 (29)奈良先端科学技術大学院大学助教
E-mail: shinya_at_is.naist.jp
2016年9月9日助教が吼える!各界の若手研究者大集合
ハードウェアはやわらかい
高前田伸也 (29)奈良先端科学技術大学院大学
2016年9月9日助教が吼える!各界の若手研究者大集合
ハードウェア?
3http://recruit.softbank.jp/career/img/project/img_pepper02_pc.jpghttp://jp.mazdacdn.com/common/assets/cars/axela/img/ax_top_hero_img_1607.ts.1607151126409000.jpghttp://news.kakaku.com/prdnews/cd=pc/ctcd=0010/id=4367/imageno=0/
ロボット? くるま?
ハードウェア?
4http://recruit.softbank.jp/career/img/project/img_pepper02_pc.jpghttp://jp.mazdacdn.com/common/assets/cars/axela/img/ax_top_hero_img_1607.ts.1607151126409000.jpghttp://news.kakaku.com/prdnews/cd=pc/ctcd=0010/id=4367/imageno=0/
コンピュータ!
5
CPU:データ処理装置の王道
6
Instruction Cache Tag
uOP Cache Tag
(Micro-Fusion/Macro-Fusion)
Store DataLoad AddressALU&Shift
Store Address
Load Address
Store Address
Port 0
Port 1
Port 5
Port 2
Port 3
Port 4
Zeroing Ideoms
2x32 Bytes/CycleLoad
(42 entries)
32 Bytes/Cycle Store
8-way, 11C
ycle Latency
Data TLB
(56 uOPs)
Up to 4 Fused uOPs
Branch
Divide
256-bit FMA(Multiply-Add)
256-bit FP Multiply
Vector Integer Multiply
Vector Logicals
Vector Shift
ALU
LEA(Load Effective Address)
Multiply
256-bit FMA(Multiply-Add)
256-bit FP Add
Vector Integer ALU
Vector Logicals
ALU
LEA(Load Effective Address)
Vector Shuffle
Vector Integer ALU
Vector Logicals
Port 6
ALU&Shift
Branch
Store Address
Port 7
64 Bytes/Cycle
uOPs
uOPs
uOPs
uOPs
uOPs
uOPs
uOPs
uOPs
http://images.anandtech.com/doci/6985/DT_Haswell_i7_FB_678x452.jpghttp://pc.watch.impress.co.jp/video/pcw/docs/665/735/p10.pdf
CPUの使い方
7
Writing a softwarein programming languages
Preprocess
Compile
Assemble
Link
Com
pile
r Flo
w
Execution on a CPU
ELF01ABF00F1...Executable Binary
int main(){int a = 1 + 2;printf(“Hello %d¥n”, a);return 0;
}
C source code
add $t0, $t1, $t2li $v0, 1syscallAssembly language
CPU(プロセッサ)の構成
8
Register File
ALU
Main Memory
Instruction Control
Program Counter
Processor
Operation supply
Dataread/write
Compute by consuming data
Instructionposition
Dataread/write
Instructionfetch
Data Instruction
Instruction fetch (IF)
9
Register File
ALU
Main Memory
Instruction Control
Program Counter
Processor
Operation supply
Dataread/write
Compute by consuming data
Instructionposition
Dataread/write
Instructionfetch
Data Instruction
Read an instruction from main memory
Instruction decode (ID)
10
Register File
ALU
Main Memory
Instruction Control
Program Counter
Processor
Operation supply
Dataread/write
Compute by consuming data
Instructionposition
Dataread/write
Instructionfetch
Data Instruction Decode the instruction and determine the ALU
operation
Register fetch (RF)
11
Register File
ALU
Main Memory
Instruction Control
Program Counter
Processor
Operation supply
Dataread/write
Compute by consuming data
Instructionposition
Dataread/write
Instructionfetch
Data Instruction Read values from register file to ALU
Execute (EX)
12
Register File
ALU
Main Memory
Instruction Control
Program Counter
Processor
Operation supply
Dataread/write
Compute by consuming data
Instructionposition
Dataread/write
Instructionfetch
Data Instruction Compute by using read data
Memory access (MA)
13
Register File
ALU
Main Memory
Instruction Control
Program Counter
Processor
Operation supply
Dataread/write
Compute by consuming data
Instructionposition
Dataread/write
Instructionfetch
Data Instruction
Sometimes data move from/to register from to/from main memory
Write back (WB)
14
Register File
ALU
Main Memory
Instruction Control
Program Counter
Processor
Operation supply
Dataread/write
Compute by consuming data
Instructionposition
Dataread/write
Instructionfetch
Data Instruction Write back the result to register file
ハードウェアはかたい?
n CPUやGPUは命令をバチバチ切り替えるだけl 我々は「どう使うか」しか変えられない
l なんて不自由な世界なんだ
n 我々はハードウェア・回路は作れないのか?
l そんなことはない
l 「ゆるふわ」なデバイスを使おう
15
ハードウェアは作れる。そうFPGAならね
n FPGA (Field Programmable Gate Array)中身を改変可能なLSI (PLD: Programmable Logic Device)l 設計者が独自のデジタル回路を形成することができる
n CPUなどとの大きな違いは?l CPUの振る舞いはソフトウェア(プログラム)で規定される
ü ユーザはCPUそのものの回路を変更することはできない
l FPGAの振る舞いはハードウェアそのものの変更で変えられる
Digital circuits
16
FPGAの構造
17
SB
CB
CB
LB
SB
CB
CB
LB
SB
CB
CB
LB
SBCB
SB
CB
CB
LB
SB
CB
CB
LB
SB
CB
CB
LB
SBCB
SB
CB
CB
LB
SB
CB
CB
LB
SB
CB
CB
LB
SBCB
SB
CB
SB
CB
SB
CB
SB
IOB
IOB
IOB
IOB
IOB
IOB
IOBIOBIOB
IOBIOBIOB
FPGA
SB
LB
CB
IOB
Logic Block
Switch Block
Connection Block
I/O Block
Wire
• An LB has logical circuit components for both combinational circuits and sequential circuits
• They are connected via interconnection components (SB, CB and wire)
FPGAの構造
18
SB
CB
CB
LB
SB
CB
CB
LB
SB
CB
CB
LB
SBCB
SB
CB
CB
LB
SB
CB
CB
LB
SB
CB
CB
LB
SBCB
SB
CB
CB
LB
SB
CB
CB
LB
SB
CB
CB
LB
SBCB
SB
CB
SB
CB
SB
CB
SB
IOB
IOB
IOB
IOB
IOB
IOB
IOBIOBIOB
IOBIOBIOB
FPGA
SB
LB
CB
IOB
Logic Block
Switch Block
Connection Block
I/O Block
Wire
• An LB has logical circuit components for both combinational circuits and sequential circuits
• They are connected via interconnection components (SB, CB and wire)
FPGAボードの基礎
FPGA(Xilinx Virtex-7 XC7V690T)
DDR3 SODIMM(4GB x2)
PCI-express10Gbps Ethernet x4
SATA-3 x2
Digilent NetFPGA SUMEPrice $24,500
19
20
Digilent Nexys3FPGA: Xilinx Spartan-6 LX16Size: Pipelined CPU ×2Price: 15,000yen (Academic)
Digilent ZedBoardFPGA: Xilinx Zynq 7020Size: Pipelined CPU ×8 (+ ARM DualCore)Price: 60,000yen (Academic)
21
SSD
Dual Camera
FPGA (Xilinx Zynq 7020, ARM Dualcore)+DDR3 DRAM 512MB
SSD Interface
22
Xilinx ZC706FPGA: Xilinx Zynq 7045Size: Pipelined CPU ×16Price: 300,000yen
23
Tokyo Electron Deice TB-6V-LX760-LSIFPGA: Xilinx Virtex-6 LX760Size: Pipelined CPU x100?Price: 4,000,000yen?
ScalableCore SystemFPGA: Xilinx Spartan-6 ×100Size: Pipelined CPU x200?Price: 100万円程度?
24
25
FPGA in Datacentersn Microsoft Bing Search Engine (Catapult)
l More space density and energy efficiency than GPUfor machine learning (DNN)
26Putnam+, A Reconfigurable Fabric for Accelerating Large-Scale Datacenter Services, ISCA'14
http://archive.eetindia.co.in/www.eetindia.co.in/STATIC/ARTICLE_IMAGES/201408/EEIOL_2014AUG14_PL_NT_01_03.jpg
FPGA for low-cost and energy-efficiency
27
http://www.wired.com/2014/06/microsoft-fpga/7Agile Co-Design for a Reconfigurable Datacenter, FPGA'16
Phenox: FPGA-based quadcoptern Programmable drone system with FPGA
l Zynq: SoC FPGA (ARM CPU + FPGA logics in a single chip)ü Easy to realize software with dedicated hardware support
28
Phenox http://phenoxlab.com/
CGRA(Coase Grained Reconfigurable Architecture)n 演算器をアレー上にたくさん並べる
l より多くのトランジスタ・電力を計算そのものに使う
l 例)EMAX[Tanomoto+, MCSoC'15]
29In
terc
onne
ctio
n
DRAM
CPU Core
PE PE PE PE
Mem
ory
Inte
rface
EMAX�
PE PE PE PE
PE PE PE PE
実際のEMAXチップn 12.5mm x 12.5mm in 180nm technology
30
Convolutional Neural Network (CNN)
n 複数種の処理が階層化
l Convolution (畳み込み): 多数の小規模行列積
l Pooling and Max-out: 複数の値から1つを選ぶ
l Full connection: 少数の比較的大きな行列積
n 性能ボトルネック: 畳み込みl ステンシル(演算毎にパターンがシフト)型の行列積
l GPUにおいてもメモリアライメント等の都合で高速化が難しい
31
Input Layer Hidden Layers Output Layer
Convolution Pooling Max Out Convolution Full Connection
EMAX上でのCNNの性能[Tanomoto+,MCSoC2015]
n 組み込み級のデータセットではEMAXが良い性能を達成l IoT機器におけるエッジコンピューティングに有利
32
0
2
4
6
8
10
12
14
16
18
Alexne
t-2
CIFAR10
-1
CIFAR10
-2
CIFAR10
-3
CIFAR10
(Avg
)
Lene
t-1
Lene
t-2
Lene
t (Avg
)
Operations/Byte�
EMAX GTX980 GK20A Core i7 ARM
CIFAR-10:1.41x better than
mobile GPU
Lenet:1.75x better than
mobile GPU
カスタムアーキテクチャの時代
n FPGAではなく応用に特化したLSIをクラウドでも使うのが当たり前に
l Google TPUとか
33https://cloudplatform.googleblog.com/2016/05/Google-supercharges-machine-learning-tasks-with-custom-chip.html
どうやってハードウェアを作るか
n 従来: RTL (Register Transfer Level) 設計l クロックサイクルレベルでレジスタ間のデータ移動や演算のタイミングを定義する
l Timed設計:「なに」を「いつ」「どのように」行うかを定義
l 通常のソフトウェアでいう「アセンブリ」の様なもの
34
例:2配列の積和演算 (c += a * b)
35
積和演算器(トップレベル) 乗算器
RTL設計 (Verilog HDL): 105行,2098文字,15分
「いつ」「なに」を「どのように」するかを設計者が決める
例:2配列の積和演算 (c += a * b)
36
積和演算器(トップレベル) 乗算器
RTL設計 (Verilog HDL): 105行,2098文字,15分
「いつ」「なに」を「どのように」するかを設計者が決める
つらいL
どうやってハードウェアを作るか
n 従来: RTL (Register Transfer Level) 設計l クロックサイクルレベルでレジスタ間のデータ移動や演算のタイミングを定義する
l Timed設計:「なに」を「いつ」「どのように」行うかを定義
l 通常のソフトウェアでいう「アセンブリ」の様なもの
n 今時: 高位合成(HLS: High Level Synthesis)l (一般に)汎用プログラミング言語を用いて振る舞いを定義
l Untimed設計:「なに」を行うかを実装ü 「いつ」「どのように」かは定義しなくても良い
ü 指示子(Directive)で「いつ」「どのように」の情報を付加することにより、より良いハードウェアが生成される
l 通常のソフトウェアでいう高級プログラミング言語に設計
37
例:2配列の積和演算 (c += a * b)
38
高位設計 (C言語): 11行,163文字,1分→1/10の記述量と1/15の開発時間(ただしディレクティブ等はなし)
(性能が出れば)高位設計 高!
「なに」をするかだけを設計者が決める
例:2配列の積和演算 (c += a * b)
39
高位設計 (C言語): 11行,163文字,1分→1/10の記述量と1/15の開発時間(ただしディレクティブ等はなし)
(性能が出れば)高位設計 高!
「なに」をするかだけを設計者が決める
たのしいJ
HLSを用いたハードウェア設計
40
Writing a hardwarein programming languages
Synthesis
Technology Mapping
Place and Route
Bitstream Generation
EDA
Flow
Configuration of the bitstreamto an FPGA
int sum(int array[1024]){int ret;for(i=0; i<1024; i++){
ret += array[i];}return ret;
}
1A0C021E...
Original HW on an FPGA
Bitstream
Lexical Analysis/Tokenize
Control-Dataflow analysis
Scheduling/Allocation
Code Generation of HDL
module sum(input [31:0] array_in,input array_in_valid, …always @(posedge CLK) begin …sum <= sum + array_in;
endendmodule
HLS
Flo
w
Xilinx Vivado HLSn Free (≠Open-source) compiler for Xilinx FPGAs
l Synthesize Verilog HDL/VHDL from C/C++
l Eclipse-based IDE
41Xilinx UG902
Altera OpenCLn OpenCL: parallel programming language for
heterogeneous platforms
n Synthesize Host-SW & FPGA-HW at same time, like GPU
42http://www.bdti.com/InsideDSP/2013/02/13/Altera
普通の高位合成だけでOK?n No.
n 動作合成では記述できない・したくない回路も多数存在
l 例)プロセッサ,タイミング・レイテンシ制約が厳しいI/F,等
n 終的な性能チューニングにはRTLが結局必要だったりl 例)Traxコンテストで毎回優勝する静岡大学はRTL設計
n 関連研究: プログラミング言語の記述力を活用したRTL設計方式・ドメイン固有言語l Chisel[Bachrach+,DAC'12]
l PyMTL[Lockhart+,MICRO’14]
l Synthesijer.Scala[三好,IEICE RECONF'15]
43
Veriloggen:PythonによるRTLメタプログラミング
44
Design Generator by Python
from veriloggen import *m = Module('blinkled')clk = m.Input('CLK')led = m.Output('LED', 8)count = m.Reg('count', 32)m.Assign( led(count[31:24]) )m.Always(Posedge(clk)(
count( count + 1 ) )hdl = m.to_verilog()print(hdl)
blinkled
CLK RST
LED count
assignalways
Veriloggen Object
module blinkled (input CLK,output [7:0] LED
);reg [31:0] count;assign LED = count[31:24];always @(posedge CLK) begincount <= count + 1;
endendmodule
Verilog Source Code
module
input
CLK
input
RST
blinkled
Verilog AST
to_verilog()
Verilog AST
Generator
Verilog Code
Generator
Run on Python Interpreter
Verilog HDLコードの組み立てルールをPythonの言語機能を活用して記述
Verilog HDLによる回路記述・テストベンチが生成される
実行
Verilogコードをオブジェクトとして表現
45
Moduleオブジェクト
Pythonの言語機能を用いてオブジェクトを組み立てる
(mの)Regオブジェクト
"count <= 0"オブジェクト
"count==1023"オブジェクト
Ifオブジェクト
(mの)Alwaysオブジェクト
完成したModuleオブジェクトをリターン
Veriloggen.Dataflowでパイプラインを作る
46
Veriloggen.Dataflowでパイプラインを作る
47
たのしいJ
Veriloggen is available!n GitHubで公開中
l Veriloggen: https://github.com/PyHDI/veriloggen
l PyCoRAM: https://github.com/PyHDI/PyCoRAM
l Pyverilog: https://github.com/PyHDI/Pyverilog
n PIP(Pythonパッケージ管理)でもインストール可
48
$ pip install veriloggen$ pip install pyverilog$ pip install pycoram
$ git clone https://github.com/PyHDI/veriloggen.git$ git clone https://github.com/PyHDI/Pyverilog.git$ git clone https://github.com/PyHDI/PyCoRAM.git
私が思う今後の高位合成の要件(気楽な話)
n 好きな言語でハードウェア開発できる
l ソフトウェア開発は用途と好みに応じて言語を選べる
ü C, C++, C#, Java, Python, Ruby, Perl, JavaScrit, Scala, Go, Haskell
l ハードウェア開発は?→選択肢が少ないü RTL: Verilog HDL, VHDL
ü 高級HDL: Chisel (Scala DSL), PyMTL (Python DSL), Veriloggen
ü 高位合成: C, C++, OpenCL, Java (Synthesijer), Python (PyCoRAM)
n 「好きな道具」で「好きなもの」を作る世界
ü 高位設計 ≠ C設計(Cベースが現状一番良いのは認める)
ü でもRubyで書きたい!Goで書きたい!Pythonで書きたい!
49
まとめ
n ハードウェアはやわらかい
l ハードウェアは作れる・改変できる
ü FPGA
ü CGRAやカスタムアーキテクチャならもっと攻められる
l ハードウェアはお手軽に設計できる
ü 高位合成 (High Level Synthesis)
ü C/C++だけではなくPythonなどの「ゆるふわ」な言語でも設計できる
n 応用を見据えたハードウェアを作ってハッピーになろう!
l ソフトウェアだけではなくハードウェアも作ると
オーダーが変えられる(はず)
50