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[i][j] = x[j] * cos(y[j] + z[j]) / (c1[i] + c2[i]);
}
}
Thanks in advance.
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[j] * cos(y[j] + z[j]) / (c1[i] + c2[i]); }
just look for some tutorials on OpenCL.