Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing array to function parameter in OpenCL

Tags:

arrays

opencl

How do I pass array into a function in OpenCL? I got error "..argument of type "_global float *" is incompatible with 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?
}

My edited source code:

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?
}
like image 251
Ina Ira Avatar asked Jun 14 '12 08:06

Ina Ira


1 Answers

It's as stated in the error message. your myArray and Key comes with the type global and read-only, thus you have to declare the same type when passing it to another function. In short your FindIndexFromArray should be

FindIndexFromArray(global read_only float* myArray, global read_only float* Key)
like image 138
ardiyu07 Avatar answered Oct 10 '22 08:10

ardiyu07