I am a newbie in OpenCL, followed some basic tutorial of matrices operation in OpenCL, but I hardly understand on how to implement some loop operations in C++ into OpenCL.
For a 2D array, the direct multiplication of matrix A x matrix A
will be implemented as:
__kernel void sum(
__global const float *a, __global float *g) {
const int size = 4;
int i = get_global_id(1);
int j = get_global_id(0);
float z = a_g[i];
g [i+size*j] = a[i+size*j] *a[i+size*j] ;
}
but what if I only want to multiply the elements in certain rows rather than the whole matrix?
for (int j=1; j < 4; j++){
for (int i=0; i < 4; i++){
P[0][j] += Z[i][0]*Z[i][j];
}
}
Says P is a 1D-array, where each element of P is the sum of multiplication of first element each row with all elements in the row of matrix Z. How can I address the first element in each row as denoted by Z[i][0]
and multiply with Z[i][j]
in OpenCL?
Thanks