8

如何将数组传递给 OpenCL 中的函数?我收到错误“..argument of type "_global float *" is incompatible with type of parameter of type "float *" in line 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?
}
4

1 回答 1

3

如错误消息中所述。你的myArrayandKey带有类型globaland read-only,因此你必须在将它传递给另一个函数时声明相同的类型。简而言之,你FindIndexFromArray应该是

FindIndexFromArray(global read_only float* myArray, global read_only float* Key)
于 2012-06-14T22:14:54.617 回答