Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can give you some hint as I was also facing similar problem. </p> <p>I can think of three different methods for achieving similar goal:</p> <p>Consider a simple kernel, assuming you launched 4 (0-3) threads </p> <pre><code>_kernel void addition (int *p) { int i = get_local_id(0); p[4]+= p[i]; } </code></pre> <p>You want to add values p[0], p[1], p[2], p[3], p[4], and store the final sum in p[4]. right? i.e:</p> <pre><code>p[4]= p[0] + p[1] + p[2] + p[3] + p[4] </code></pre> <p><strong>Method -1</strong> (no parallelism)</p> <p>Assign this job to only 1 thread (no parallelism):</p> <pre><code>int i = get_local_id(0); if (i==0) { p[4]+= p[i]; } </code></pre> <p><strong>Method-2</strong> (with parallelism)</p> <p>Express your problem as follows: </p> <pre><code>p[4]= p[0] + p[1] + p[2] + p[3] + p[4] + 0 </code></pre> <p>This is a reduction problem </p> <p>So launch 3 threads: i=0 to i=2. In first iteration </p> <pre><code> i=0 finds p[0] + p[1] i=1 finds p[2] + p[3] i=2 finds p[4] + 0 </code></pre> <p>Now you have three numbers, you apply the same logic as above and add these numbers (with suitable padding of 0 to make it in power of two) </p> <p><strong>Method -3</strong> Atomic operations</p> <p>If you still need to implement this atomically, you can use <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/atomic_add.html" rel="nofollow">atomic_add()</a>:</p> <pre><code> int fsfunc atomic_add ( volatile __global int *p ,int val) </code></pre> <blockquote> <p>Description</p> <p>Read the 32-bit value (referred to as old) stored at location pointed by p. Compute (old + val) and store result at location pointed by p. The function returns old.</p> </blockquote> <p>This is assuming the data is int type. Otherwise you can see the <a href="http://suhorukov.blogspot.co.uk/2011/12/opencl-11-atomic-operations-on-floating.html" rel="nofollow">link</a> as suggested above. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload