[日本語]
GPUおよびCPUのOpenCLを使用した並列コンピューティング。

LUX.GPU.OpenCLライブラリ
TOpenCL:TCLSystemのシングルトン
┃
TCLSystem:システムTCLPlatfos:プラットフォームリストTCLPlatfo:プラットフォームTCLExtenss:拡張リストTCLDevices:デバイスリストTCLDevice:デバイスTCLContexs:コンテキストリストTCLContex:コンテキストTCLQueuers:コマンドキューリストTCLQueuer:コマンドキューTCLArgumes:引数リストTCLBuffer:バッファーTCLImager:画像TCLSamplr:サンプラーTCLLibrars:ライブラリリストTCLLibrar:ライブラリTCLExecuts:実行可能なプログラムリストTCLExecut:実行可能プログラムTCLBuildrs:ビルドリストTCLBuildr:ビルドTCLKernels:カーネルリストTCLKernel:カーネルTCLParames:パラメーターリストTCLParame:パラメーター
TOpenCLクラスは、 TCLSystemクラスのシングルトンです。 TCLSystemクラスは、ホストマシンに存在するすべてのコンピューティングデバイスを自動的に検出します。
「プラットフォーム」オブジェクト( TCLPlatfo )は、各デバイスベンダーが提供する環境を表します。 TCLSystemクラスは、すべてのプラットフォームを自動的に検出し、 Platfos[]プロパティにリストします。
Object PascalTOpenCL.Platfos.Count :Integer // Number of all platforms TOpenCL.Platfos[*] :TCLPlatfo // Array of all platforms
TCLPlatfoクラスは、特定のプラットフォームに関する情報をプロパティとして提供します。
Object Pascal_Platfo := TOpenCL.Platfos[ 0 ]; // Selecting a specific platform _Platfo.Handle :T_cl_platform_id // Pointer _Platfo.Profile :String // Profile _Platfo.Version :String // Version _Platfo. Name :String // Name _Platfo.Vendor :String // Vendor Name _Platfo.Extenss.Count :Integer // Number of Extensions _Platfo.Extenss[*] :String // Array of Extensions
「デバイス」オブジェクト( TCLDevice )は、物理GPUまたはCPUを表します。 TCLPlatfoクラスは、特定のプラットフォームオブジェクト内のすべてのデバイスオブジェクトを自動的に検出し、 Devices[]プロパティにそれらを列挙します。
Object Pascal_Platfo.Devices.Count :Integer // Number of devices _Platfo.Devices[*] :TCLDevice // Array of devices
TCLDeviceクラスは、そのプロパティを介して各特定のデバイスに関する詳細情報を提供します。
Object Pascal_Device := _Platfo.Devices[ 0 ]; // Selecting a specific device _Device.Handle :T_cl_device_id // Pointer _Device.DEVICE_TYPE :T_cl_device_type // Type _Device.DEVICE_VENDOR_ID :T_cl_uint // Vendor ID _Device.DEVICE_NAME :String // Name _Device.DEVICE_VENDOR :String // Vendor _Device.DRIVER_VERSION :String // Driver Version _Device.DEVICE_PROFILE :String // Profile _Device.DEVICE_VERSION :String // Version
「コンテキスト」オブジェクト( TCLContex )は、関連するデータとプログラムのコレクションを管理します。 TCLContexクラスは、 TCLPlatfoクラスからインスタンス化されています。
Object Pascal_Contex := TCLContex.Create( _Platfo );
生成されたTCLContexクラスは、 TCLPlatfoクラスのContexs[]プロパティに登録されています。
Object Pascal_Platfo.Contexs.Count :Integer // Number of contexts _Platfo.Contexs[*] :TCLContex // Array of contexts ``
「コマンドキュー」オブジェクト( TCLQueuer )は、デバイスに送信されたコマンドを管理します。つまり、コンテキストとデバイスの間の橋渡しとして機能します。 TCLQueuerクラスは、 TCLContexおよびTCLDeviceクラスを引数として作成します。
Object Pascal_Queuer := TCLQueuer.Create( _Contex, _Device ); { or } _Queuer := _Contex.Queuers[ _Device ];
TCLContexクラスは、 Queuers[]プロパティのTCLQueuerオブジェクトを登録します。
Object Pascal_Contex.Queuers.Count :Integer // Number of command queue _Contex.Queuers[*] :TCLQueuer // Array of command queue
さまざまなプラットフォーム上のコンテキストとデバイスは、コマンドキューを生成できないことに注意してください。
Object PascalP0 := TOpenCL.Platfos[ 0 ]; P1 := TOpenCL.Platfos[ 1 ]; P2 := TOpenCL.Platfos[ 2 ]; D00 := P0.Devices[ 0 ]; D01 := P0.Devices[ 1 ]; D02 := P0.Devices[ 2 ]; D10 := P1.Devices[ 0 ]; D20 := P2.Devices[ 0 ]; C0 := TCLContex.Create( P0 ); C1 := TCLContex.Create( P1 ); C2 := TCLContex.Create( P2 ); Q00 := TCLQueuer.Create( C0, D00 ); // OK Q01 := TCLQueuer.Create( C0, D01 ); // OK Q02 := TCLQueuer.Create( C0, D02 ); // OK Q10 := TCLQueuer.Create( C1, D00 ); // Error Q11 := TCLQueuer.Create( C1, D01 ); // Error Q12 := TCLQueuer.Create( C1, D02 ); // Error Q20 := TCLQueuer.Create( C2, D00 ); // Error Q21 := TCLQueuer.Create( C2, D10 ); // Error Q22 := TCLQueuer.Create( C2, D20 ); // OK
TCLArgume
TCLMemory
TCLBuffer
TCLImager
TCLSamplr
「メモリ」オブジェクト( TCLMemory )はさまざまなデータを保存し、デバイスと共有します。 TCLMemoryクラスは、 TCLContexおよびTCLQueuerクラスから作成されます。 TCLMemoryクラスは抽象的であり、 TCLBufferおよびTCLImagerクラスを導き出します。
TCLBufferクラスには、「シンプルなタイプ」または「レコードタイプ」の配列を保存します。
次の構造タイプの配列をデバイスに送信する場合は、
OpenCL Ctypedef struct { int A ; double B ; } TItem ; kernel void Main ( global TItem * Buffer ) { ・・・ }
次のようにTCLBufferクラスを生成します。
Object PascalTItem = record A :Integer; B :Double; end ; _Buffer := TCLBuffer<TItem>.Create( _Contex, _Queuer );
Dataプロパティを介して配列データを読み取り、書き込みます。アレイデータは、読み取りまたは書き込み前にホストと同期するために「 Map PED」でなければならず、使用後にデバイスと同期するために「 UNMAP PED」でなければなりません。
Object Pascal_Buffer.Count := 3 ; // Setting the number of elements _Buffer.Data.Map; // Synchronize data with host _Buffer.Data[ 0 ] := TItem.Create( 1 , 2.34 ); // Writing _Buffer.Data[ 1 ] := TItem.Create( 5 , 6.78 ); // Writing _Buffer.Data[ 2 ] := TItem.Create( 9 , 0.12 ); // Writing _Buffer.Data.Unmap; // Synchronize data with Device
「画像」オブジェクト( TCLImager )は、ピクセル配列を1Dから3Dに保存します。 3Dボクセルデータも3D画像の一種と見なされます。 TCLImagerクラスは抽象的であり、カラーチャネルのレイアウトとビットに応じてさまざまなクラスを導き出します。
TCLImager
TCLImager1D
TCLImager1DxBGRAxUInt8
TCLImager1DxBGRAxUFix8
TCLImager1DxRGBAxUInt32
TCLImager1DxRGBAxSFlo32
TCLImager2D
TCLImager2DxBGRAxUInt8
TCLImager2DxBGRAxUFix8
TCLImager2DxRGBAxUInt32
TCLImager2DxRGBAxSFlo32
TCLImager3D
TCLImager3DxBGRAxUInt8
TCLImager3DxBGRAxUFix8
TCLImager3DxRGBAxUInt32
TCLImager3DxRGBAxSFlo32
クラス名の最初の部分は、画像の次元を表します。
- tclimager
1Dx*x*
- 寸法:
1D- Tclimager
2Dx*x*
- 寸法:
2D- tclimager
3Dx*x*
- 寸法:
3D
クラス名の2番目の部分は、画像のカラーチャネル順序を表します。
- tclimager
*xBGRAx*
- カラーチャネル順序:
BGRA- tclimager
*xRGBAx*
- カラーチャネルの順序:
RGBA
クラス名の3番目の部分は、画像のカラーデータ型を表します。
- tclimager
*x*xUInt8
- デバイス側のデータタイプ:
uint8@ opencl c- ホスト側のデータタイプ:
UInt8 (Byte)@ Delphi- tclimager
*x*xUFix8
- デバイス側のデータタイプ:
float@ opencl c- ホスト側のデータタイプ:
UInt8 (Byte)@ Delphi- tclimager
*x*xUInt32
- デバイス側のデータタイプ:
uint@ opencl c- ホスト側のデータタイプ:
UInt32 (Cardinal)@ Delphi- tclimager
*x*xSFlo32
- デバイス側のデータタイプ:
float@ opencl c- ホスト側のデータタイプ:
Single@ Delphi
'countx'/'y'/'z'プロパティは、x/y/z方向にピクセル数を設定します。
Object Pascal_Imager := TCLDevIma3DxBGRAxUInt8.Create( _Contex, _Queuer ); _Imager.CountX := 100 ; // Number of pixels in the X direction _Imager.CountY := 200 ; // Number of pixels in the Y direction _Imager.CountZ := 300 ; // Number of pixels in the Z direction
サンプラーオブジェクト( TCLSamplr )は、補間法を定義して、実際の座標でピクセルの色を取得します。
TCLSamplrクラスは、引数として「TCLContex」クラスで生成されます。
Object Pascal_Samplr := TCLSamplr.Create( _Contex );
「プログラム」オブジェクト( TCLProgra )はソースコードを読み取り、実行可能なバイナリにコンパイルします。 TCLPrograクラスは、 TCLContexクラスを引数として作成します。 TCLPrograクラスは抽象的であり、ソースコードのタイプに応じて、 TCLLibrarおよびTCLExecutクラスの基本クラスとして機能します。
TCLLibrarクラスは、直接実行する機能を含まないプログラムです。ライブラリタイプと呼ばれます。
Object Pascal_Librar := TCLLibrar.Create( _Contex ); _Librar.Source.LoadFromFile( ' Librar.cl ' ); // load Sourcecode
TCLExecutクラスは、直接実行する関数(カーネルS)を含むプログラムです。
Object Pascal_Execut := TCLExecut.Create( _Contex ); _Execut.Source.LoadFromFile( ' Execut.cl ' ); // load Sourcecode
「ビルド」( TCLBuildr )は、プログラムによって実行される「アクション」ですが、ライブラリのクラスとして明示的に表されています。
Object Pascal_Buildr := TCLBuildr.Create( _Execut, _Device ); { or } _Buildr := _Execut.Buildrs[ _Device ]; { or } _Buildr := _Execut.BuildTo( _Device );
カーネルオブジェクト(第2.8章を参照)は、実行時にTCLBuildrクラスを自動的に作成します。ただし、カーネルを実行する前にTCLBuildrオブジェクトを作成することにより、コンパイルとリンクエラーを確認できます。
Object Pascal_Buildr.Handle; // Run build _Buildr.CompileStatus :T_cl_build_status // Compile status _Buildr.CompileLog :String // Compile log _Buildr.LinkStatus :T_cl_build_status // Link status _Buildr.LinkLog :String // Link log
「カーネル」オブジェクト( TCLKernel )は、プログラム内の実行可能機能を表します。
OpenCL Ckernel void Main ( ・・・ ) { ・・・ }
TCLKernelクラスは、 TCLExecutおよびTCLQueuerオブジェクトからインスタンス化されています。
Object Pascal_Kernel := TCLKernel.Create( _Execut, ' Main ' , _Queuer ); { or } _Kernel := _Execut.Kernels.Add( ' Main ' , _Queuer );
メモリオブジェクトは、 TCLKernelクラスの「パラーム」プロパティを介してソースコードのパラメーターにリンクされています。
Object Pascal_Kernel.Parames[ ' Buffer ' ] := _Buffer; // Connect to buffer _Kernel.Parames[ ' Imager ' ] := _Imager; // Connect to image _Kernel.Parames[ ' Samplr ' ] := _Samplr; // Connect to sampler
OPENCLプログラムは、トリプルループステートメントのように繰り返し実行されます。
Object Pascal_Kernel.GloSizX := 100 ; // Number of loops in X direction _Kernel.GloSizY := 200 ; // Number of loops in Y direction _Kernel.GloSizZ := 300 ; // Number of loops in Z direction
最小および最大ループインデックスを指定することもできます。
Object Pascal_Kernel.GloMinX := 0 ; // Start index in X direction _Kernel.GloMinY := 0 ; // Start index in Y direction _Kernel.GloMinZ := 0 ; // Start index in Z direction _Kernel.GloMaxX := 100 - 1 ; // End index in X direction _Kernel.GloMaxY := 200 - 1 ; // End index in Y direction _Kernel.GloMaxZ := 300 - 1 ; // End index in Z direction
Object Pascal_Kernel.Run; // Run