OpenCL only offers access to single dimensional arrays using the C99 specs. My problem however is in two dimensions and I am using two dimensional arrays on the host side
Rather than making my code less readable by calculating indices, I would like to use a C macro to get element A[i][j]
. Unfortunately I'm rather bad at this and have little experience in C. I think I have the general idea of how it is done, but if someone could critique it would be appreciated.
It would be something like:
#define 2d_access(u, y, x) (u[y][x])
where u is the matrix, y is the row, and x is the column and the macro would return the
value at u[y][x]
The matrix is allocated statically so the macro would have a WIDTH component.
#define 2d_access(u, y, x) (u[y * WIDTH] + x])