gpt4 book ai didi

c++ - 嵌套 opencl 的内核函数

转载 作者:太空宇宙 更新时间:2023-11-04 02:36:32 29 4
gpt4 key购买 nike

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

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

最佳答案

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

您应用中的关键问题只是 0.0f float 。

您还可以执行一个由两个内核调用的单独函数。其中之一只是函数的包装器。

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

关于c++ - 嵌套 opencl 的内核函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36494470/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com