- CLHandleType
- CLGetInfoInteger
- CLGetInfoString
- CLContextCreate
- CLContextFree
- CLGetDeviceInfo
- CLProgramCreate
- CLProgramFree
- CLKernelCreate
- CLKernelFree
- CLSetKernelArg
- CLSetKernelArgMem
- CLSetKernelArgMemLocal
- CLBufferCreate
- CLBufferFree
- CLBufferWrite
- CLBufferRead
- CLExecute
- CLExecutionStatus
Working with OpenCL
OpenCL programs are used for performing computations on video cards that support OpenCL 1.1 or higher. Modern video cards contain hundreds of small specialized processors that can simultaneously perform simple mathematical operations with incoming data streams. The OpenCL language organizes parallel computing and provides greater speed for a certain class of tasks.
In some graphic cards working with the double type numbers is disabled by default. This can lead to compilation error 5105. To enable support for the double type numbers, please add the following directive to your OpenCL program: #pragma OPENCL EXTENSION cl_khr_fp64 : enable. However if a graphic card doesn't support double, enabling this directive won't be of help.
It is recommended to write the source code for OpenCL in separate CL files, which can later be included in the MQL5 program using the resource variables.
Handling errors in OpenCL programs
To get information about the last error in an OpenCL program, use the CLGetInfoInteger and CLGetInfoStringfunctions that allow getting the error code and text description.
OpenCL last error code: To get the latest OpenCL error, call CLGetInfoInteger, while thehandleparameter is ignored (can be set to zero). Description of errors: https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#CL_SUCCESS.
For an unknown error code, the"unknown OpenCL error N" string is returned where N is an error code. Example:
//--- the first 'handle' parameter is ignored when getting the last error code
|
Text description of the OpenCL error: To get the latest OpenCL error, call CLGetInfoString. The error code should be passed as thehandleparameter.
Description of errors: https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#CL_SUCCESS. If CL_LAST_ERROR is passed instead of the error code, then the function returns the description of the last error. For example:
//--- get the code of the last OpenCL error
|
So far, the name of the internal enumeration is given as an error description. You can find its decoding here: https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#CL_SUCCESS. For example, the CL_INVALID_KERNEL_ARGS value means "Returned when enqueuing a kernel when some kernel arguments have not been set or are invalid."
Functions for running programs in OpenCL:
Function |
Action |
---|---|
Returns the type of an OpenCL handle as a value of the ENUM_OPENCL_HANDLE_TYPE enumeration |
|
Returns the value of an integer property for an OpenCL object or device |
|
Creates an OpenCL context |
|
Removes an OpenCL context |
|
Receives device property from OpenCL driver |
|
Creates an OpenCL program from a source code |
|
Removes an OpenCL program |
|
Creates an OpenCL start function |
|
Removes an OpenCL start function |
|
Sets a parameter for the OpenCL function |
|
Sets an OpenCL buffer as a parameter of the OpenCL function |
|
Sets the local buffer as an argument of the kernel function |
|
Creates an OpenCL buffer |
|
Deletes an OpenCL buffer |
|
Writes an array into an OpenCL buffer |
|
Reads an OpenCL buffer into an array |
|
Runs an OpenCL program |
|
Returns the OpenCL program execution status |
See also