ssn
ssn

Reputation: 439

Nesting kernel functions for opencl

I have a fairly complex mql5 for-loop code set that I need to run via opencl. What this will mean is I need to be able to have some kernel functions calling others. I have therefore experimented with this simple code and it fails to create a program (error 5105) when I call another function through it. Why?

               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";

Upvotes: 1

Views: 393

Answers (1)

DarkZeros
DarkZeros

Reputation: 8410

EDIT:Actually, I reviewed it, and it is possible to call a kernel from another kernel. However you should not do it, since it may lead you to problems down the road (specially if you use __local memory).

The key problem in your app is just the 0.0f floats.

You can also do a separate function that is called by both kernels. And one of them is just a wrapper to the function.

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);                                         
} 

Upvotes: 2

Related Questions