PDA

View Full Version : reg kernel function(linear search)



paviraj_1989
03-21-2011, 12:16 PM
__kernel void lin_search (__global const float *a,float c,int pos)
{
int tid = get_global_id(0);
if(c==a[tid])
pos=(tid+1)
};

Is this function is right for searching an element using linear search?

praveenraj

chai
03-21-2011, 02:36 PM
Almost! You need to get the output through a buffer, however. Actually, I'm not sure if this is the only way, but definitely the standard:



__kernel void lin_search (__global const float *a,float c,__global unsigned int *pos)
{
int tid = get_global_id(0);
if(c==a[tid])
pos[0]=(tid+1);
};


EDIT: if the search returns true for more than one element, you have a data-racing issue, however...