reg kernel function(linear search)

__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

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…