Parallel execution is not performed OpenCL MQL5

偶尔善良 提交于 2019-12-25 01:06:28

问题


I have created a kernel of the OpenCL in Mql5.
Here is the code:

const string cl_src = 
    //"  int weightsum;                                               \r\n"
    " #pragma OPENCL EXTENSION cl_khr_fp64 : enable                          \r\n"
    "__kernel void CalculateSimpleMA(                                       \r\n"
        "int rates_total,                                \r\n"
        "int prev_calculated,                           \r\n"
        "int begin,                                      \r\n"
        "int InpMAPeriod,                                \r\n"
        "__global double *price,                         \r\n"
        "__global double *ExtLineBuffer                  \r\n"
        ")                                               \r\n"
    "{                                                                 \r\n"
        "int i,limit;                                                  \r\n"
        "int len_price = get_global_id(4);                                     \r\n"
        //"int len_Ext = get_global_id(5);                                     \r\n"

        " if(prev_calculated==0)// first calculation                       \r\n"
        " {                                                                \r\n"
            "limit=InpMAPeriod+begin;                                      \r\n"   
            "for(i=0;i<limit-1;i++) ExtLineBuffer[i]=0.0;                  \r\n"     
            "double firstValue=0;                                          \r\n"
            "for(i=begin;i<limit;i++)                                      \r\n"
            "firstValue+=price[i];                                         \r\n"
            "firstValue/=InpMAPeriod;                                      \r\n"
            "ExtLineBuffer[limit-1]=firstValue;                            \r\n"
        "}                                                             \r\n"
        "else limit=prev_calculated-1;                                  \r\n"
        "for(i=limit;i<rates_total;i++)                                \r\n"
            "ExtLineBuffer[i]=ExtLineBuffer[i-1]+(price[i]-price[i-InpMAPeriod])/InpMAPeriod;\r\n"
    "}                                                                  \r\n"
    "                                                                          \r\n"                            
    "__kernel void CalculateEMA(                                            \r\n"
        "int rates_total,                                  \r\n"
        "int prev_calculated,                              \r\n"
        "int begin,                                        \r\n"
        "int InpMAPeriod,                                  \r\n"
        "__global double *price,                           \r\n"
        "__global double *ExtLineBuffer                    \r\n"
    ")                                                    \r\n"
    "{                                                                \r\n"
        "int    i,limit;                                               \r\n"
        "double SmoothFactor=2.0/(1.0+InpMAPeriod);                    \r\n"
        "if(prev_calculated==0)                                        \r\n"
        "{                                                             \r\n"
            "limit=InpMAPeriod+begin;                                      \r\n"
            "ExtLineBuffer[begin]=price[begin];                            \r\n"
            "for(i=begin+1;i<limit;i++)                                    \r\n"
                "ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor); \r\n"
        "}                                                             \r\n"
        "else limit=prev_calculated-1;                                 \r\n"
        "for(i=limit;i<rates_total;i++)                                \r\n"
            "ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor); \r\n"
    "}                                                                 \r\n"
    "                                                                          \r\n"

    "__kernel void CalculateLWMA(                                           \r\n"
        "int rates_total,                                 \r\n"
        "int prev_calculated,                             \r\n"
        "int begin,                                       \r\n"
        "int InpMAPeriod,                                 \r\n"
        "__global double *price,                          \r\n"
        "__global double *ExtLineBuffer                   \r\n"

    ")                                                 \r\n"
    "{                                                              \r\n"
        "int        i,limit;                                           \r\n"
        "int        weightsum;                                          \r\n"   
        "double     sum;                                               \r\n"
        "if(prev_calculated==0)                                        \r\n"
        "{                                                             \r\n"                                   
            "weightsum=0;                                                  \r\n"
            "limit=InpMAPeriod+begin;                                      \r\n"
            "for(i=0;i<limit;i++) ExtLineBuffer[i]=0.0;                    \r\n"
                 "double firstValue=0;                                         \r\n"
                "for(i=begin;i<limit;i++)                                      \r\n"
                "{                                                             \r\n"
                    "int k=i-begin+1;                                          \r\n"
                    "weightsum+=k;                                             \r\n"
                    "firstValue+=k*price[i];                                   \r\n"
                "}                                                             \r\n"
                "firstValue/=(double)weightsum;                                \r\n"
                "ExtLineBuffer[limit-1]=firstValue;                            \r\n"
            "}                                                             \r\n"
            "else limit=prev_calculated-1;                                 \r\n"
            "for(i=limit;i<rates_total;i++)                                \r\n"
            "{                                                             \r\n"
                "sum=0;                                                        \r\n"
                "for(int j=0;j<InpMAPeriod;j++) sum+=(InpMAPeriod-j)*price[i-j];\r\n"
                "ExtLineBuffer[i]=sum/weightsum;                               \r\n"
            "}                                                             \r\n"
        "}                                                                \r\n"
   "                                                                           \r\n"                            
   "__kernel void CalculateSmoothedMA(                                     \r\n"
        "int rates_total,                                 \r\n"
        "int prev_calculated,                             \r\n"
        "int begin,                                       \r\n"
        "int InpMAPeriod,                                 \r\n"
        "__global double *price,                          \r\n"
        "__global double *ExtLineBuffer                   \r\n"
    ")                                                 \r\n"
    "{                                                              \r\n"
        "int i,limit;                                                  \r\n"
        "if(prev_calculated==0)                                        \r\n"
        "{                                                             \r\n"
            "limit=InpMAPeriod+begin;                                      \r\n"
            "for(i=0;i<limit-1;i++) ExtLineBuffer[i]=0.0;                  \r\n"
            "double firstValue=0;                                          \r\n"
            "for(i=begin;i<limit;i++)                                      \r\n"
                "firstValue+=price[i];                                        \r\n"
                "firstValue/=InpMAPeriod;                                      \r\n"
                "ExtLineBuffer[limit-1]=firstValue;                            \r\n"
        "}                                                             \r\n"
        "else limit=prev_calculated-1;                                 \r\n"
        "for(i=limit;i<rates_total;i++)                \r\n"
            "ExtLineBuffer[i]=(ExtLineBuffer[i-1]*(InpMAPeriod-1)+price[i])/InpMAPeriod;\r\n"
    "}                                                              \r\n";

While I am able to run this code, I am getting results but are not fast as expected with GPU as I am not able to utilize the cores or worker. I tried the following way to execute:

int  offset[2]={0,0};
int  work  [2]={1024,1024};         
if(!CLExecute(cl_krn,2,offset,work))
           Print("Kernel not executed",GetLastError());

But the program got error as OpenCl device not found.
Then I tried this:

int  offset[2]={0,0};
int  work  [2]={1024,1024};         
if(!CLExecute(cl_krn))
           Print("Kernel not executed",GetLastError());

And my code ran smoothly, but not with multiple cores.

What I can do to make the program work with multiple workers without fail.

EDITED

What platform? Did you install the proper OpenCL drivers? What is the output of clinfo?

Answer: I am using Windows 10 Pro. I have installed the latest OpenCL drivers from the Intel website. I guess the SDK what they give is what I have installed.
Here is the output of the clinfo: Gist of clinfo output

来源:https://stackoverflow.com/questions/50041120/parallel-execution-is-not-performed-opencl-mql5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!