Download Exploring NVIDIA's Tesla Micro-architecture & CUDA in Computer Architecture and more Summaries Advanced Computer Architecture in PDF only on Docsity!
Advanced Computer Architecture Chapter 7.
Data-Level Parallelism
Architectures and Programs
March 2017
Luigi Nardi
332 Advanced Computer Architecture Chapter 7 These lecture notes are partly based on:
- lecture slides from Paul H. J. Kelly (CO332/2013-2014)
- lecture slides from Fabio Luporini (CO332/2014-2015)
- the course text, Hennessy and Patterson’s Computer Architecture ( th ed.)
Advanced Computer Architecture Chapter 7. 2 Papers on parallel programming languages. Data according to Google Scholar (Feb. 2014)
Advanced Computer Architecture Chapter 7. 4 A glimpse of the performance (GFLOPS/s) IBM POWER Single Precision POWER 7 POWER 8 Source: http://docs.nvidia.com/cuda/cuda-c-programming-guide/
Advanced Computer Architecture Chapter 7. 5 A glimpse of the performance (GB/s) Sources: http://docs.nvidia.com/cuda/cuda-c-programming-guide/ http://www.anandtech.com/show/10435/assessing-ibms-power8-part-1/ IBM POWER POWER 8
Advanced Computer Architecture Chapter 7. A first comparison with CPUs 7 Source: http://docs.nvidia.com/cuda/cuda-c-programming-guide/
- “Simpler” cores
- Many functional units (FUs) (implementing the SIMD model)
- No (or limited) caching; just thousands of threads and super-fast context switch
- Drop sophisticated branch prediction mechanisms
Advanced Computer Architecture Chapter 7. NVIDIA G80 (2006) 16 cores, each with 8 “SP” units 16x8=128 threads execute in parallel Sketchy information on graphics primitive processing No L2 cache coherency problem, data can be in only one cache. Caches are small NVIDIA TESLA: A UNIFIED GRAPHICS AND COMPUTING ARCHITECTURE; Erik Lindholm John Nickolls, Stuart Oberman, John Montrym (IEEE Micro, March-April 2008) ROP performs colour and depth frame buffer operations directly on memory 8 Streaming Processor Array (SPA ) Raster operation processor (ROP)
Advanced Computer Architecture Chapter 7. NVIDIA’s Tesla micro-architecture
- Designed to do rendering
- Evolved to do general-purpose computing (GPGPU)
- But to manage thousands of threads, a new programming model is needed, called CUDA (Compute Unified Device Architecture)
- (^) CUDA is proprietary, but the same model lies behind OpenCL, an open standard with implementations for multiple vendors’ GPUs
- GPU evolved from hardware designed specifically around the OpenGL/DirectX rendering pipeline, with separate vertex- and pixel- shader stages
- “Unified” architecture arose from increased sophistication of shader programs
- Tesla still has some features specific to graphics:
- Work distribution, load distribution
- Texture cache, pixel interpolation
- Z-buffering and alpha-blending (the ROP units, see diagram)
- Tesla is also the NVIDIA brand codename for server GPUs:
- NVIDIA micro-architectures: Tesla, Fermi, Kepler, Maxwell, Pascal, Volta
- (^) NVIDIA brands: Tegra, Quadro, GeForce, Tesla 10
Advanced Computer Architecture Chapter 7.
CUDA Execution Model
- (^) CUDA is a C extension
- (^) Serial CPU code
- Parallel GPU code ( kernels )
- (^) GPU kernel is a C function
- (^) Each thread executes kernel code
- (^) A group of threads forms a thread block (1D, 2D or 3D)
- Thread blocks are organised into a grid (1D, 2D or 3D)
- (^) Threads within the same thread block can synchronise execution, and share access to local scratchpad memory Source: CUDA programming guide 11 Key idea: hierarchy of parallelism, to handle thousands of threads Blocks are allocated (dynamically) to SMs. Threads within a block run on the same SM Blocks in a grid can’t interact with each other
Advanced Computer Architecture Chapter 7.
CUDA Memory Model
- (^) Local memory — private to each thread (slow if off-chip, fast if register allocated)
- Shared memory — shared between threads in a thread block (fast on- chip)
- Global memory — shared between thread blocks in a grid (off-chip DRAM but in the GPU card)
- (^) Constant memory (small, read-only)
- (^) Texture memory (read-only; cached, stored in Global memory)
- (^) Memory instructions load-global, store-global, load-shared, store- shared, load-local, and store-local ! (^) Diagram is misleading: logical association but not hardware locality ! (^) “Local memory” is non-cached (in Tesla), stored in global DRAM ! (^) Critical thing is that “shared” memory is shared among all threads in a block, since they all run on the same SM 13 Source: CUDA programming guide
Advanced Computer Architecture Chapter 7. // Invoke DAXPY daxpy(n, 2.0, x, y); // DAXPY in C void daxpy(int n, double a, double x, double y) { for(int i=0; i < n; ++i) y[i] = ax[i] + y[i]; }* (^) fully parallel loop int main(){ // Kernel setup int N = 1024; int blockDim = 256; // These are the threads per block int gridDim = N / blockDim;// These are the number of blocks daxpy<<<gridDim, blockDim>>>(N, 2.0, x, y);// Kernel invocation }
CUDA example: DAXPY
! (^) Kernel invocation (“<<<…>>>”) corresponds to enclosing loop nest, managed by hardware ! (^) Explicitly split into 2-level hierarchy: blocks (which share “shared” memory), and grid ! (^) Kernel commonly consists of just one iteration but could be a loop ! (^) Multiple tuning parameters trade off register pressure, shared-memory capacity and parallelism 14 global void daxpy(int N, double a, double x, double y) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < N) y[i] = ax[i] + y[i]; }*
Advanced Computer Architecture Chapter 7. 15 Running DAXPY (N=1024) on a GPU …….. DRAM Multithreaded SIMD Processor (SM) Multithreaded SIMD Processor (SM) Multithreaded SIMD Processor (SM) Host (via I/O bus, DMA) BLOCK 1 (DAXPY 0-255) BLOCK 2 (DAXPY 256-511) BLOCK 3 (DAXPY 512-767) BLOCK 4 (DAXPY 768-1023) Note that: SIMD + MIMD
Advanced Computer Architecture Chapter 7. 15 Running DAXPY (N=1024) on a GPU …….. DRAM Multithreaded SIMD Processor (SM) Multithreaded SIMD Processor (SM) Multithreaded SIMD Processor (SM) Host (via I/O bus, DMA) BLOCK 1 (DAXPY 0-255) BLOCK 2 (DAXPY 256-511) BLOCK 3 (DAXPY 512-767) BLOCK 4 (DAXPY 768-1023) BLOCK x (…) BLOCK x+ (…) BLOCK x+ (…) Note that: SIMD + MIMD
Advanced Computer Architecture Chapter 7. Mapping from CUDA to TESLA
- (^) Array of streaming multiprocessors (SMs)
- (we might call them “cores”, when comparing to conventional
multi-core; each SM is an instruction-fetch-execution engine)
- (^) CUDA thread blocks get mapped to SMs
- (^) SMs have thread processors, private registers, shared memory, etc.
- (^) Each SM executes a pool of warps, with a separate instruction pointer for each warp. Instructions are issued from each ready-to-run warp in turn (SMT, hyper-threading)
- A warp is like a traditional thread (32 CUDA threads executed as 32 SIMD operations)
! Corollary: enough warps are needed to avoid stalls (i.e., enough threads per
block). Also called GPU occupancy in CUDA
! But: high occupancy is not always a good solution to achieve good
performance, i.e., memory bound applications may need a less busy bus to
perform well. Reduce the number of in-flight loads/stores by reducing the
number of blocks on a SM and improve cache trashing. How?
- If you are a ninja: use dynamic shared memory to reduce occupancy
- Or increase the number of registers in your kernel 17
Advanced Computer Architecture Chapter 7. 18 Branch divergence
- In a warp threads all take the same path (good!) or diverge!
- A warp serially executes each path, disabling some of the
threads
- When all paths complete, the threads reconverge
- Divergence only occurs within a warp - different warps execute
independently
- This model of execution is called lockstep instructions are
serialised on branch divergence
- Control-flow coherence: every thread goes the same way (a
form of locality) Predicate bits: enable/disable each lane
: : if (x == 10) c = c + 1; : : LDR r5, X p1 <- r5 eq 10 LDR r1 <- C ADD r1, r1, 1 STR r1 -> C :