sarkanydavidhu

Kernel Example

Mar 10th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. __kernel void vector_add_gpu (__global const float* src_a,
  2.                      __global const float* src_b,
  3.                      __global float* res,
  4.            const int num)
  5. {
  6.    /* get_global_id(0) returns the ID of the thread in execution.
  7.    As many threads are launched at the same time, executing the same kernel,
  8.    each one will receive a different ID, and consequently perform a different computation.*/
  9.    const int idx = get_global_id(0);
  10.  
  11.    /* Now each work-item asks itself: "is my ID inside the vector's range?"
  12.    If the answer is YES, the work-item performs the corresponding computation*/
  13.    if (idx < num)
  14.       res[idx] = src_a[idx] + src_b[idx];
  15. }
Advertisement
Add Comment
Please, Sign In to add comment