在OpenCL中将数组传递给函数参数

时间:2012-06-14 08:29:25

标签: arrays opencl

如何将数组传递给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?
}

1 个答案:

答案 0 :(得分:3)

如错误消息中所述。您的myArrayKey带有globalread-only类型,因此在将其传递给另一个函数时必须声明相同的类型。简而言之,FindIndexFromArray应为

FindIndexFromArray(global read_only float* myArray, global read_only float* Key)