Nvidia Cuda Architecture
Created: January 18, 2019 by [lek-tin]
Last updated: January 18, 2019
Fundamental concepts/components in the CUDA architecture:
- thread:
- core/kernel:
- Block: a collection of parallel threads.
- Grid: a collection of parallel thread blocks.
- warp: a set of threads (commonly 32) that get executed simultaneously. Thread blocks are executed as smaller groups of threads known as “warps” in sequence.
- streaming multiprocessor: the number of blocks per grid is limited by SM. Waprs are scheduled to execute in SMs. Streaming Multiprocessor has a Shared Memory. (Hence “private”, like a private programmer-controlled L1 cache). Each thread block can allocate shared memory where the allocations are private to that thread block. If there are multiple thread blocks in the same Streaming Multiprocessor, each thread blocks’ shared memory allocation is in the same physical shared memory, but the contents are private to each thread block. (The content of
block 0
's shared memory is not visible toblock 1
's, etc.) - texture:
- control divergency:
- CPU DMA:
- Shared memory: shared memory is much faster than local and global memory. Because it is on-chip, in fact, shared memory latency is roughly 100x lower than uncached global memory latency (provided that there are no bank conflicts between the threads. Threads within a thread block can cooperate via the shared memory.
- warp occupancy:
- Local memory: “Local memory” in CUDA is actually global memory (and should really be called “thread-local global memory”) with interleaved addressing (which makes iterating over an array in parallel a bit faster than having each thread’s data blocked together).
APIs:
__syncthreads
: wait for all threads in the block to finish an instruction.cudaThreadSynchronize()
: used when measuring performance to ensure that all device operations have completed before stopping the timer.cudaGetDeviceCount(int *count)
:cudaSetDevice(int device)
:cudaGetDevice(int *device)
:cudaGetDeviceProperties(cudaDeviceProp *prop, int device)
:cudaSetDevice(i)
: to select current devicecudaMemcpy(...)
: for peer-to-peer copies. cpu cache is not used.
Events:
Performance:
- Warp divergence: mainly caused by the SIMT execution model where 32 threads in a warp must execute the same instruction (all share the same Program Counter). Due to this, if threads diverge and operate on different instructions, the execution becomes serialized.
- Maximum number of threads per SM: the aim is to fit in as many threads in a SM as possible. For a SM has 1536 threads, a tile size of 16 we can fit up to 6 thread blocks in an SM (using all 1536 hardware thread contexts), while a tile size of 32 can only fit 1 thread block in an SM (using 1024 out of 1536 possible hardware thread contexts).
As of Nvidia Fermi series GeForce GPUs