Skip to content

OpenCL

Class for working with OpenCL programs

The COpenCL class is a wrapper to facilitate working with the OpenCL functions. In some cases, use of the GPU allows to substantially increase the speed of computations.

Examples of class use for calculations based on float and double values can be found in the corresponding subdirectories of the MQL5\Scripts\Examples\OpenCL\ folder. The source codes of the OpenCL programs are located in MQL5\Scripts\Examples\OpenCL\Double\Kernels and MQL5\Scripts\Examples\OpenCL\Float\Kernels subdirectories.

  • MatrixMult.mq5 - example of matrix multiplication using global and local memory
  • BitonicSort.mq5 - example of parallel sorting of array elements in GPU
  • FFT.mq5 - example of fast Fourier transform calculation
  • Wavelet.mq5 - example of wavelet transform of data using the Morlet wavelet.

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.

Declaration

class COpenCL

Title

#include <OpenCL\OpenCL.mqh>

Class methods

NameDescription
BufferCreateCreates an OpenCL buffer at the specified index
BufferFreeDeletes buffer at the specified index
BufferFromArrayCreates a buffer at the specified index from an array of values
BufferReadReads an OpenCL buffer at the specified index into an array
BufferWriteWrites an array of values into buffer at the specified index
ExecuteExecutes the OpenCL kernel with the specified index
GetContextReturns handle of the OpenCL context
GetKernelReturns handle of the kernel object at the specified index
GetKernelNameReturns name of the kernel object at the specified index
GetProgramReturns handle of the OpenCL program
InitializeInitializes the OpenCL program
KernelCreateCreates an entry point into the OpenCL program at the specified index
KernelFreeRemoves an OpenCL start function at the specified index
SetArgumentSets a parameter for the OpenCL function at the specified index
SetArgumentBufferSets an OpenCL buffer as a parameter of the OpenCL function at the specified index
SetArgumentLocalMemorySets a parameter in local memory for the OpenCL function at the specified index
SetBuffersCountSets the number of buffers
SetKernelsCountSets the number of kernel objects
ShutdownUnloads the OpenCL program
SupportDoubleChecks if floating point data types are supported on the device
Last updated on