 //#define THR_N  ${THR_N}
 //#define THR_M  ${THR_M}
 
+#define fetch(arr, col, m, n, bound) arr[min(n*col + m, bound)]
+
 
 extern "C" __global__
 void sgemm(

    for (n = 0; n < BLK_K; n += DIM_YA) {
        #pragma unroll
        for (m = 0; m < BLK_M; m += DIM_XA) {
            sA[n + idyA][m + idxA] = offs_dA[n * M + m];
        }
    }
    // blockwise transpose to transpose load

        for (n = 0; n < BLK_K / DIM_YA; n++) {
            #pragma unroll
            for (m = 0; m < BLK_M / DIM_XA; m++) {
                ra[n][m] = fetch(offs_dA, M, m * DIM_XA, n * DIM_YA, boundA);
            }
        }

