I wrote a little code to flip the dimensions of a matrix. It compiled and ran but the values were not changed.
After playing around with it for a little bit, I found that using “if (b_idx<N && a_idx<N)” or “if (b_idx<N)” instead of “if (a_idx<N)” worked.
Can anybody explain why this would happen?
Code that didn’t work:
global void shiftDimOnDevice_float(float *a, float *b, int N, int width, int height)
{
int row = blockIdx.y * blockDim.y + threadIdx.y;
int col = blockIdx.x * blockDim.x + threadIdx.x;
int a_idx = rowwidth + col;
int b_idx = colheight+row;
if (a_idx<N) {
b[b_idx] = a[a_idx];
}
}