[日本語]
การคำนวณแบบขนานกับ OpenCL บน GPU และ CPU

LUX.GPU.OpenCL Library
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 ที่สร้างขึ้นนั้นลงทะเบียนในคุณสมบัติ Contexs[] ของคลาส TCLPlatfo
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 ลงทะเบียนวัตถุ TCLQueuer ในคุณสมบัติ Queuers[]
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 ข้อมูลอาร์เรย์จะต้องเป็น " แผนที่ 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 voxel ถือเป็นประเภทของ ภาพ 3 มิติ คลาส 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
ส่วนที่สองของชื่อคลาสแสดงถึงลำดับช่องสีของภาพ
- tclimager
*xBGRAx*
- คำสั่งช่องสี::
BGRA- tclimager
*xRGBAx*
- คำสั่งช่องสี
RGBA
ส่วนที่สามของชื่อคลาสแสดงถึงประเภทข้อมูลสีของภาพ
- 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
" Build " ( 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 );
วัตถุหน่วย ความจำ เชื่อมโยงกับพารามิเตอร์ในซอร์สโค้ดผ่านคุณสมบัติ "parames" ของคลาส 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