annotate paper/chapter2.tex @ 31:f0060254db3f

fix introduction
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Sat, 14 Feb 2015 14:29:17 +0900
parents 79d16cee0afd
children 9b7ce931cad9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
f0060254db3f fix introduction
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 19
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 の概要}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
6 Cerium は当初 Cell 用であったが、現在では Linux、 MaxOS X上で動作する。
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つの要素から構成される。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
10 本研究では Cerium の TaskManager を汎用計算フレームワークとして改良を行う。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
11 これによりヘテロジニアス環境に対応したシステムやフレームワークに必要な API や機構について考察していく。
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 Task を生成する際に、以下のような要素を設定することができる。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
16
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
17 \begin{itemize}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
18 \item input data
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
19 \item output data
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
20 \item parameter
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
21 \item cpu type
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
22 \item dependency
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
23 \end{itemize}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
24
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
25 input/output data, parameter は関数で言うところの引数に相当する。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
26 cpu type は Task が動作する Device を示し、 dependency は他の Task との依存関係を表す。
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 \section{Cerium における Task}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
29 図:\ref{fig:taskmanager}は Cerium が Task を生成/実行する場合のクラスの構成図である。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
30 TaskManager で依存関係が解消され、実行可能になった Task は ActiveTaskList に移される。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
31 ActiveTaskList に移された Task は依存関係が存在しないのでどのような順番で実行されても良い。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
32 Task は転送を行いやすい TaskList に変換され、cpu type に対応した Scheduler に転送される。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
33 なお、転送はSynchronozed Queue である mail を通して行われる。
0
aae08d907517 first commit
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
aae08d907517 first commit
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
36 \begin{figure}[htpb]
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
37 \begin{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
38 \includegraphics[scale=0.7]{./images/createTask.pdf}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
39 \end{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
40 \caption{Task Manager}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
41 \label{fig:taskmanager}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
42 \end{figure}
0
aae08d907517 first commit
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
44 \section{Task の Scheduling}
15
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
45
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
46 GPU や Cell のような Shared Memory でない環境でのプログラミングを行う場合、
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
47 Task の入出力となるデータを転送し、転送が終わってから Task を起動しなければならない。
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
48 転送処理がボトルネックとなり、並列度が低下してしまう。
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
49 そのため、Cerium はパイプライン実行をサポートしている。
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
50
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
51 Scheduler に転送された Task はパイプラインで処理される(図:\ref{fig:scheduler})。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
52 Task が全て終了すると Scheduler から TaskManager に mail を通して通知される。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
53 通知に従い依存関係を解決した Task が再び TaskManager から Scheduler に転送される。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
54
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
55 \begin{figure}[htpb]
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
56 \begin{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
57 \includegraphics[scale=0.7]{./images/scheduler.pdf}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
58 \end{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
59 \caption{Scheduler}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
60 \label{fig:scheduler}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
61 \end{figure}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
62 \newpage
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
63 \section{Task 生成の例}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
64 ソースコード:\ref{src:createTask}に Task を生成する例題を示す。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
65 input data を2つ用意し、 input data の各要素同士を乗算し、
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
66 output に格納する multiply という例題である。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
67
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
68 \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
69 void
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
70 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
71
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
72 // create task
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
73 HTask* multiply = manager->create_task(MULTIPLY_TASK);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
74 multiply->set_cpu(spe_cpu);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
75
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
76 // set indata
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
77 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
78 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
79
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
80 // set outdata
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
81 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
82
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
83 // set parameter
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
84 multiply−>set_param(0,(long)length);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
85
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
86 // set device
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
87 multiply->set_cpu(SPE_ANY);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
88
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
89 // spawn task
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
90 multiply−>spawn();
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 \end{lstlisting}
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 表:\ref{table:task_create_api}は Task 生成時に用いる API の一覧である。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
95 create された Task は各種パラメタを設定し、spawn/iterate することで TaskManager に登録される。
0
aae08d907517 first commit
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
97 \begin{tiny}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
98 \begin{table}[htpb]
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
99 \begin{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
100 \small
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
101 \begin{tabular}[htpb]{c|l}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
102 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
103 create\_task & Task を生成する \\
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 set\_inData & Task への入力データのアドレスを追加 \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
106 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
107 set\_outData & Task からの出力データのアドレスを追加 \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
108 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
109 set\_param & Task へ値を一つ渡す。ここではlengthを渡している \\
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 set\_cpu & Task を実行する Device の設定 \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
112 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
113 spawn & 生成した Task を ActiveTaskList に登録する \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
114 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
115 \end{tabular}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
116 \caption{Task 生成おける API}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
117 \label{table:task_create_api}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
118 \end{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
119 \end{table}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
120 \end{tiny}
0
aae08d907517 first commit
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
122 ソースコード:\ref{src:createTask}は Host 側で Task を生成しているプログラムである。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
123 Device 側で実行される Task (OpenCL、CUDA でいう kernel) の記述はソースコード:\ref{src:task}のようになる。
0
aae08d907517 first commit
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
125 \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
126 static int
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
127 run(SchedTask *s) {
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
128 // get input
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
129 float *i_data1 = (float*)s->get_input(0);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
130 float *i_data2 = (float*)s->get_input(1);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
131 // get output
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
132 float *o_data = (float*)s->get_output(0);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
133 // get parameter
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
134 long length = (long)s->get_param(0);
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
135
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
136 // calculate
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
137 for (int i=0; i<length; i++) {
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
138 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
139 }
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
140 return 0;
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
141 }
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
142 \end{lstlisting}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
143
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
144 表:\ref{table:task_api}は Task 側で使用する API である。
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
145
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
146 \begin{tiny}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
147 \begin{table}[htpb]
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
148 \begin{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
149 \small
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
150 \begin{tabular}[htpb]{c|l}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
151 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
152 get\_input & 入力データのアドレスを取得 \\
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
153 \hline
7
786db8c94c6e Bitonic sort example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
154 set\_output & 出力先データのアドレスを取得 \\
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
155 \hline
7
786db8c94c6e Bitonic sort example
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
156 set\_param & パラメータを取得 \\
4
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
157 \hline
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
158 \end{tabular}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
159 \caption{Task 側で使用する API}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
160 \label{table:task_api}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
161 \end{center}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
162 \end{table}
af22b3d1e5c3 about Cerium
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
163 \end{tiny}