[日本語]
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
" Context "객체 ( 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
클래스 이름의 두 번째 부분은 이미지의 색상 채널 순서를 나타냅니다.
- 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
" 빌드 "( 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 클래스의 "Parames"속성을 통해 소스 코드의 매개 변수에 연결됩니다.
Object Pascal_Kernel.Parames[ ' Buffer ' ] := _Buffer; // Connect to buffer _Kernel.Parames[ ' Imager ' ] := _Imager; // Connect to image _Kernel.Parames[ ' Samplr ' ] := _Samplr; // Connect to sampler
OPENCL 프로그램은 3 중 루프 진술처럼 반복적으로 실행됩니다.
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