OpenCL的用户定义的内联函数 [英] OpenCL user defined inline functions
本文介绍了OpenCL的用户定义的内联函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以定义自己的职能的OpenCL code,以使内核可以打电话给他们吗?这是的,我在这里可以看到一些简单的例子?
Is it possible to define my own functions in OpenCL code, in order that the kernels could call them? It yes, where can I see some simple example?
推荐答案
用于创建程序的功能是...
Function used to create program is ...
cl_program clCreateProgramWithSource (
cl_context context,
cl_uint count,
const char **strings,
const size_t *lengths,
cl_int *errcode_ret)
您可以将在字符串函数内部参数是这样,
You can place functions inside the strings parameter like this,
float AddVector(float a, float b)
{
return a + b;
}
kernel void VectorAdd(
global read_only float* a,
global read_only float* b,
global write_only float* c )
{
int index = get_global_id(0);
//c[index] = a[index] + b[index];
c[index] = AddVector(a[index], b[index]);
}
现在你有一个用户自定义函数AddVector的内核函数VectorAdd
Now you have one user defined function "AddVector" and a kernel function "VectorAdd"
这篇关于OpenCL的用户定义的内联函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文