我试图继续使用MQL5中的OpenCL .
我尝试过以下方法:
My GPU-kernel program :
kernel void SMA_executeSMA(float ExtLineBufferi_1, float price1,float price2, int InpMAPeriod, __global float *output)
{
int len = get_global_id(1);
output[len] = ExtLineBufferi_1 + (price1 - price2)/InpMAPeriod;
}
GPU-kernel Execution :
void executeSMA(int limit, int rates_total, const double &price[])
{
int cl_output = CLBufferCreate(cl_ctx,1*sizeof(float),CL_MEM_READ_WRITE);
float temp_output_as_float[];
ArrayResize(temp_output_as_float,ArraySize(price));
Check_Memory_Initialization(cl_output,cl_CommonKernel1,"executeSMA function");
CLSetKernelArg(cl_CommonKernel1,3,InpMAPeriod);
CLSetKernelArgMem(cl_CommonKernel1,4,cl_output);
for(int i=limit;i<rates_total && !IsStopped();i++)
{
CLSetKernelArg(cl_CommonKernel1,0,(float)ExtLineBuffer[i-1]);
CLSetKernelArg(cl_CommonKernel1,1,(float)price[i]);
CLSetKernelArg(cl_CommonKernel1,2,(float)price[i-InpMAPeriod]);
CLExecute(cl_CommonKernel1,CUDA_CORE,offset,work);
//ExtLineBuffer[i] = (double)temp_output_as_float[0];
//Print(ExtLineBuffer[i]);
//ArrayPrint(ExtLineBuffer);
}
CLBufferRead(cl_output,temp_output_as_float);
ArrayPrint(temp_output_as_float);
ArrayCopy(ExtLineBuffer,temp_output_as_float);
CLBufferFree(cl_output);
}
首先,我没有看到输出,因此我试图打印收到的值,他们是可怕的 .
看一看 :
2018.05.17 16:57:09.122 [ 130] -1.52993219472835656E+30 65762250018783232.00000 +0.00000 +0.00000 -12210.34766
2018.05.17 16:57:09.122 [ 135] -0.00000 52789604352.00000 -0.00000 -0.00000 +0.00000
2018.05.17 16:57:09.122 [ 140] +0.00000 3.63274742468334127E+33 0.00164 -15064.41504 3.81201777719114223E+31
2018.05.17 16:57:09.122 [ 145] -2.08007761411320351E+30 1.09393519416171176E+33 3.65208085768979492E+26 +0.00000 4.02907890816376635E+20
2018.05.17 16:57:09.122 [ 150] 0.05321 -4.04696761050396099E+19 52162858846257152.00000 4.35782820014886955E+30 -101985552.00000
2018.05.17 16:57:09.122 [ 155] -1357115162624.00000 -0.00000 9.69987852353929216E+17 -4.08771377928525016E+27 -1508.35950
2018.05.17 16:57:09.122 [ 160] -3.75750553631447475E+34 +0.00000 -1.14407317793544081E+25 +0.00000 +0.00000
2018.05.17 16:57:09.122 [ 165] 0.00000 1.00636449569426391E+31 +0.00000 1.00745736463519553E+31 +0.00000
2018.05.17 16:57:09.122 [ 170] 0.00000 0.00000 0.00000 +0.00000 +0.00000
2018.05.17 16:57:09.122 [ 175] -0.00000 -nan -0.00000 4.66067614346858278E+26 -0.00000
2018.05.17 16:57:09.122 [ 180] 101861180833792.00000 -5438716.50000 -0.00000 -0.00000 0.00392
2018.05.17 16:57:09.122 [ 185] 2.20188484451444982E+19 -0.00000 -0.00000 -0.00000 -1.36779461243699200E+17
2018.05.17 16:57:09.122 [ 190] -0.00000 -0.00000 2.78185773515439493E+26 572.76062 5379800432640.00000
2018.05.17 16:57:09.122 [ 195] 5.03024135461499105E+29 4.89968494738145280E+18 -0.00000 1.41897647324680016E+25 -0.00000
2018.05.17 16:57:09.122 [ 200] +0.00000 2.29293931121773089E+33 +0.00000 -0.00000 -1024160384.00000
2018.05.17 16:57:09.122 [ 205] +0.00000 -8.51650283897900189E+27 -1.70224724395179630E+27 -1336.28491 -0.37853
2018.05.17 16:57:09.122 [ 210] 9.31834169399695114E+20 215.54121 -30563845013504.00000 -0.00006 +0.00000
2018.05.17 16:57:09.122 [ 215] -58.68730 -4.70151723484777573E+27 -4.93228151330119772E+22 -683407008858112.00000 -2.40153189121636035E+23
这是MQL5语言的 CustomIndicator -indicator,我正在尝试使用OpenCL减少GPU对CPU的处理 .
上面的数字清楚地表明我错过了返回数组的变量的分配 .
请稍微看看,并建议我可能的出路,以便我可以获得GPU计算指标 .
EDITED :
其中一个重要的代码:
#define CUDA_CORE 2
int c = 1;
ArrayFill(work,0,CUDA_CORE,c);
//ArrayInitialize(offset,0);
int enter = -c;
for (int i =0; i < CUDA_CORE; i++)
{
offset[i] = enter + c;
enter = offset[i];
}