Docsity

Parallel Computing: Challenges and Solutions for Asymmetric Processing, Study notes of Computer Science

Partial preview of the text

Download Parallel Computing: Challenges and Solutions for Asymmetric Processing and more Study notes Computer Science in PDF only on Docsity!

Asymmetric Multiprocessing for

High Performance Computing

Stephen Jenks

Electrical Engineering and Computer Science

UC Irvine

[email protected] Source: NVIDIA

Overview and Motivation

 Conventional Parallel Computing Was:

◦ For scientists with large problem sets

◦ Complex and difficult

◦ Very expensive computers with limited access

 Parallel Computing is Becoming:

◦ Ubiquitous

◦ Cheap

◦ Essential

◦ Different

◦ Still complex and difficult

 Where Is Parallel Computing Going?

 And What are the Research Challenges?

Conventional Processor

Architecture

 Hasn’t Changed Much For 40 Years

◦ Pipelining and Superscalar Since the 1960s

◦ But has become integrated  Microprocessors

 High Clock Speed

◦ Great performance

◦ High Power

◦ Cooling Issues

◦ Various

Solutions

From Hennessy & Patterson, 2nd Ed.

Parallel Computing Problem

Overview

Image Relaxation (Blur)

newimage[i][j] = (image[i][j] + image[i][j-1] + image[i][j+1] + image[i+1][j] + image[i-1][j]) / 5

Stencil

Shared Memory Programming

 Threads

◦ POSIX Threads

◦ Windows Threads

 OpenMP

◦ User-inserted directives to compiler

◦ Loop parallelism

◦ Parallel regions

◦ Visual Studio 2/25/2009^ Stephen Jenks^7

Not Integrated with Compiler or Language No idea if code is in thread or not Poor optimizations

#pragma omp parallel for for (i=0; i<n; i++) a[i] = b[i] * c[i];

Multicore Processors

 Several CPU Cores

Per Chip

 Shared Memory

 Shared Caches (sometimes)

 Lower Clock Speed

◦ Lower Power & Heat

◦ But Good Performance

 Program with Threads

 Single Threaded Code

◦ Not Faster

◦ Majority of Code Today

Intel Core Duo

AMD Athlon 64 X

AMD Phenom X4 Floorplan

Source: AMD.com

Single Nehalem (Intel I7) Core

Nehalem - Everything You Need to Know about Intel's New Architecture http://www.anandtech.com/cpuchipsets/intel/showdoc.aspx?i=

Asymmetric Parallel Accelerators

 Current Cores are Powerful and General

◦ Some Applications Only Need Certain Operations

◦ Perhaps a Simpler Processor Could Be Faster

 Pair General CPUs with Specialized

Accelerators

◦ Graphics Processing Unit

◦ Field Programmable

Gate Array (FPGA)

◦ Single Instruction,

Multiple Data (SIMD)

Processor

Athlon 64 CPU

ATI
GPU
XBAR

Hyper- Transport

Memory Controller

Possible Hybrid
AMD Multi-Core
Design

Graphics Processing Unit (GPU)

 GPUs Do Pixel Pushing and Matrix Math

From NVIDIA CUDA Compute Unified Device Architecture Programming Guide 11/29/

Finite Difference, Time Domain

(FDTD) Electromagnetic Simulation

Fields stored in 6 3D Arrays: EX, EY, EZ, HX, HY, HZ 2 other coefficient arrays O(N^3 ) algorithm

/ update magnetic field / for (i = 1; i < nx - 1; i++) for (j = 1; j < ny - 1; j++) { / combining Y loop / for (k = 1; k < nz - 1; k++) { ELEM_TYPE invmu = 1.0f/AR_INDEX(mu,i,j,k); ELEM_TYPE tmpx = rxinvmu; ELEM_TYPE tmpy = ryinvmu; ELEM_TYPE tmpz = rzinvmu; AR_INDEX(hx,i,j,k) += tmpz * (AR_INDEX(ey,i,j,k+1) - AR_INDEX(ey,i,j,k)) - tmpy * (AR_INDEX(ez,i,j+1,k) - AR_INDEX(ez,i,j,k)); AR_INDEX(hy,i,j,k) += tmpx * (AR_INDEX(ez,i+1,j,k) - AR_INDEX(ez,i,j,k)) - tmpz * (AR_INDEX(ex,i,j,k+1) - AR_INDEX(ex,i,j,k)); AR_INDEX(hz,i,j,k) += tmpy * (AR_INDEX(ex,i,j+1,k) - AR_INDEX(ex,i,j,k)) - tmpx * (AR_INDEX(ey,i+1,j,k) - AR_INDEX(ey,i,j,k)); } / now update the electric field / for (k = 1; k < nz - 1; k++) { ELEM_TYPE invep = 1.0f/AR_INDEX(ep,i,j,k); ELEM_TYPE tmpx = rxinvep; ELEM_TYPE tmpy = ryinvep; ELEM_TYPE tmpz = rzinvep; AR_INDEX(ex,i,j,k) += tmpy * (AR_INDEX(hz,i,j,k) - AR_INDEX(hz,i,j-1,k)) - tmpz * (AR_INDEX(hy,i,j,k) - AR_INDEX(hy,i,j,k-1)); AR_INDEX(ey,i,j,k) += tmpz * (AR_INDEX(hx,i,j,k) - AR_INDEX(hx,i,j,k-1)) - tmpx * (AR_INDEX(hz,i,j,k) - AR_INDEX(hz,i-1,j,k)); AR_INDEX(ez,i,j,k) += tmpx * (AR_INDEX(hy,i,j,k) - AR_INDEX(hy,i-1,j,k)) - tmpy * (AR_INDEX(hx,i,j,k) - AR_INDEX(hx,i,j-1,k)); } }**

OpenMP FDTD

/ update magnetic field / #pragma omp parallel for private(i,j,k)
shared(hx,hy,hz,ex,ey,ez) for (i = 1; i < nx - 1; i++) for (j = 1; j < ny - 1; j++) { for (k = 1; k < nz - 1; k++) { ELEM_TYPE invmu = 1.0f/AR_INDEX(mu,i,j,k); ELEM_TYPE tmpx = rx
invmu; ELEM_TYPE tmpy = ry
invmu; ELEM_TYPE tmpz = rzinvmu; AR_INDEX(hx,i,j,k) += tmpz * (AR_INDEX(ey,i,j,k+1) - AR_INDEX(ey,i,j,k)) - tmpy * (AR_INDEX(ez,i,j+1,k) - AR_INDEX(ez,i,j,k)); AR_INDEX(hy,i,j,k) += tmpx * (AR_INDEX(ez,i+1,j,k) - AR_INDEX(ez,i,j,k)) - tmpz * (AR_INDEX(ex,i,j,k+1) - AR_INDEX(ex,i,j,k)); AR_INDEX(hz,i,j,k) += tmpy * (AR_INDEX(ex,i,j+1,k) - AR_INDEX(ex,i,j,k)) - tmpx * (AR_INDEX(ey,i+1,j,k) - AR_INDEX(ey,i,j,k));*

} }

#pragma omp parallel for private(i,j,k)
shared(hx,hy,hz,ex,ey,ez)

Sequential OpenMP Core2Quad PS3 Core2Quad PS 26.7 28.6 8.8 26. Speedup 3.0 1.

Because of Dependences, Need to Split E & M Loops

CUDA FDTD (cont.)

float invep = 1.0f/AR_INDEX(d_ep,i,j,k); float tmpx = d_rxinvep; float tmpy = d_ryinvep; float tmpz = d_rzinvep;*

float ex = d_ex; float ey = d_ey; float* ez = d_ez;**

AR_INDEX(ex,i,j,k) += tmpy(AR_INDEX(d_hz,i,j,k)-AR_INDEX(d_hz,i,j-1,k))- tmpz(AR_INDEX(d_hy,i,j,k)-AR_INDEX(d_hy,i,j,k-1)); AR_INDEX(ey,i,j,k) += tmpz(AR_INDEX(d_hx,i,j,k)-AR_INDEX(d_hx,i,j,k-1))- tmpx(AR_INDEX(d_hz,i,j,k)-AR_INDEX(d_hz,i-1,j,k)); AR_INDEX(ez,i,j,k) += tmpx(AR_INDEX(d_hy,i,j,k)-AR_INDEX(d_hy,i-1,j,k))- tmpy(AR_INDEX(d_hx,i,j,k)-AR_INDEX(d_hx,i,j-1,k));**

Code looks normal, but: Only one “iteration” Arrays reside in device global memory

Machine Code Style Time (s) Speedup Core2Quad Sequential 26.5 1 Core2Quad OpenMP 8.8 3. GeForce 9800GX2 CUDA 7.4 3.

Better CUDA FDTD

 Problem: CUDA Memory Accesses Slow

 Problem: Not Much Work Done Per Thread

 Idea 1: Copy Data to Fast Shared Memory

◦ Allows Reuse By Neighbor Threads

◦ Takes Advantage of Coalesced Memory Accesses

 Idea 2: Compute Multiple Elements Per Thread

◦ But Each Block Only Gets 16KB Shared Space

◦ Barely Enough for 2 Points at 1x16x16 Threads

Machine Code Style Time (s) Speedup Core2Quad Sequential 26.5 1 Core2Quad OpenMP 8.8 3. GeForce 9800GX2 CUDA 7.4 3. GeForce 9800GX2 CUDA faster 6.5 4.