Docsity

CUDA - Parallel Computing - Lecture Slides, Slides of Parallel Computing and Programming

Partial preview of the text

Download CUDA - Parallel Computing - Lecture Slides and more Slides Parallel Computing and Programming in PDF only on Docsity!

Programming GPUs with CUDA

Why GPUs?

  • Two major trends

—GPU performance is pulling away from traditional processors

—availability of general (non-graphics) programming interfaces

  • GPU in every PC and workstation

—massive volume, potentially broad impact

Figure Credits: NVIDIA CUDA Compute Unified Device Architecture Programming Guide 3.1 2 (FERMI) (FERMI)

GPGPU?

  • General Purpose computation using GPU

—applications beyond 3D graphics

—typically, data-intensive science and engineering applications

  • Data-intensive algorithms leverage GPU attributes

—large data arrays, streaming throughput

—fine-grain “single instruction multiple threads” (SIMT) parallelism

—low-latency floating point computation

GPGPU Programming in 2005

  • Stream-based programming model
  • Express algorithms in terms of graphics operations

—use GPU pixel shaders as general-purpose SP floating point units

  • Directly exploit

—pixel shaders

—vertex shaders

—video memory

  • Example: GPUSort (Govindaraju, Manocha; 2005) Figure Credits: Dongho Kim, School of Media, Soongsil University 5 threads interact through off-chip video memory

CUDA

CUDA = Compute Unified Device Architecture

  • Software platform for parallel computing on Nvidia GPUs

—introduced in 2006

—Nvidia’s repositioning of GPUs as versatile compute devices

  • C plus a few simple extensions

—write a program for one thread

—instantiate for many parallel threads

—familiar language; simple data-parallel extensions

  • CUDA is a scalable parallel programming model

—runs on any number of processors without recompiling

Slide credit: Patrick LeGresley, NVidia 7

NVIDIA Fermi GPU (2010)

  • 3.0B transistors
  • 15 SMs; 1 SM disabled for yield
  • 32 CUDA cores per SM

—CUDA core =

programmable

shader

  • 480 cores total 8 Figure credit: http://tpucdn.com/reviews/NVIDIA/GeForce_GTX_480_Fermi/images/arch.jpg

NVIDIA GPU Stats Through Fermi

Figure Credit: http://www.nvidia.com/content/PDF/fermi_white_papers/NVIDIA_Fermi_Compute_Architecture_Whitepaper.pdf Note: Fermi specification here is pre-release. Actual cores = 480

NVIDIA Kepler GK110 (May 2012)

  • 28nm chip, 7.1B transistors
  • 15 Streaming Multiprocessors

—192 CUDA cores

  • fully pipelined FP and INT units
  • IEEE 754-2008; fused multiply add

—four warp schedulers

  • 32-thread groups (warps)
  • 4 warps issue and execute concurrently
  • 2 inst/warp/cycle

—64 DP FP units

—32 SFU

—32 LD/ST units

  • 6 64-bit memory controllers http://www.nvidia.com/content/PDF/kepler/NVIDIA-Kepler-GK110-Architecture-Whitepaper.pdf^11

CUDA Design Goals

  • Support heterogeneous parallel programming (CPU + GPU)
  • Scale to hundreds of cores, thousands of parallel threads
  • Enable programmer to focus on parallel algorithms

—not GPU characteristics, programming language, work

scheduling ...

CUDA Software Stack for Heterogeneous Computing Figure Credit: NVIDIA CUDA Compute Unified Device Architecture Programming Guide 1.1 14

Hierarchy of Concurrent Threads

  • Parallel^ kernels^ composed of many^ threads

—all threads execute same sequential program

—use parallel threads rather than sequential loops

  • Threads are grouped into^ thread blocks

—threads in block can sync and share memory

  • Blocks are grouped into^ grids

—threads and blocks have unique IDs

  • threadIdx: 1D, 2D, or 3D
  • blockIdx: 1D or 2D Slide credit: Patrick LeGresley, NVidia 16

—simplifies addressing

—when processing

—multidimensional data

CUDA Programming Example

**void saxpy_serial(int n, float alpha, float x, float y) { for (int i = 0; i< n; i++) y[i] = alpha * x[i] + y[i]; } // invoke serial saxpy kernel saxpy_serial(n, 2.0, x, y) Computing y = ax + y with a serial loop **Host code global void saxpy_parallel(int n, float alpha, float x, float y) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) y[i] = alpha * x[i] + y[i]; } Computing y = ax + y in parallel using CUDA // invoke parallel saxpy kernel (256 threads per block) int nblocks = (n + 255)/ saxpy_parallel<<nblocks, 256>>(n, 2.0, x, y) Device code Host code

CPU vs. GPGPU vs. CUDA

Comparing the abstract models 19

CPU

CPU GPGPU CUDA/GPGPU

Figure Credit: http://www.nvidia.com/docs/IO/55972/220401_Reprint.pdf

CUDA Memory Model

Figure credits: Patrick LeGresley, NVidia 20