Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relation between number of blocks of threads and cuda cores on machine (in CUDA C)

Tags:

cuda

I have CUDA 2.1 installed on my machine and it has a graphic card with 64 cuda cores. I have written a program in which I initialize simultaneously 30000 blocks (and 1 thread per block). But am not getting satisfying results from the gpu (It performs slowly than the cpu)

Is it that the number of blocks must be smaller than or equal to the number of cores for good performance? Or is it that the performance has nothing to do with number of blocks

like image 429
Pushpak Dagade Avatar asked Jun 13 '11 11:06

Pushpak Dagade


People also ask

What is the relationship between warps thread blocks and CUDA cores?

All the threads in a warp executes concurrently on the resources of the SM. The actual execution of a thread is performed by the CUDA Cores contained in the SM. There is no specific mapping between threads and cores. If a warp contains 20 thread, but currently there are only 16 cores available, the warp will not run.

How many blocks and threads CUDA?

CUDA architecture limits the numbers of threads per block (1024 threads per block limit). The dimension of the thread block is accessible within the kernel through the built-in blockDim variable.

How many threads can a CUDA core run?

CUDA Streaming Multiprocessor executes threads in warps (32 threads) There is a maximum of 1024 threads per block (for our GPU) There is a maximum of 1536 threads per multiprocessor (for our GPU)

Does number of CUDA cores matter?

More number of CUDA cores means more data can be processed parallelly. More clock speed means that a single core can perform much faster. The GPUs get better with new generations and architectures, so a graphic card with more number of CUDA cores is not necessarily more powerful than the one with lesser CUDA cores.


2 Answers

CUDA cores are not exactly what you might call a core on a classical CPU. Indeed, they have to be viewed as nothing more than ALUs (Arithmetic and Logic Units), which are just able to compute ready operations.

You might know that threads are handled per warps (groups of 32 threads) inside the blocks you've defined. When your blocks are dispatched on the different SMs (Streaming Multiprocessors, they are the actual cores of the GPU), each SM schedules warps within a block to optimize the computation time in regard of the memory access time needed to get threads' input data.

The problem is threads are always handled through their belonging warp, so if you have only one thread per block, the SM it is running on won't be able to schedule through warps and you won't take advantage of the multiple CUDA cores available. Your CUDA cores will be waiting for data to process, since CUDA cores compute far quicker than data are retrieved through memory.

Having lots of blocks with few threads is not what the GPU is awaiting. In this case, you face the block per SM limitation (this number depends on your device), which force your GPU to spend a lot of time to put blocks on SM and then remove them to treat the next ones. You should rather increase the number of threads in your blocks instead of the number of blocks in your application.

like image 174
jopasserat Avatar answered Jan 04 '23 11:01

jopasserat


The warp size in all current CUDA hardware is 32. Using less than 32 threads per block (or not using a round multiple of 32 threads per block) just wastes cycles. As it stands, using 1 thread per block is leaving something like 95% of the ALU cycles of your GPU idle. That is the underlying reason for the poor performance.

like image 36
talonmies Avatar answered Jan 04 '23 11:01

talonmies