简体   繁体   English

CUDA 块和线程与 SMP 之间的关系

[英]Relation Between CUDA Blocks and Threads and SMPs

I recently read this CUDA tutorial: https://developer.nvidia.com/blog/even-easier-introduction-cuda/ and one thing was unclear.我最近读了这个 CUDA 教程: https://developer.nvidia.com/blog/even-easier-introduction-cuda/有一件事不清楚。 When we sum two vectors we divide the task into several blocks and threads to do this in parallel.当我们将两个向量相加时,我们将任务分成几个线程以并行执行此操作。 My question is why then the number of blocks (and maybe threads) doesn't depend on physical properties of GPU, the number of physical SMPs and threads?我的问题是为什么块(可能还有线程)的数量不取决于 GPU 的物理属性、物理 SMP 和线程的数量?

For example let's say GPU has 16 SMPs and each of them can run 128 threads, will it be faster to split the problem into 16 blocks by 128 threads or, like in the article, split by 4000 blocks with 256 threads?例如,假设 GPU 有 16 个 SMP,每个 SMP 可以运行 128 个线程,将问题分成 16 个块乘 128 个线程,或者像文章中那样,将问题分成 4000 个块和 256 个线程会更快吗?

It does not depend because the number of threads will depend mainly on your problem size and the block size will depend on your GPU architecture.它不依赖,因为线程数主要取决于您的问题大小,而块大小将取决于您的 GPU 架构。 For example, if your GPU has 3000 cores and can have blocks of a maximum of 512, and your code will process a matrix with a size of 2 billion, you will have to specify the "number of blocks X number of threads per block(which is not greater than 512)" that will be EQUAL or GREATER than 2 billion, then CUDA will smartly partition your blocks of threads into your 3000 CUDA cores of your GPU until all of the threads specified by the "numBLocks X numThreadsPerBlock" have been called by the GPU.例如,如果您的 GPU 有 3000 个内核并且最多可以有 512 个块,并且您的代码将处理一个大小为 20 亿的矩阵,则您必须指定“块数 X 每块线程数( which is not greater than 512)" that will be EQUAL or GREATER than 2 billion, then CUDA will smartly partition your blocks of threads into your 3000 CUDA cores of your GPU until all of the threads specified by the "numBLocks X numThreadsPerBlock" have been由 GPU 调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM