【发布时间】:2021-07-19 20:45:46
【问题描述】:
我试图检测矩阵转置内核的共享内存库冲突。第一个内核在没有填充的情况下执行矩阵转置,因此应该有存储库冲突,而第二个内核使用填充,应该没有存储库冲突。
但是,在内存工作负载部分使用 NSight Compute 进行分析显示两个内核的存储库冲突为 0。
我将内核实现为像这样的设备功能
// tiled, with padding (expecting no bank conflicts)
template <class value_type, class container_type = value_type*>
__device__
void
transpose_padded(container_type m1, container_type m2, size_t width)
{
__shared__ value_type tile[BLOCK_WIDTH][BLOCK_WIDTH+1];
// BLOCK_WIDTH = 32, global scope constant
auto row = blockDim.y*blockIdx.y + threadIdx.y;
auto col = blockDim.x*blockIdx.x + threadIdx.x;
auto index = row * width + col;
auto tr_row = blockDim.y * blockIdx.x + threadIdx.y;
auto tr_col = blockDim.x * blockIdx.y + threadIdx.x;
auto tr_index = tr_row * width + col;
auto local_x = threadIdx.x;
auto local_y = threadIdx.y;
tile[local_x][local_y] = m1[index];
__syncthreads();
if (tr_row < width && tr_col < width)
{
m2[tr_index] = tile[local_y][local_x];
}
return;
}
// tiled, without padding (expecting bank conflicts)
template <class value_type, class container_type = value_type*>
__device__
void
transpose_tiled(container_type input, container_type output, size_t width)
{
// assuming square blocks
extern __shared__ value_type input_tile[];
auto row = blockDim.y*blockIdx.y + threadIdx.y;
auto col = blockDim.x*blockIdx.x + threadIdx.x;
auto matrix_index = row*width + col;
auto tr_row = col;
auto tr_col = row;
auto tr_index = tr_row*width + tr_col;
// coalesced global memory access
auto shared_index = threadIdx.y*blockDim.x+threadIdx.x;
input_tile[shared_index]= input[matrix_index];
__syncthreads();
if (tr_row < width && tr_col < width)
output[tr_index] = input_tile[shared_index];
return;
}
我使用的输入矩阵的尺寸为 100x100。在两个内核中,块大小都是 32x32 线程。实例化的值类型为 double。
真的没有银行冲突,还是完全由其他原因引起的?我可以使用其他部分的哪些其他信息来确定是否存在银行冲突?
【问题讨论】:
-
银行冲突取决于执行参数和类型。一些未实例化的模板没有说明可能发生或可能不会发生的事情
-
我编辑了实例化和内核启动的细节。还有什么我应该补充的来改进这个问题吗?
-
Are there really no bank conflicts您的任何一个内核都不应显示 32x32 块大小的存储库冲突。分析器是正确的。由于您在第二个代码中有注释expecting bank conflicts,也许您应该解释一下您的理由。
标签: c++ cuda gpu profiling nsight