c#でopencl with opentk + cloo
DESCRIPTION
関西GPGPU勉強会#2 http://connpass.com/event/865/ で発表した、OpenTKとClooを使ってC#からOpenCLによるGPGPUをする方法の基礎的な話。TRANSCRIPT
![Page 1: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/1.jpg)
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
青子守歌
C#でOpenCL with OpenTK+Cloo
![Page 2: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/2.jpg)
- 2 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
どんなことができるか
どんなことができるか
<OpenTK+Cloo>
![Page 3: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/3.jpg)
- 3 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
.NET Frameworkをふんだんに使った
かっちょいいアプリ
どんなことができるか<OpenTK+Cloo>
![Page 4: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/4.jpg)
- 4 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
OpenCL-GL interopで高速かつきれいなかっちょいいアプリ
どんなことができるか<OpenTK+Cloo>
![Page 5: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/5.jpg)
- 5 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
こんなの↓どんなことができるか
<OpenTK+Cloo>
![Page 6: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/6.jpg)
- 6 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
計算空間へのリアルタイム干渉!
(入出力)
どんなことができるか<OpenTK+Cloo>
![Page 7: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/7.jpg)
- 7 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
Open TKとClooとは
OpenTKとClooとは<OpenTK+Cloo>
![Page 8: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/8.jpg)
- 8 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
対象環境:Windowsです!
MacとLinuxはどうなんだろう?
<OpenTK+Cloo>
OpenTKとClooとは
![Page 9: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/9.jpg)
- 9 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
OpenTKとは
Open Tool Kit:http://www.opentk.com/
OpenGLをC# (.NET Framework/Mono)から使うフレームワーク
<OpenTK+Cloo>
![Page 10: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/10.jpg)
- 10 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
OpenTKの使い方
OpenTKのインストール方法
<OpenTK+Cloo>
![Page 11: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/11.jpg)
- 11 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
インストールするには
ダウンロードしてインストーラ使え?
<OpenTK+Cloo>
![Page 12: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/12.jpg)
- 12 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
インストールした後は
VisualStudioの参照設定にOpenTKが追加されます
<OpenTK+Cloo>
![Page 13: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/13.jpg)
- 13 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
OpenTKの使い方
OpenGLの使い方は割愛!
<OpenTK+Cloo>
![Page 14: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/14.jpg)
- 14 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
OpenTKをWPFで使うには
※注意OpenTKのGLControlがForm向け
→WPFで使うにはWindowsFormsHostを使うのが一番ラク(速度も気にならない)
<OpenTK+Cloo>
![Page 15: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/15.jpg)
- 15 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
詳しい使い方とかは
私の学習用レポジトリ@githubをご覧あれ?
https://github.com/aokomoriuta/StudiesOfOpenTK
そのうちドキュメント作ります
<OpenTK+Cloo>
![Page 16: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/16.jpg)
- 16 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
Clooとは
Cloo:http://sourceforge.net/projects/cloo/
OpenCLをC# (.NET Framework/Mono)から使うフレームワーク
<OpenTK+Cloo>
![Page 17: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/17.jpg)
- 17 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
Clooのインストール方法
Clooのインストール方法
<OpenTK+Cloo>
![Page 18: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/18.jpg)
- 18 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
ソースそのままを
インストーラみたいなのはないので、ソースそのものをダウンロードします
オリジナルzip:http://sourceforge.net/projects/cloo/files/latest/
オリジナルgitレポジトリ:git://cloo.git.sourceforge.net/gitroot/cloo/cloo
非公式githubレポジトリby青子守歌:https://github.com/aokomoriuta/Cloo
<OpenTK+Cloo>
![Page 19: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/19.jpg)
- 19 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
自分のソリューションへ
VisualStudioのプロジェクトを追加
<OpenTK+Cloo>
![Page 20: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/20.jpg)
- 20 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
Clooの使い方
Clooの使い方!!
<OpenTK+Cloo>
![Page 21: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/21.jpg)
- 21 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
そもそもOpenCLとは異種演算装置が混在する計算環境のためのフレームワーク
ホスト
プログラムオブジェクト
ソースコード(OpenCL C)
コンテキスト
メモリ転送コマンドカーネル実行コマンド同期コマンド
読み込み
ビルド
コマンド発行
実行
引数
コマンドキューメモリオブジェクトB
メモリオブジェクトA
カーネルA
カーネルB
デバイス
CPU
GPU
DSP
Cell
OpenMP, MPIなど
など
CUDA, ATI Streamなど
<OpenTK+Cloo>
![Page 22: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/22.jpg)
- 22 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
処理の順番1. 初期化する2. プログラムを作る3. メモリを確保4. 入力値を書き込む5. プログラムを実行する6. 出力値を読み込む
<OpenTK+Cloo>
![Page 23: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/23.jpg)
- 23 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
初期化する1
1. platformとdevice取得
<OpenTK+Cloo>
![Page 24: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/24.jpg)
- 24 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
初期化する2
2. contextとcommand queue作成
<OpenTK+Cloo>
![Page 25: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/25.jpg)
- 25 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
プログラムを作る
3. programとkernel作成
<OpenTK+Cloo>
![Page 26: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/26.jpg)
- 26 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
メモリを確保
4. buffer作成
<OpenTK+Cloo>
![Page 27: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/27.jpg)
- 27 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
入力値を書き込む
5. bufferへ書き込み
<OpenTK+Cloo>
![Page 28: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/28.jpg)
- 28 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
プログラムを実行する
6. kernel実行
<OpenTK+Cloo>
![Page 29: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/29.jpg)
- 29 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
出力値を読み込む
7. bufferから読み込み
<OpenTK+Cloo>
![Page 30: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/30.jpg)
- 30 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
以上です!
割と簡単でしょう?
<OpenTK+Cloo>
![Page 31: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/31.jpg)
- 31 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
応用例とかは
私の学習用レポジトr(ry
https://github.com/aokomoriuta/StudiesOfOpenCLWithCloo
そのうちドキュメント作りません
<OpenTK+Cloo>
![Page 32: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/32.jpg)
- 32 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
Clooの問題点
・開発が最近放置気味・命名規則が気に入らない・C#に最適化されてない
(ジェネリックとか)
<OpenTK+Cloo>
![Page 33: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/33.jpg)
- 33 -
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
個人的には
Clooのバインド(ラッパー)だけ使う
<OpenTK+Cloo>
![Page 34: C#でOpenCL with OpenTK + Cloo](https://reader036.vdocuments.net/reader036/viewer/2022081716/548dbd81b47959f2248b4a58/html5/thumbnails/34.jpg)
aokomoriuta (2012-10-13): 関西GPGPU勉強会#2
一部で特別な指定があるものを除き、全ての文章と画像はクリエイティブ・コモンズ 表示-継承または表示-非営利 3.0 非移植で利用可能です。
Otherwise noted, all text and images are availableunder the Creative Commons Attribution-Share Alike or Attribution-Noncommercial 3.0 Unported.
CC-BY-SA: http://creativecommons.org/licenses/by-sa/3.0 CC-BY-NC: http://creativecommons.org/licenses/by-nc/3.0
return 0;