Discussion of article "How to Install and Use OpenCL for Calculations"

 

New article How to Install and Use OpenCL for Calculations is published:

It has been over a year since MQL5 started providing native support for OpenCL. However not many users have seen the true value of using parallel computing in their Expert Advisors, indicators or scripts. This article serves to help you install and set up OpenCL on your computer so that you can try to use this technology in the MetaTrader 5 trading terminal.

How to Install and Use OpenCL for Calculations

What is OpenCL?

OpenCL is the open standard for parallel programming developed by the Khronos Group consortium in 2008. This standard allows you to develop applications that could be run in parallel on GPUs or CPUs with different architecture in a heterogeneous system.

In other words, OpenCL makes it possible to utilize all CPU cores or GPU's enormous computing capacity when calculating a task, thus reducing program execution time. Use of OpenCL is therefore very beneficial when dealing with tasks associated with laborious and resource consuming computations.

For example, speaking of MQL5, performance gain can be very rewarding when handling a certain script (indicator or Expert Advisor) that performs a complex and lengthy analysis of historical data by several symbols and time frames (it should be noted here that a MQL5 program that is intended to employ parallel execution should be written in a special way using OpenCL API).

Author: MetaQuotes

 
In order to demonstrate the advantage of using OpenCL in MQL5, the OpenCL_Sample.mq5 script was written, which calculates the values of a function from two variables on some set and displays the result in the chart window<br/ translate="no">.

TC is also a function, the result of which is some custom indicator. I.e. the optimiser is a calculation of function values on some set, as in the given quote.

Can we talk about the expediency of a standard OpenCL optimiser then? Or are there pitfalls that will not allow to get such significant (> 2 times) speedups?

I'm even more interested in the optimiser's work in mat mode.

 
OpenCL is well suited for those cases when it is necessary to perform uniform computational operations on a large data set. Then we take a set of values, cut it into pieces and give each piece to a separate processor for calculation. This is the time gain. More details about OpenCL technology are described in two articles mentioned in this article.
 

Can you explain the decoding in the log about found devices with OpenCL support.

First comes the device number in your case it is device#0 then the device name nvidia GTX 580 , OpenCL version of the device, but what is written in brackets is not quite clear. Shouldn't the number of ALU (for nvidia CODA cores) be indicated??? and then there is a very unclear frequency, it's not clear what it refers to, usually the frequency of the video core is not more than 1000 MHz.... Please decipher it.

OpenCL: Мост в параллельные миры
OpenCL: Мост в параллельные миры
  • 2012.05.16
  • Sceptic Philozoff
  • www.mql5.com
В конце января 2012 года компания-разработчик терминала MetaTrader 5 анонсировала нативную поддержку OpenCL в MQL5. В статье на конкретном примере изложены основы программирования на OpenCL в среде MQL5 и приведены несколько примеров "наивной" оптимизации программы по быстродействию.
 

Good afternoon everyone.

Can you please advise on this very interesting topic:

1. Are there already any Expert Advisors for trading that use OpenCL for calculations?

2. If there are several video cards installed in the system, will they all be used for calculations or only one of them ?

 

2. Each expert can use only one card.

Several experts can use several OpenCL devices at the same time.

 
If multiple devices on a comp can be involved in OpenCL calculations, will all of them be used or just one of them?
 
paladin800:
If multiple devices on a comp can be involved in OpenCL calculations, will all of them be used or just one of them?

There was already an answer above

Renat:

2. Each Expert Advisor can use only one card.

You can explicitly specify which device should be used by a particular MQL5 programme. Look at the CLContextCreate function
 
sigma7i:

Can you explain the decoding in the log about found devices with OpenCL support.

First comes the device number in your case it is device#0 then the device name nvidia GTX 580 , OpenCL version of the device, but what is written in brackets is not quite clear. Shouldn't the number of ALU (for nvidia CODA cores) be indicated??? and then there is an incomprehensible frequency, it is not clear what it refers to, usually the frequency of the video core is not more than 1000 MHz... Please decipher it.

Incorrectly I asked the questions I apologise....

the questions are based on the picture from the article:

1. what does "16 units" mean ? And why is the number of cores in the video card not specified ?

2. what is meant by 1630 MHz ? the full frequency of the video card or individual components ?

picture

 

First of all, OpenCL is its own specification of parallelism methods independent of the hardwired implementation. That's why you can't look for a complete coincidence with GPU specifications.

Units are not separate cores but groups of cores. Different architectures have different methods of grouping several cores into units. For example, NVIDIA may have 8, 32, 48 cores (or more) in a unit. In CPU modes, units are counted as logical CPU cores.

The frequency is shown by the device (video card, for example).

 
There is another advantage of using OpenCL, the execution of OpenCL code in parallel with MQL5 code.

The point is that the call of the CLExecute function is just a command to the OpenCL driver to start execution.
Waiting for the completion of the OpenCL task occurs when accessing the OpenCL execution queue, for example, when calling the CLBufferRead function, as it happens in this example.


Between CLExecute and CLBufferRead calls, you can perform any MQL5 calculations that do not access the OpenCL queue.
OpenCL: Мост в параллельные миры
OpenCL: Мост в параллельные миры
  • 2012.05.16
  • Sceptic Philozoff
  • www.mql5.com
В конце января 2012 года компания-разработчик терминала MetaTrader 5 анонсировала нативную поддержку OpenCL в MQL5. В статье на конкретном примере изложены основы программирования на OpenCL в среде MQL5 и приведены несколько примеров "наивной" оптимизации программы по быстродействию.