cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

scharupa
Staff

Kernal code for simple searching logic(max value)

Hi,

 

Could please help me how to write below c programm in opencl kernal. I tried different scenarios but nothing worked.

int A[5], temp=0, i;

//scanning A[5] values from user///

for(i=0; i>5; i++)

{ if(A>max){

max=A;}

}

printf("%d", max);

 

Could you please some give me opencl kernal for the same logic

0 Likes
5 Replies
nou
Exemplar

look into reduction example or search parallel reduction algorithm.

0 Likes
mishka_p
Journeyman III

Hi

Look at "AMD Accelerated Parallel Processing" pdf document, latest version. On page 1-29 is the code for finding the minimum. I think it will help you.

0 Likes

Thanks for your support.

 

I got the logic. We need to print K[4] from below kernal which gives larest values.

here is the kernel:

__kernel
void vecadd(__global int *A,
            __global int *B,
            __global int *K) {

   int idx = get_global_id(0);
 int x=0;
    for(int i=4; i>0; i--)
    {
           if(A[idx]>x)
            {
             x=A[idx];   K[idx]=x;
            }
            else { K[idx]=x;}
               A[idx]=A[idx++];  
    }
        
   }

0 Likes

Sorry, we dont need "__global int *B" in the kernal.

0 Likes

why do you decrease? on GPU accessing memory in reverse can have some serious speed penalty

0 Likes