NSight Compute - 预计银行冲突但未检测到任何

如何解决NSight Compute - 预计银行冲突但未检测到任何

我试图检测矩阵转置内核的共享内存库冲突。第一个内核进行矩阵转置没有填充,因此应该有bank冲突,而第二个内核使用padding,应该没有bank冲突。

但是,在内存工作负载部分使用 NSight Compute 进行分析显示两个内核的存储体冲突为 0。

Shared memory workload statistics,baseline being the kernel without padding

我将内核实现为这样的设备功能

// 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。

真的没有银行冲突,还是完全是其他原因造成的?我可以使用其他部分的哪些其他信息来确定是否可能存在银行冲突?

解决方法

对于 32x32 的块尺寸,我不希望任何一个内核都表现出银行冲突。银行冲突包含在 many resources 中,包括 cuda 标签上的 many questions,因此我将简要总结一下。

当同一 warp 中的两个或多个线程(并且在同一条指令期间)执行共享加载或共享存储时,会出现 Bank 冲突,其中这两个线程引用的位置在同一 bank 但不相同位置。

一个 bank 可以粗略地描述为共享内存中的一列,当共享内存被认为是一个 2D 数组,宽度为 32 个 bank 乘以每个 bank 32 位的数量,即宽度为 128 字节。

>

这些定义应提供相当完整的理解并涵盖大多数感兴趣的情况。我们可以从中得出一个观察结果,即对于全局内存合并加载/存储很好地工作的相同访问模式(相邻线程访问内存中的相邻元素)也可以很好地避免组冲突。 (这不是唯一适用于共享内存的模式,但它是一种规范模式。)

转向你的代码,然后:

  1. 您已经(正确地)指出您不希望在第一个代码中出现共享银行冲突。该代码中的共享负载:

     = tile[local_y][local_x];
    

    threadIdx.x(或包含 threadIdx.x 且没有任何乘法因子的索引)作为最后一个下标,这是CUDA 中用于“nice”访问的规范模式.它表示相邻线程将从内存中的相邻位置读取。这对全局内存和共享内存都适用。

    对于共享商店:

    tile[local_x][local_y] = 
    

    乍一看,这似乎是跨经线的“列式”访问,对 CUDA(无论是全局还是共享)来说是典型的错误,但您正在使用 shared memory offset-the-columns-by-1 trick

    __shared__ value_type tile[BLOCK_WIDTH][BLOCK_WIDTH+1];
                                                       ^^
    

    这样的情况也得到处理/排序。对于 32x32 块配置(每个经线中的所有 32 个线程将具有单调递增的 threadIdx.xconstant threadIdx.y),此处预计不会发生 bank 冲突。

  2. 对于第二个代码,只有一种索引模式用于共享存储和共享加载:

    input_tile[shared_index]=
    = input_tile[shared_index];
    

    即:

    auto shared_index = threadIdx.y*blockDim.x+threadIdx.x;
    

    因此,要回答这种情况下的银行冲突问题,我们只需要研究一种访问模式。让我们看看我们是否可以走同样的捷径。索引模式是否包含 threadIdx.x 且没有乘法因子(在最后一个下标中)? 是的。因此,warp 中的相邻线程将访问内存中的相邻位置,这是一种典型的良好模式,即没有 bank 冲突。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res