title: OpenCL - is it possible to invoke another function from within a kernel?
body: <p>I am following along with a tutorial located here: <a href="http://opencl.codeplex.com/wikipage?title=OpenCL%20Tutorials%20-%201" rel="noreferrer">http://opencl.codeplex.com/wikipage?title=OpenCL%20Tutorials%20-%201</a></p>
  
  <p>The kernel they have listed is this, which computes the sum of two numbers and stores it in the output variable:</p>
  
  <pre><code>__kernel void vector_add_gpu (__global const float* src_a,
                       __global const float* src_b,
                       __global float* res,
             const int num)
  {
     /* get_global_id(0) returns the ID of the thread in execution.
     As many threads are launched at the same time, executing the same kernel,
     each one will receive a different ID, and consequently perform a different computation.*/
     const int idx = get_global_id(0);
  
     /* Now each work-item asks itself: "is my ID inside the vector's range?"
     If the answer is YES, the work-item performs the corresponding computation*/
     if (idx &lt; num)
        res[idx] = src_a[idx] + src_b[idx];
  }
  </code></pre>
  
  <p>1) Say for example that the operation performed was much more complex than a summation - something that warrants its own function.  Let's call it ComplexOp(in1, in2, out).  How would I go about implementing this function such that vector_add_gpu() can call and use it?  Can you give example code?</p>
  
  <p>2) Now let's take the example to the extreme, and I now want to call a generic function that operates on the two numbers.  How would I set it up so that the kernel can be passed a pointer to this function and call it as necessary?</p>