为opencl嵌套内核函数
Nesting kernel functions for opencl
我有一个相当复杂的mql5 for循环代码集,需要通过opencl运行。这意味着我需要能够让一些内核函数调用其他函数。因此,我尝试了这个简单的代码,当我通过它调用另一个函数时,它无法创建程序(错误5105)。为什么?
const string _cl_source=
" rn"
" rn"
"__kernel void Tester() rn"
"{ rn"
" rn"
" float _margin = 10f; rn"
" float _balance = 10f; rn"
" float _equity = 10f; rn"
" float _openprice = 10f; rn"
" float _closeprice = 10f; rn"
" float _position = 10f; rn"
" rn"
/*fails on adding this line*/" CouponReset(_margin,_balance,_equity,_openprice,_closeprice,_position);rn"
" rn"
"} rn"
" rn"
" rn"
"__kernel void CouponReset(float margin, rn"
" float balance, rn"
" float equity, rn"
" float openprice, rn"
" float closeprice, rn"
" float position) rn"
"{ rn"
" position = 0f; rn"
" openprice = 0f; rn"
" closeprice = 0f; rn"
" balance = equity; rn"
" margin = balance; rn"
" rn"
"} rn"
" rn";
EDIT:实际上,我已经看过了,可以从另一个内核调用内核。但是,您不应该这样做,因为这可能会导致以后出现问题(特别是如果您使用__local
内存)。
应用程序中的关键问题只是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);
}
相关文章:
- CUDA内核和数学函数的显式命名空间
- 将 2D 推力::d evice_vector 复矩阵传递给 CUDA 内核函数
- 为什么将函数传递给内核会导致数据变得不可变?
- 带有大结构变量的 CUDA 内核函数给出了错误的结果
- 是否可以从 CUDA 10.1 内核调用 cuBLAS 或 cuBLASLt 函数?
- 如何将函数作为CUDA内核参数传递
- 如何在 CUDA 中的内核函数中乘以两个 openCV 矩阵?
- 调用共享C++函数时 Python 内核崩溃
- 函数成员作为 CUDA 内核的参数
- 通过复制将对象传递给 CUDA 内核会调用其析构函数并过早释放内存
- Ubuntu,如何找到内核工作繁重的程序热点?似乎kernel.kallsyms上的函数没有标记为用户空间函数的子级
- 如何存储CUDA内核函数的Bool结果
- CUDA内核作为类的成员函数
- 为什么调用 CUDA 内核函数时这个类成员变量没有改变
- 如何在内核中定义/使用函数
- 具有虚拟继承传递到CUDA内核函数的对象
- C++ std::future在单独的内核上运行每个函数
- 为opencl嵌套内核函数
- 在CUDA中编写内核函数的正确方法
- 从 HANDLE 到 HINSTANCE 的转换无效(获取内核函数的地址)