annotate paper/chapter2.tex @ 79:7990a2abbf05 default tip

add file
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Mon, 02 Mar 2015 11:21:40 +0900
parents 48db1f674a83
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
48db1f674a83 update pdf
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 54
diff changeset
1 \chapter{並列プログラミング\\フレームワーク Cerium}
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
2 Cerium は、当初 Cell 用の Fine-Grain TaskManager として当研究室で開発された。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
3 本章では Cerium の実装について説明する。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
5 \section{Cerium の概要}
54
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 49
diff changeset
6 Cerium は当初 Cell 用であったが、現在では Linux、 MacOS X上で動作する。
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
7 GPGPU の Data Parallel を含めて同じ形式で記述できる。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
8
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
9 CeriumはTaskManager、 SceneGraph、Rendering Engine の3つの要素から構成される。
32
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
10 本研究では Cerium の TaskManager を汎用計算フレームワークとして改良を行った。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
11
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
12 \section{Cerium TaskManager}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
13 Cerium TaskManager では、処理の単位を Task としてプログラムを記述していく。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
14 関数やサブルーチンを Task として扱い、 Task 間の依存関係を考慮しながら実行される。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
15
32
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
16 ソースコード:\ref{src:createTask}に Host 側で Task を生成する例題を示す。
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
17 input data を2つ用意し、 input data の各要素同士を乗算し、
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
18 output に格納する multiply という例題である。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
19
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
20 \begin{lstlisting}[frame=lrbt,label=src:createTask,caption=Task の生成,numbers=left]
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
21 void
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
22 multiply_init(TaskManager *manager, float *i_data1, float *i_data2, float *o_data) {
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
23
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
24 // create task
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
25 HTask* multiply = manager->create_task(MULTIPLY_TASK);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
26 multiply->set_cpu(spe_cpu);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
27
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
28 // set indata
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
29 multiply->set_inData(0, i_data1, sizeof(float) * length);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
30 multiply->set_inData(1, i_data2, sizeof(float) * length);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
31
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
32 // set outdata
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
33 multiply->set_outData(0, o_data, sizeof(float) * length);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
34
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
35 // set parameter
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
36 multiply−>set_param(0,(long)length);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
37
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
38 // set device
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
39 multiply->set_cpu(SPE_ANY);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
40
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
41 // spawn task
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
42 multiply−>spawn();
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
43 }
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
44 \end{lstlisting}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
45
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
46 表:\ref{table:task_create_api}は Task 生成時に用いる API の一覧である。
32
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
47 create された Task は Input Data や 依存関係を設定し、
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
48 spawn することで TaskManager に登録される。
0
aae08d907517 first commit
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
50 \begin{tiny}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
51 \begin{table}[htpb]
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
52 \begin{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
53 \small
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
54 \begin{tabular}[htpb]{c|l}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
55 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
56 create\_task & Task を生成する \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
57 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
58 set\_inData & Task への入力データのアドレスを追加 \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
59 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
60 set\_outData & Task からの出力データのアドレスを追加 \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
61 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
62 set\_param & Task へ値を一つ渡す。ここではlengthを渡している \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
63 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
64 set\_cpu & Task を実行する Device の設定 \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
65 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
66 spawn & 生成した Task を ActiveTaskList に登録する \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
67 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
68 \end{tabular}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
69 \caption{Task 生成おける API}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
70 \label{table:task_create_api}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
71 \end{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
72 \end{table}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
73 \end{tiny}
0
aae08d907517 first commit
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
32
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
75 次に、ソースコード:\ref{src:task} に Device 側で実行される Task (OpenCL、CUDA でいう kernel) の記述を示す。
0
aae08d907517 first commit
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
77 \begin{lstlisting}[frame=lrbt,label=src:task,caption=Task,numbers=left]
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
78 static int
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
79 run(SchedTask *s) {
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
80 // get input
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
81 float *i_data1 = (float*)s->get_input(0);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
82 float *i_data2 = (float*)s->get_input(1);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
83 // get output
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
84 float *o_data = (float*)s->get_output(0);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
85 // get parameter
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
86 long length = (long)s->get_param(0);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
87
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
88 // calculate
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
89 for (int i=0; i<length; i++) {
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
90 o_data[i] = i_data1[i] * i_data2[i];
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
91 }
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
92 return 0;
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
93 }
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
94 \end{lstlisting}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
95
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
96 表:\ref{table:task_api}は Task 側で使用する API である。
32
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
97 Host 側で設定した Input Data やパラメタを取得することができる。
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
98
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
99 \begin{tiny}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
100 \begin{table}[htpb]
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
101 \begin{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
102 \small
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
103 \begin{tabular}[htpb]{c|l}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
104 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
105 get\_input & 入力データのアドレスを取得 \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
106 \hline
7
786db8c94c6e Bitonic sort example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
107 set\_output & 出力先データのアドレスを取得 \\
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
108 \hline
7
786db8c94c6e Bitonic sort example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
109 set\_param & パラメータを取得 \\
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
110 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
111 \end{tabular}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
112 \caption{Task 側で使用する API}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
113 \label{table:task_api}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
114 \end{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
115 \end{table}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
116 \end{tiny}
32
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
117
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
118 Task を生成する際に設定できる要素は以下の通りとなる。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
119
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
120 \begin{itemize}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
121 \item Input Data
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
122 \item Output Data
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
123 \item Parameter
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
124 \item CpuType
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
125 \item Dependency
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
126 \end{itemize}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
127
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
128 Input/Output Data, Parameter は関数で言うところの引数に相当する。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
129 CpuType は Task が動作する Device を示し、 Dependency は他の Task との依存関係を表す。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
130
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
131 \section{Cerium における Task}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
132 図:\ref{fig:taskmanager}は Cerium が Task を生成/実行する場合のクラスの構成図である。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
133 TaskManager で依存関係が解消され、実行可能になった Task は ActiveTaskList に移される。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
134 ActiveTaskList に移された Task は依存関係が存在しないのでどのような順番で実行されても良い。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
135 Task は転送を行いやすい TaskList に変換され、CpuType に対応した Scheduler に転送される。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
136 なお、転送はSynchronozed Queue である mail を通して行われる。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
137
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
138 \begin{figure}[htpb]
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
139 \begin{center}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
140 \includegraphics[scale=0.7]{./images/createTask.pdf}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
141 \end{center}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
142 \caption{Task Manager}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
143 \label{fig:taskmanager}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
144 \end{figure}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
145
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
146 \section{Task の Scheduling}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
147 GPU や Cell のような Shared Memory でない環境でのプログラミングを行う場合、
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
148 Task の入出力となるデータを転送し、転送が終わってから Task を起動しなければならない。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
149 転送処理がボトルネックとなり、並列度が低下してしまう。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
150 そのため、Cerium はパイプライン実行をサポートしている。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
151
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
152 Scheduler に転送された Task はパイプラインで処理される(図:\ref{fig:scheduler})。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
153 Task が全て終了すると Scheduler から TaskManager に mail を通して通知される。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
154 通知に従い依存関係を解決した Task が再び TaskManager から Scheduler に転送される。
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
155
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
156 \begin{figure}[htpb]
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
157 \begin{center}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
158 \includegraphics[scale=0.7]{./images/scheduler.pdf}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
159 \end{center}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
160 \caption{Scheduler}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
161 \label{fig:scheduler}
9b7ce931cad9 fix about cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
162 \end{figure}
48
8d6a0f047d5a create task in sort bench example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
163
49
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
164 Cerium の Task は SchedTask と呼ばれるデータ構造で表現されている。
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
165 SchedTask は input/output data の length や合計 size を持っており、
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
166 これらのパラメタから自分の data が格納されているアドレスを算出し、read/write を実行する。
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
167 SchedTask を利用することで容易にパイプラインを構築できる。
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
168 Task をパイプライニングにより Scheduling している部分をソースコード:\ref{src:pipeline_multicore}に示す。
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
169
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
170 \begin{lstlisting}[frame=lrbt,label=src:pipeline_multicore,caption=Task,numbers=left]
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
171 void
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
172 Scheduler::run(SchedTaskBase* task1)
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
173 {
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
174 // Pipeline Stage
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
175 SchedTaskBase* task2 = new SchedNop();
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
176 SchedTaskBase* task3 = new SchedNop();
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
177
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
178 // main loop
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
179 do {
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
180
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
181 task1->read();
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
182 task2->exec();
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
183 task3->write();
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
184
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
185 delete task3;
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
186
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
187 task3 = task2;
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
188 task2 = task1;
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
189 task1 = task1->next(this, 0);
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
190
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
191 } while (task1);
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
192
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
193 delete task3;
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
194 delete task2;
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
195 }
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
196 \end{lstlisting}
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
197
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
198 引数として受け取っている task1 は Task のリストである。このリストがなくなるまでパイプライン実行のループを回す。
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
199 task1 が read、task2 が exec、task3 が write を担当している。
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
200 つまり task3 には read と exec が終わった Task が来るため、write が終わったら delete して良い。
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
201 各 Task はそれぞれの処理を行い、task2 は task3 に、task1 は task2 に自分の Task を渡していく。
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
202
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
203 このメインループを回すことで Cerium の Scheduler はパイプラインによる実行を可能にしている。
c7678996940c add pipeline in multicore
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 48
diff changeset
204