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
look into reduction example or search parallel reduction algorithm.
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.
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++];
}
}
Sorry, we dont need "__global int *B" in the kernal.
why do you decrease? on GPU accessing memory in reverse can have some serious speed penalty