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?
}
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With