cuda中关于占用率的计算

官方文档CUDA C++ Best Practices Guide中提到一个例子:对于7.0的设备,每个multiprocessor有65536个寄存器,且支持最大的并发线程束为64。要想每个multiprocessor达到100%的占用率,意味着每个线程最多能使用32个寄存器。可以使用官方提供的NVIDIA GPU Computing Toolkit\CUDA\v11.1\tools目录下的CUDA_Occupancy_Calculator.xls来计算相关参数。

For purposes of calculating occupancy, the number of registers used by each thread is one of the key factors. For example, on devices of compute capability 7.0 each multiprocessor has 65,536 32-bit registers and can have a maximum of 2048 simultaneous threads resident (64 warps x 32 threads per warp). This means that in one of these devices, for a multiprocessor to have 100% occupancy, each thread can use at most 32 registers. However, this approach of determining how register count affects occupancy does not take into account the register allocation granularity. For example, on a device of compute capability 7.0, a kernel with 128- thread blocks using 37 registers per thread results in an occupancy of 75% with 12 active 128-thread blocks per multi-processor, whereas a kernel with 320-thread blocks using the same 37 registers per thread results in an occupancy of 63% because only four 320-thread blocks can reside on a multiprocessor. Furthermore, register allocations are rounded up to the nearest 256 registers per block on devices with compute capability 7.0.

  1. 如果使用128 size的线程块(每个线程使用37个寄存器),会有12个活跃线程块/SM,从而有12*4(128/32,线程束/SM) = 48活跃线程束/SM,那么占用率为48/64=75%。
  2. 如果使用320 size的线程块(每个线程使用37个寄存器),会有4个活跃线程块/SM, 从而有4*10(320/32,线程束/SM) = 40活跃线程束/SM,那么占用率为40/64=62.5%。

这里最重要的数据是每个SM上的活跃线程块,这个数值受两个方面的资源限制,一个是寄存器资源,一个是共享内存的资源。

每个线程块使用128个线程
1

每个线程块使用320个线程
2

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值