如何将数组传递给OpenCL中的函数?我得到错误“..argument of type”_global float *“与行中的”float *“类型的参数不兼容 c [n] = FindIndexFromArray(a,3);
float FindIndexFromArray(float myArray[], float Key)
{
// simple looping to find the index
for (int i=0;i<sizeof(myArray);i++)
if (myArray[i]==Key)
return i;
}
kernel void ProcessArray(
global read_only float* myArray,
global read_only float* Key,
global write_only float* c )
{
int index = get_global_id(0);
c[index] = FindIndexFromArray(myArray, Key); // How do I pass myArray parameter?
}
我编辑的源代码:
float FindIndexFromArray(__global read_only float* myArray[], __global read_only float* Key)
{
// simple looping to find the index
for (int i=0;i<sizeof(myArray);i++)
if (myArray[i]==Key)
return i;
}
kernel void ProcessArray(
__global read_only float* myArray,
__global read_only float* Key,
__global write_only float* c )
{
int index = get_global_id(0);
c[index] = FindIndexFromArray(myArray, Key); // How do I pass myArray parameter?
}
答案 0 :(得分:3)
如错误消息中所述。您的myArray
和Key
带有global
和read-only
类型,因此在将其传递给另一个函数时必须声明相同的类型。简而言之,FindIndexFromArray
应为
FindIndexFromArray(global read_only float* myArray, global read_only float* Key)