2016-04-08 129 views
1

我有一个相当复杂的mql5 for-loop代码集,我需要通过opencl运行。这意味着我需要能够拥有一些调用他人的内核函数。因此,我试验了这个简单的代码,并且当我通过它调用另一个函数时,它无法创建程序(错误5105)。为什么?嵌套内核函数opencl

   const string _cl_source= 
       "              \r\n" 
       "              \r\n" 
       "__kernel void Tester()        \r\n" 
       "{              \r\n" 
       "              \r\n" 
       " float _margin = 10f;         \r\n" 
       " float _balance = 10f;        \r\n" 
       " float _equity = 10f;         \r\n" 
       " float _openprice = 10f;        \r\n" 
       " float _closeprice = 10f;        \r\n" 
       " float _position = 10f;        \r\n" 
       "              \r\n" 
/*fails on adding this line*/" CouponReset(_margin,_balance,_equity,_openprice,_closeprice,_position);\r\n" 
       "              \r\n" 
       "}              \r\n" 
       "              \r\n" 
       "              \r\n" 
       "__kernel void CouponReset(float margin,      \r\n" 
       "     float balance,      \r\n" 
       "     float equity,      \r\n" 
       "     float openprice,      \r\n" 
       "     float closeprice,      \r\n" 
       "     float position)    \r\n" 
       "{              \r\n" 
       " position = 0f;       \r\n" 
       " openprice = 0f;       \r\n" 
       " closeprice = 0f;       \r\n" 
       " balance = equity;       \r\n" 
       " margin = balance;       \r\n" 
       "              \r\n" 
       "}              \r\n" 
       "              \r\n"; 
+0

你可以把0.0f放在所有零的末尾吗? –

+0

好的,让我试试。 thx – ssn

+0

做到了这一点,仍然有相同的错误! – ssn

回答

2

编辑:其实,我回顾了它,它可以从另一个内核调用内核。但是你不应该这么做,因为它可能会导致你在路上遇到问题(特别是如果你使用内存)。

你的应用程序的关键问题只是0.0f浮游物。

你也可以做一个由两个内核调用的独立函数。其中之一只是该功能的封装。

void _CouponReset(float margin,      
        float balance,      
        float equity,      
        float openprice,      
        float closeprice,      
        float position)    
{              
    position = 0.0f;       
    openprice = 0.0f;       
    closeprice = 0.0f;       
    balance = equity;       
    margin = balance;           
} 


__kernel void Tester()         
{              

    float _margin = 10.0f;         
    float _balance = 10.0f;         
    float _equity = 10.0f;         
    float _openprice = 10.0f;        
    float _closeprice = 10.0f;        
    float _position = 10.0f;        

    _CouponReset(_margin,_balance,_equity,_openprice,_closeprice,_position); 

}  


__kernel void CouponReset(float margin,      
        float balance,      
        float equity,      
        float openprice,      
        float closeprice,      
        float position)    
{              
    _CouponReset(margin, balance, equity, openprice, closeprice, position);           
} 
+1

这个原因的很大一部分是因为在浮动数据的末尾包含'.0f'。谢谢 – ssn

+0

这不是简单的原因,DarkZeros重新排序函数声明,以便被调用者出现在调用者之前?尽管我可能会困惑自己是否可以从设备代码调用内核导出。 – Lee

+0

@是的,这是真的,但在保持该顺序时,我意识到我只需要两个函数,一个void另一个__kernel – ssn