Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
To obtain data resume from results like following code:
int k = get_global_id(0);
double result=d[k]*d[k];

It must be used reductions that is very difficult to perform and reduces the code cleariness as said in following link:
http://developer.amd.com/resources/articles-whitepapers/opencl-optimization-case-study-simple-reductions/"]http://developer.amd.com/resources/articles-whitepapers/opencl-optimization-case-study-simple-reductions

So it would be an advantage that the opencl had a command to do it (also over kuda)

What I have tried:

This is the smaller working code I made to make reductions:
if (k==0)
{
    int size=HEIGHT;
    while(size>1)
    {
        barrier(CLK_GLOBAL_MEM_FENCE ); //to give time to all rms[k] of the level be filled
        rms[size]=0.0f;size=(1+size)/2;
        rms[k]+=rms[k+size];
    }
}
barrier(CLK_GLOBAL_MEM_FENCE ); //to give time to all rms[k] be filled
media=rms[0]/(float) WIDTH/(float) HEIGHT;
Posted
Updated 31-Aug-17 0:52am

1 solution

OpenCL 2.0 already has reductions for thread groups.

C++
work_group_reduce_add()

this command adds all participant threads' elements into single value and broadcasts it to all participant threads.

Its execution time will be comparable to an optimized custom algorithm so it can get automatically upgraded for speed, depending on the hardware vendor's implementation of these functions.

You can say "just workgroup scope is not enough" but whole thing about OpenCL and CUDA is breaking a work into smaller pieces and computing them in parallel. You could use these functions to compute a global sum reduction with good enough performance.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900