Mercurial > hg > Papers > 2012 > yutaka-master
comparison paper/chapter1.tex @ 1:5dbcea03717e draft
fix
author | Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 07 Feb 2012 17:38:59 +0900 |
parents | 6d80c2c895e4 |
children | d17943f59cc3 |
comparison
equal
deleted
inserted
replaced
0:6d80c2c895e4 | 1:5dbcea03717e |
---|---|
1 \chapter{序論} | 1 \chapter{Cell Broadband Engine} |
2 | 2 本研究で実験題材の対象となった Cell アーキテクチャについて説明する。 |
3 \section{はじめに} | 3 |
4 はじめに | 4 Cell Broadband Engine \cite{cell} は、ソニー・コンピュータエンタテインメント、 |
5 ソニー、IBM , 東芝によって開発されたマルチコア CPU である。 | |
6 Cell は、1基の制御系プロセッサコア PPE ( PowerPC Processor Element ) と | |
7 8基の演算系プロセッサコア SPE ( Synergistic Processor Element ) で構成される。 | |
8 各プロセッサコアは、EIB (Element Interconnect Bus) | |
9 と呼ばれる高速なバスで接続されている。また、EIB はメインメモリや | |
10 外部入出力デバイスとも接続されていて、 | |
11 各プロセッサコアは EIB を経由してデータアクセスをおこなう。 | |
12 本研究で用いた PS3Linux (Yellow Dog Linux 6.2) では、6 個の SPE を | |
13 使うことが出来る ( \figref{cell_arch} ) | |
14 | |
15 この PPE と SPE の2種類の CPU を、プログラマ自身が用途に | |
16 合わせて適切に使い分けるように考慮する必要がある。 | |
17 | |
18 \begin{figure}[htb] | |
19 \begin{center} | |
20 \includegraphics[scale=0.8]{./images/cell-main.pdf} | |
21 \end{center} | |
22 \caption{Cell Broadband Engine Architecture} | |
23 \label{fig:cell_arch} | |
24 \end{figure} | |
25 | |
26 | |
27 \section{PPE (PowerPC Processor Element)} | |
28 | |
29 PPE は Cell Broadband Engine のメインプロセッサで、複数の SPE を | |
30 コアプロセッサとして使用することができる汎用プロセッサである。 | |
31 メインメモリや外部デバイスへの入出力、SPEを制御する役割を担っている。 | |
32 PPU (PowerPC Processor Unit) は、 | |
33 PPE の演算処理を行うユニットで、PowerPC アーキテクチャをベースとした | |
34 命令セットを持つ。PPSS (PowerPC Processor Storage Subsystem) は | |
35 PPU からメインメモリへのデータアクセスを制御する | |
36 ユニットである (\figref{ppe}) 。 | |
37 | |
38 \begin{figure}[htb] | |
39 \begin{center} | |
40 \includegraphics[scale=0.6]{./images/PPE.pdf} | |
41 \end{center} | |
42 \caption{PPE (PowerPC Processor Element)} | |
43 \label{fig:ppe} | |
44 \end{figure} | |
45 | |
46 \section{SPE (Synergistic Processor Element)} \label{sec:spe} | |
47 | |
48 SPE には 256KB の Local Store (LS) と呼ばれる、SPE から唯一、 | |
49 直接参照できるメモリ領域があり、バスに負担をかける事無く | |
50 並列に計算を進めることが出来る。SPE からメインメモリへは、 | |
51 直接アクセスすることは出来ず、SPE を構成する一つである | |
52 MFC (Memory Flow Controller) へ、チャネルを介して DMA (Direct Memory Access) | |
53 命令を送ることで行われる (\figref{spe}) 。 | |
54 | |
55 \begin{figure}[htb] | |
56 \begin{center} | |
57 \includegraphics[scale=0.8]{./images/SPE.pdf} | |
58 \end{center} | |
59 \caption{SPE (Synergistic Processor Element)} | |
60 \label{fig:spe} | |
61 \end{figure} | |
62 | |
63 \section{Cell の基本性能} | |
64 | |
65 \subsection{DMA (Direct Memory Access)} | |
66 | |
67 \ref{sec:spe}節 で述べた通り、SPE は LS 以外のメモリに | |
68 直接アクセスすることができず、PPE が利用するメインメモリ上のデータに | |
69 アクセスするには DMA (Direct Memory Access) を用いる。 | |
70 DMA 転送とは、CPU を介さずに周辺装置とメモリとの間でデータ転送ことで、 | |
71 Cell の場合はメインメモリと LS 間でデータの転送を行う。手順としては以下の様になる。 | |
72 | |
73 \begin{enumerate} | |
74 \item SPE プログラムが MFC (Memory Flow Controller) に対して | |
75 DMA 転送命令を発行 | |
76 \item MFC が DMA Controller を介して DMA 転送を開始。 | |
77 この間、SPE プログラムは停止しない。 | |
78 \item DMA 転送の終了を待つ場合、SPE プログラム内で転送の完了を待つ | |
79 \end{enumerate} | |
80 | |
81 この時、DMA 転送するデータとアドレスにはいくつか制限がある。 | |
82 転送データが 16 バイト以上の場合、データサイズは 16 バイトの倍数で、 | |
83 転送元と転送先のアドレスが 16 バイト境界に揃えられている必要がある。 | |
84 転送データが 16 バイト未満の場合、データサイズは 1,2,4,8 バイトで、 | |
85 転送サイズに応じた自然なアライメントである (転送サイズのバイト境界に | |
86 揃えられている) ことが条件となる。 | |
87 | |
88 \subsection{SIMD (Single Instruction Multiple Data)} | |
89 Cell では、SPE に実装されている 128 ビットレジスタを用いて | |
90 SIMD を行うことが出来る。SIMD とは、1 つの命令で | |
91 複数のデータに対して処理を行う演算方式である (\figref{simd}) 。 | |
92 | |
93 \begin{figure}[htb] | |
94 \begin{center} | |
95 \includegraphics[scale=0.8]{./images/SIMD.pdf} | |
96 \end{center} | |
97 \caption{SIMD (Single Instruction Multiple Data)} | |
98 \label{fig:simd} | |
99 \end{figure} | |
100 | |
101 \figref{simd} のスカラ演算は以下のような式に当てはまる。 | |
102 | |
103 \begin{verbatim} | |
104 int a[4] = {1, 2, 3, 4}; | |
105 int b[4] = {5, 6, 7, 8}; | |
106 int c[4]; | |
107 | |
108 for (int i = 0; i < 4; i++) { | |
109 a[i] + b[i] = c[i]; | |
110 } | |
111 \end{verbatim} | |
112 | |
113 これに対し、SIMD 演算は以下のようになる。 | |
114 | |
115 \begin{verbatim} | |
116 vector signed int va = {1, 2, 3, 4}; | |
117 vector signed int vb = {5, 6, 7, 8}; | |
118 vector signed int vc; | |
119 | |
120 vc = spu_add(va, vb); | |
121 \end{verbatim} | |
122 | |
123 Cell の SIMD 演算では、vector 型の変数を用いる。 | |
124 | |
125 このように、通常は 4 回計算するところを 1 回の計算で行うことが | |
126 できる反面、すべての演算を 128 ビットで計算するため、なるべく | |
127 効果的に行う様に工夫する必要がある。 | |
128 | |
129 \begin{verbatim} | |
130 int a, b, c; | |
131 | |
132 c = a + b; | |
133 \end{verbatim} | |
134 | |
135 この様な計算の場合でも 128 ビット同士の演算を行うため、無駄が生じる。 | |
136 | |
137 \subsection{Mailbox} \label{sec:mailbox} | |
138 | |
139 Mailbox とは SPE の MFC 内の FIFO キューであり、PPE と SPE 間の 32 ビット | |
140 メッセージの交換に用いられる。Mailbox では 3 つの振る舞いが | |
141 出来る様に設計されている (\figref{mailbox}) 。 | |
142 | |
143 \begin{figure}[htb] | |
144 \begin{center} | |
145 \includegraphics[scale=0.8]{./images/Mailbox.pdf} | |
146 \end{center} | |
147 \caption{Mailbox} | |
148 \label{fig:mailbox} | |
149 \end{figure} | |
150 | |
151 \begin{enumerate} | |
152 \item SPU Inbound Mailbox \\ | |
153 PPE から SPE へデータを渡すためのキュー。キューのエントリ数は | |
154 実装依存による \cite{cell} が、研究環境では最大4個までのデータを蓄積できる。 | |
155 このキューが空の場合は、SPE は、データがメールボックスに書き込まれるまでは、 | |
156 命令でストールする。読み出すデータの順番は書き込んだ順番に保証されている。 | |
157 \item SPU Outbound Mailbox \\ | |
158 SPE から PPE へのデータを渡すためのキュー。研究環境では最大1個までしか | |
159 データが蓄積できない。 | |
160 \item SPU Outbound interrupt Mailbox \\ | |
161 SPU Outbound Mailbox とほとんど同じだが、このキューでは SPE から | |
162 キューにデータが書き込まれると、PPE に対して割り込みイベントが | |
163 発生し、データの読み出しタイミングを通知する事が出来る。 | |
164 \end{enumerate} | |
165 | |
166 \section{開発環境} | |
167 | |
168 \subsection{libSPE2} | |
169 | |
170 libSPE2 とは、PPE が SPE を扱うためのライブラリ群である \cite{libspe2} 。 | |
171 libSPE2 は SPE Context Creation、SPE Program Image Handling、 | |
172 SPE Run Control、SPE Event Handling、SPE MFC Problem State Facilities、 | |
173 Direct SPE Access for Applications という基本構成でできている。 | |
174 Cell の基本プログラムは次の様になる。 | |
175 | |
176 \begin{enumerate} | |
177 \item create N SPE context | |
178 \item Load the appropriate SPE executable object into each SPE context's local store | |
179 \item Create N threads | |
180 \item Wait for all N threads to terminate | |
181 \end{enumerate} | |
182 | |
183 \subsection{SPU C/C++ 言語拡張} | |
184 SPE では基本的な C 言語の機能の他に、Cell 特有の拡張が行われている | |
185 \cite{cell_cpp} 。 | |
186 \tabref{cell_cpp} に主な API を記す。 | |
187 | |
188 \begin{table}[htb] | |
189 \begin{center} | |
190 \caption{SPU C/C++ 言語拡張 API} | |
191 \label{tab:cell_cpp} | |
192 \begin{tabular}{|l|l|} | |
193 \hline | |
194 spu\_mfcdma32 & DMA 転送を開始する \\ | |
195 \hline | |
196 spu\_read\_in\_mbox & PPE からの mail を取得する \\ | |
197 \hline | |
198 spu\_write\_out\_mbox & PPE へ mail を送信する \\ | |
199 \hline | |
200 spu\_add、spu\_sub、spu\_mul & SIMD 演算 (加算、減算、乗算) \\ | |
201 \hline | |
202 \end{tabular} | |
203 \end{center} | |
204 \end{table} | |
205 | |
206 SPE を効率よく使う上で \tabref{cell_cpp} の様な Cell 特有の API や、 | |
207 SPE アセンブラ命令を学ぶことが必要となる。 | |
208 | |
209 \subsection{SPURS} | |
210 | |
211 ここでは、現在発表されている Cell の開発環境である SPURS について説明する。 | |
212 | |
213 SPURS \cite{spurs} は、閉じた並列分散と考えることができる Cell の環境で、 | |
214 いかに効率よく動作させるかということを考えたシステムである。 | |
215 | |
216 Cell の性能を存分に生かすためには SPE を効率よく使い切ることであり、 | |
217 SPE の動作を止めることなく、同期を最小限に行う必要がある。 | |
218 そこで SPURS では SPE を効率よく利用するために、PPE に依存せずに SPE コードを | |
219 選択し、実行することと機能は効率重視で割り切ることを挙げている。 | |
220 そのため、SPE 上にカーネルを組み込んでいる。 | |
221 | |
222 アプリケーションを複数 SPE で実行するとき、アプリケーションプログラムを | |
223 出来るだけ小さな単位(タスク)に分割し、通信ライブラリを用いて | |
224 タスク間を依存関係で結合する。 | |
225 LS 常駐のカーネルが、実行可能なタスクを選んで実行していく | |
226 (\figref{spurs}) 。 | |
227 | |
228 \begin{figure}[htb] | |
229 \begin{center} | |
230 \includegraphics[scale=0.6]{./images/spurs_task.pdf} | |
231 \end{center} | |
232 \caption{SPURS Task} | |
233 \label{fig:spurs} | |
234 \end{figure} | |
235 | |
236 これらの処理はデータを扱うため、SPURS はパイプラインで実行される | |
237 (\figref{spurs_pipeline}) 。 | |
238 | |
239 \begin{figure}[htb] | |
240 \begin{center} | |
241 \includegraphics[scale=0.6]{./images/spurs_pipeline.pdf} | |
242 \end{center} | |
243 \caption{SPURS Pipeline} | |
244 \label{fig:spurs_pipeline} | |
245 \end{figure} | |
246 | |
247 以上から、SPURS は複数の SPE を効率よく使うためのライブラリとして | |
248 優れた物であると思われるが、現在一般には公開されていない。 |