Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Journeyman III

What is the best approach for writing a kernel for the following task

I need to compute a function f(x,y, z, c1, c2) where x, y, z are vectors and c1 and c2 are constants and I need to repeat this calculus for many values of c1 and c2 (which are already known and with the same dimension). My question is: what is the most efficient way to write down this into an OpenCL kernel?

Sequential algorithm would be as follows:

for (int i = 0; i < c1.length;i++)


  for(int j = 0;j < x.length;j++)


     f = x * cos(y + z) / (c1 + c2);



Thanks in advance.

1 Reply

something like this

__kernel void my_kernel(__global int *x,__global int *y,__global int *z,__global int *c1, __global int *c2, __global int *f)


     int i = get_global_id(0);

     int j = get_global_id(1);

     int w = get_gloval_size(0);

     f[i*w+j] = x * cos(y + z) / (c1 + c2);


just look for some tutorials on OpenCL.