Passing an array to a function parameter in OpenCL

How to pass an array to a function in OpenCL? I got the error ".. argument of type" _global float * "is incompatible with the parameter of type" float * "in the string 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? } 
+7
source share
1 answer

As indicated in the error message. your myArray and Key are of type global and read-only , so you must 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) 
+2
source

All Articles