CUDA如何选取Blocks和Threads

Blocks

  1. 早期的卡,最多支持65535个blocks, 后面的卡最多可以支持 2 31 − 1 = 2147483647 2^{31}-1=2147483647 2311=2147483647

可以理解为blocks可以随便造,主要是要把threads的大小选好

Threads

  1. 一般来讲每一个block不能超过512(Compute Capability 1.x)/ 1024(2.x和之后版本)个线程

你电脑不旧的话,一般都是不超过1024

  1. 每个块的线程数应该是warp size大小的整数倍,在所有当前的硬件上,warp size大小是32。

比如我的电脑:
Device : “GeForce RTX 2080 Ti”
driverVersion : 10010
runtimeVersion : 10000
CUDA Driver Version / Runtime Version 10.1 / 10.0
CUDA Capability Major/Minor version number : 7.5
Total amount of global memory : 10.73 GBytes (11523260416 bytes)
GPU Clock rate : 1545 MHz(1.54 GHz)
Memory Clock rate : 7000 Mhz
Memory Bus Width : 352-bit
L2 Cache Size: 5767168 bytes
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp Size: 32
Maximum number of threads per multiprocessor: 1024
Maximum number of thread per block: 1024
Maximum sizes of each dimension of a block: 1024 x 1024 x 64
Maximum sizes of each dimension of a grid: 2147483647 x 65535 x 65535

一般来讲都是32,你也可以那个用一下代码测试一下:

#include <stdio.h>

int main(void) {
        cudaDeviceProp deviceProp;
        if (cudaSuccess != cudaGetDeviceProperties(&deviceProp, 0)) {
                printf("Get device properties failed.\n");
                return 1;
        } else {
                printf("The warp size is %d.\n", deviceProp.warpSize);
                return 0;
        }
}
  1. threads太小(32)或者太大(512)都不好,经验来讲,最好选择128 threads/256 threads 为好
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老实人小李

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值