Jaf*_*son 5 gpu opencl metatrader5 mql5
我已经使用 MQL5 创建了一个指标。
分析后,我读到的程序说我的 CPU 的 99% 被我的OnCalculate().
这是我的功能:
int OnCalculate( const int rates_total,
const int prev_calculated,
const int begin,
const double &price[]
)
{
//--- check for bars count
float tempprice[];
ArrayResize( tempprice, ArraySize( price ) );
if ( rates_total < InpMAPeriod - 1 + begin ) return( 0 ); // not enough bars for calculation
//--- first calculation or number of bars was changed
if ( prev_calculated == 0 ) ArrayInitialize( ExtLineBuffer, 0 );
ArrayCopy( tempprice, price );
//--- sets first bar from what index will be draw
PlotIndexSetInteger( 0, PLOT_DRAW_BEGIN, InpMAPeriod - 1 + begin );
switch( InpMAMethod )
{
case MODE_EMA: Execute_Me( price,
"CalculateEMA",
rates_total,
prev_calculated,
begin
);
break;
case MODE_LWMA: Execute_Me( price,
"CalculateLWMA",
rates_total,
prev_calculated,
begin
);
break;
case MODE_SMMA: Execute_Me( price,
"CalculateSmoothedMA",
rates_total,
prev_calculated,
begin
);
break;
case MODE_SMA: Execute_Me( price,
"CalculateSimpleMA",
rates_total,
prev_calculated,
begin
);
break;
}
return( rates_total );
}
Run Code Online (Sandbox Code Playgroud)
请让我知道,我如何才能OnCalculate()在 GPU 而不是 CPU 上工作。
可以通过调用来控制哪个计算设备,即您的程序是否使用CPU CLContextCreate:
int CLContextCreate(int device)
Run Code Online (Sandbox Code Playgroud)
其中device可以是例如CL_USE_GPU_ONLY,或特定的设备编号。
此处描述了如何查找该号码。
然而:我从配置文件中可以看到,大部分时间都花在创建和释放 OpenCL 上下文上。如果配置文件代表某种调用堆栈,我会假设为每个计算创建并释放 OpenCL 上下文,而不是在程序初始化和取消初始化期间执行一次。
这似乎花费了您 85% 的运行时间。因此,请确保在初始化期间创建 OpenCL 上下文、程序、内核和缓冲区对象。对于重复计算,您只需要设置内核参数,读/写缓冲区对象,并将内核排队执行
希望有帮助。