Hi everyone,
My graphics card is an RTX 4070 Super.
I ran into a problem while studying CUDA NCU analysis. When analyzing blocked matrix multiplication, I can’t understand how NCU calculates the Shared Load Bank Conflicts, mainly regarding the code below. This piece of code is taken from the blocked matrix multiplication and simplified to make it easier to understand.
#define TM 8
#define TK 8
#define BM 128
#define BK 128
#define BN 8
// The blocksize is 16*16
const int tx = threadIdx.x; // 0~15
const int ty = threadIdx.y; // 0~15
const int bx = blockIdx.x;
const int by = blockIdx.y;
const int tid = ty * blockDim.x + tx;
int tCx = tid % 16; // 0~15
int c_col = tCx * TK;
__shared__ float Bs[BN][BK];
float c_val[TM][TK] = { {0.0f} };
for (int n = 0; n < BN; n++) {
for (int k = 0; k < TK; k++) {
c_val[n][k] += Bs[n][c_col + k];
}
}
For a warp with 32 threads, the c_col indices are 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, the Bank indices are
(n*128 + k)%32 = k
(n*128 + k+8)%32 = k + 8
(n*128 + k+16)%32 = k + 16
(n*128 + k+24)%32 = k + 24
(n*128 + k+32)%32 = k
…
(n*128 + k+120)%32 = k + 24
So each read only touches four banks, with 8 threads reading from each bank. I understand this as an 8-way conflict, so Bank Conflicts = 8-1 = 7, and since the loop runs 64 times, the total Bank Conflicts should be 448. But the NCU result shows only 64, I feel like I have a misunderstanding about bank conflict, but I can’t pinpoint exactly what’s wrong.
I would really appreciate it if I could get any answers or any hints about information related to this topic.
Best,
LiTian

