data level parallelism (vector processors)

78
DataLevel Parallelism (Vector Processors) ECE 154B Dmitri Strukov Dmitri Strukov

Upload: others

Post on 12-Sep-2021

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Data Level Parallelism (Vector Processors)

Data‐Level Parallelism (Vector Processors)

ECE 154B

Dmitri StrukovDmitri Strukov

Page 2: Data Level Parallelism (Vector Processors)

Introduction

‐ SIMD architectures can exploit significant data‐level parallelism for:parallelism for:

‐matrix‐oriented scientific computing‐media‐oriented image and sound processorsg p

‐ SIMD is more energy efficient than MIMDl f h‐ Only needs to fetch one instruction per data 

operationMakes SIMD attractive for personal mobile devices‐Makes SIMD attractive for personal mobile devices

‐ SIMD allows programmer to continue to think p gsequentially

Page 3: Data Level Parallelism (Vector Processors)

SIMD Variations

‐ Vector architectures‐ SIMD extensionsSIMD extensions

‐MMX: Multimedia Extensions (1996)‐ SSE: Streaming SIMD Extensionsg‐ AVX: Advanced Vector Extension (2010)

‐ Graphics Processor Units (GPUs)

Page 4: Data Level Parallelism (Vector Processors)

SIMD vs MIMD

‐ For x86 processors:‐ Expect two additionalExpect two additional cores per chip per yeary

‐ SIMD width to double every four years

‐ Potential speedup from SIMD to befrom SIMD to be twice that from MIMD!

Page 5: Data Level Parallelism (Vector Processors)

PART I: Vector Architectures

Page 6: Data Level Parallelism (Vector Processors)

Vector Architectures

‐ Basic idea:‐ Read sets of data elements into “vector registers”Read sets of data elements into  vector registers‐ Operate on those registers‐ Disperse the results back into memoryp y

‐ Registers are controlled by compiler‐ Register files act as compiler controlled buffers

h l‐ Used to hide memory latency‐ Leverage memory bandwidth

Vector loads/stores deeply pipelined‐ Vector loads/stores deeply pipelined‐ pay for memory latency once per vector ld/st!

‐ Regular loads/storesg /‐ pay for memory latency for each vector element

Page 7: Data Level Parallelism (Vector Processors)

Example: VMIPS

‐ Vector registers‐ Each register holds a 64‐element, 64 

b / lbits/element vector‐ Register file has 16 read ports and 8 

write portsVector functional units‐ Vector functional units

‐ Fully pipelined‐ Data and control hazards are detected

‐ Vector load‐store unitVector load store unit‐ Fully pipelined‐Words move between registers‐ One word per clock cycle after initial p y

latency‐ Scalar registers

‐ 32 general‐purpose registers‐ 32 floating‐point registers

Page 8: Data Level Parallelism (Vector Processors)

VMIPS Instructions

Page 9: Data Level Parallelism (Vector Processors)

VMIPS Instructions

- Example: DAXPYL.D F0,a ;load scalar aLV V1 R l d t XLV V1,Rx ;load vector XMULVS.D V2,V1,F0 ;vector-scalar multLV V3,Ry ;load vector YADDVV V4 V2 V3 ;addADDVV V4,V2,V3 ;addSV Ry,V4 ;store result

In MIPS Code- In MIPS Code- ADD waits for MUL, SD waits for ADD

I VMIPS- In VMIPS- Stall once for the first vector element, subsequent

elements will flow smoothly down the pipeline. y p p- Pipeline stall required once per vector instruction!

Page 10: Data Level Parallelism (Vector Processors)

VMIPS Instructions

‐ Operate on many elements concurrently‐ Allows use of slow but wide execution unitsAllows use of slow but wide execution units

‐ High performance, lower power

‐ Independence of elements within a vector instruction‐ Allows scaling of functional units without costly 

h kdependence checks

Flexible‐ Flexible‐ 64 64‐bit / 128 32‐bit / 256 16‐bit, 512 8‐bit‐Matches the need of multimedia (8bit), scientific ( ),applications that require high precision. 

Page 11: Data Level Parallelism (Vector Processors)

Vector Execution Time

‐ Execution time depends on three factors:‐ Length of operand vectorsLength of operand vectors‐ Structural hazards‐ Data dependenciesp

‐ VMIPS functional units consume one element per clock lcycle‐ Execution time is approximately the vector length

Page 12: Data Level Parallelism (Vector Processors)

Convoy

‐ Set of vector instructions that could potentially execute togethertogether‐Must not contain structural hazards‐ Sequences with read‐after‐write dependency hazards q p yshould be in different convoys

‐ however can be in the same convoy via chaining 

Page 13: Data Level Parallelism (Vector Processors)

Vector Chaining‐ Vector version of register bypassingVector version of register bypassing

‐ Chaining

‐ Allows a vector operation to start as soon as the individual elements of its vector source operand become available

‐ Results from the first functional unit are forwarded to the second unitsecond unit 

V1 V2 V3 V4 V5LV v1MULV v3 v1 v2

Chain Chain

MULV v3,v1,v2ADDV v5, v3, v4

Load Unit

Mult Add

Chain

Memory

Mult. Add

Page 14: Data Level Parallelism (Vector Processors)

Vector Chaining Advantage

• Without chaining, must wait for last element of result to be written before starting dependent instruction

Load

Mul

g p

Mul

AddTime

• With chaining, can start dependent instruction as soon as first result appears

Load

Mul

AddAdd

Page 15: Data Level Parallelism (Vector Processors)

Convoy and Chimes

‐ Chime‐ Unit of time to execute one convoyUnit of time to execute one convoy‐m convoys executes in m chimes‐ For vector length of n, requires m x n clock cyclesg q y

Page 16: Data Level Parallelism (Vector Processors)

Example

LV V1,Rx ;load vector XMULVS.D V2,V1,F0 ;vector-scalar multLV V3,Ry ;load vector YADDVV.D V4,V2,V3 ;add two vectorsSV Ry V4 ;store the sumSV Ry,V4 ;store the sum

‐ Convoys:y1 LV MULVS.D2 LV ADDVV.D3 SV

‐ 3 chimes 2 FP ops per result cycles per FLOP = 1 53 chimes, 2 FP ops per result, cycles per FLOP = 1.5‐ For 64 element vectors, requires 64 x 3 = 192 clock cycles

Page 17: Data Level Parallelism (Vector Processors)

Challenges

‐ Start up time‐ Latency of vector functional unity‐ Assume the same as Cray‐1

‐ Floating‐point add => 6 clock cycles‐ Floating‐point multiply => 7 clock cyclesg p p y y‐ Floating‐point divide => 20 clock cycles‐ Vector load => 12 clock cycles

Page 18: Data Level Parallelism (Vector Processors)

Vector Instruction ExecutionADDV C,A,B

Execution using oneFour‐lane

i i fExecution using one pipelined functional unit

execution using four pipelined functional units

A[4] B[4]

A[5] B[5]

A[6] B[6]

A[16] B[16]

A[20] B[20]

A[24] B[24]

A[17] B[17]

A[21] B[21]

A[25] B[25]

A[18] B[18]

A[22] B[22]

A[26] B[26]

A[19] B[19]

A[23] B[23]

A[27] B[27]

C[2]

A[3] B[3]

A[4] B[4]

C[8]

A[12] B[12]

A[16] B[16]

C[9]

A[13] B[13]

A[17] B[17]

C[10]

A[14] B[14]

A[18] B[18]

C[11]

A[15] B[15]

A[19] B[19]

C[1]

C[2]

C[4]

C[8]

C[5]

C[9]

C[6]

C[10]

C[7]

C[11]

C[0] C[0] C[1] C[2] C[3]

Page 19: Data Level Parallelism (Vector Processors)

Multiple Lanes

Element n of vector register A is “hardwired” to element n of vector register B‐ Allows for multiple hardware lanes‐ No communication between lanesNo communication between lanes‐ Little increase in control overhead‐ No need to change machine code

Adding more lanes allows designers to tradeoff clock rate and energy without sacrificing performance!g p

Page 20: Data Level Parallelism (Vector Processors)

Multiple Lanes

For effective utilization‐ Application and architecture must 

support long vectorsOth i th ill t i kl‐ Otherwise, they will execute quickly and run out of instructions requiring ILP

Page 21: Data Level Parallelism (Vector Processors)

Vector Length Register

‐ Vector length not known at compile time?‐ Use Vector Length Register (VLR)Use Vector Length Register (VLR)‐ Use strip mining for vectors over maximum length:low = 0;VL ( % MVL) /*fi d dd i i i d l % */VL = (n % MVL); /*find odd‐size piece using modulo op % */for (j = 0; j <= (n/MVL); j=j+1) { /*outer loop*/

for (i = low; i < (low+VL); i=i+1) /*runs for length VL*/Y[i] = a * X[i] + Y[i] ; /*main operation*/Y[i] = a * X[i] + Y[i] ; /*main operation*/

low = low + VL; /*start of next vector*/VL = MVL; /*reset the length to maximum vector length*/

}}

Page 22: Data Level Parallelism (Vector Processors)

Maximum Vector Length

Advantage:‐ Determines the maximum number of elements in aDetermines the maximum number of elements in a vector for a given architecture

‐ Later generations may grow the MVL g y g‐ No need to change the ISA

Page 23: Data Level Parallelism (Vector Processors)

Masked Vector Instruction Implementationsp

Density‐Time Implementation– scan mask vector and only execute elements with non‐zero masks

Simple Implementation– execute all N operations, turn off result writeback according to mask

A[7] B[7]M[5] 1

M[6]=0

M[7]=1

elements with non zero masks

A[5] B[5]

A[6] B[6]

M[5] 1

M[6]=0

A[7] B[7]M[7]=1

writeback according to mask

C[4]

C[5]M[3]=0

M[4]=1

M[5]=1

M[2]=0

A[3] B[3]

A[4] B[4]

A[5] B[5]

M[3]=0

M[4]=1

M[5]=1

C[4]

C[1]

M[2]=0

M[1]=1

M[0]=0C[1]

C[2]M[2]=0

M[1]=1

Write data port

C[0]M[0]=0

Write data portWrite Disable Write data portWrite Disable

Page 24: Data Level Parallelism (Vector Processors)

Vector Mask Register

‐ Consider sparse matrix operations!:for (i = 0; i < 64; i=i+1)( ; ; )

if (X[i] != 0)X[i] = X[i] – Y[i];

‐ Use vector mask register to “disable” elements:LV V1,Rx ;load vector X into V1

2 l dLV V2,Ry ;load vector YL.D F0,#0 ;load FP zero into F0SNEVS.D V1,F0 ;sets VM(i) to 1 if V1(i)!=F0SUBVV.D V1,V1,V2 ;subtract under vector maskSV Rx,V1 ;store the result in X

‐ GFLOPS rate decreases!

Page 25: Data Level Parallelism (Vector Processors)

Vector Mask Register

‐ VMR is part of the architectural state

‐ Rely on compilers to manipulate VMR explicitly

‐ GPUs get the same effect using HW!‐ GPUs get the same effect using HW!‐ Invisible to SW

h G d hi d i ki !‐ Both GPU and Vector architectures spend time on masking!

Page 26: Data Level Parallelism (Vector Processors)

Memory Banks

‐Memory system must be designed to support high bandwidth for vector loads and storesS d lti l b k‐ Spread accesses across multiple banks‐ Control bank addresses independently‐ Load or store non sequential wordsLoad or store non sequential words‐ Support multiple vector processors sharing the same memoryy

‐ Example:‐ 32 processors, each generating 4 loads and 2 

/ lstores/cycle‐ Processor cycle time is 2.167 ns, SRAM cycle time is 15 ns15 ns

‐ How many memory banks needed?

Page 27: Data Level Parallelism (Vector Processors)

Memory Banks

‐ 6 mem refs / processor‐ 6*32 = 192 mem refs6 32 = 192 mem refs‐ 15/2.167 = 6.92 processor cycles pass for one SRAM cycley‐ Therefore around 7*192 = 1344 banks are needed!

‐ Cray T932 has 1024 banksl ’ f ll b h ll‐ It couldn’t sustain full bandwidth to all processors

‐ Replaced SRAM with pipelined asynchronous SRAM (halved the memory cycle time)(halved the memory cycle time)

Page 28: Data Level Parallelism (Vector Processors)

Stride: Multidimensional Arrays

‐ Consider:for (i = 0; i < 100; i=i+1)for (i = 0; i < 100; i=i+1)

for (j = 0; j < 100; j=j+1) {A[i][j] = 0.0;jfor (k = 0; k < 100; k=k+1)A[i][j] = A[i][j] + B[i][k] * D[k][j];

}}‐ Must vectorize multiplication of rows of B with columns of Dof D

‐ Need to access adjacent elements of B and D‐ Elements of B stored in row‐major order but jelements of D stored in column‐major order!

Page 29: Data Level Parallelism (Vector Processors)

Stride: Multidimensional Arrays

for (i = 0; i < 100; i=i+1)for (j = 0; j < 100; j=j+1) {(j ; j ; j j ) {

A[i][j] = 0.0;for (k = 0; k < 100; k=k+1)A[i][j] = A[i][j] + B[i][k] * D[k][j];

}‐ Assuming that each entry is a double word, distance between D[0][0] and D[1][0] is :  800 bytesy‐ Once vector is loaded into the register, it acts as if it has logically adjacent elements‐ Use non‐unit stride for D! ( B uses one unit stride)‐ Use non‐unit stride for D! ( B uses one unit stride)

‐ Ability to access non‐sequential addresses and reshape them into a dense structure!

U LVWS/SVWS l d/ i h id i i‐ Use LVWS/SVWS: load/store vector with stride instruction‐ Stride placed in a general purpose register (dynamic)

Page 30: Data Level Parallelism (Vector Processors)

Problem of Stride

for (i = 0; i < 100; i=i+1)for (j = 0; j < 100; j=j+1) {(j ; j ; j j ) {

A[i][j] = 0.0;for (k = 0; k < 100; k=k+1)A[i][j] = A[i][j] + B[i][k] * D[k][j];

}‐ With non‐unit stride, it is possible to request accesses from the same bank frequentlyq y‐ When multiple accesses compete for the same memory bank

‐ Memory bank conflict!‐ Stall one access‐ Stall one access‐ Bank conflict (stall) occurs when the same bank is hit faster than bank busy time

Page 31: Data Level Parallelism (Vector Processors)

Problem of Stride

‐ Example: ‐ 8 memory banks, bank busy time 6 cycles, total memory y , y y , ylatency 12 cycles (startup cost, initiation)

‐ What is the difference between a 64‐element vector load with a stride of 1 and 32?a stride of 1 and 32?  

Page 32: Data Level Parallelism (Vector Processors)

Scatter Gather

‐ Sparse matrices in vector mode is a necessity

‐ Sparse matrix elements stored in a compact form and accessed indirectly

‐ Consider a sparse vector sum on arrays A and Cfor (i = 0; i < n; i=i+1)

[ [i]] [ [i]] C[ [i]]A[K[i]] = A[K[i]] + C[M[i]];where K and M and index vectors to designate the nonzero elements of A and C

‐ Gather‐scatter operations are used 

Page 33: Data Level Parallelism (Vector Processors)

Scatter Gather

for (i = 0; i < n; i=i+1)for (i = 0; i < n; i=i+1)A[K[i]] = A[K[i]] + C[M[i]];

LVI/SVI: load/store  vector indexed/gather/ / /g

Use index vector:LV Vk, Rk ;load KLVI Va, (Ra+Vk) ;load A[K[]]LV Vm Rm ;load MLV Vm, Rm ;load MLVI Vc, (Rc+Vm) ;load C[M[]]ADDVV.D Va, Va, Vc ;add themADDVV.D Va, Va, Vc ;add themSVI (Ra+Vk), Va ;store A[K[]]

A and C must have the same number of non‐zero elements (size of K and M)

Page 34: Data Level Parallelism (Vector Processors)

Vector Summary

‐ Vector is alternative model for exploiting ILP‐ If code is vectorizable, then simpler hardware, energy efficient, and better real‐time model than out‐of‐orderand better real time model than out of order‐ More lanes, slower clock rate!‐ Scalable if elements are independent

If there is dependency‐ If there is dependency‐ One stall per vector instruction rather than one stall per vector element

‐ Programmer in charge of giving hints to the compiler!‐ Design issues: number of lanes, functional units and registers, length of vector registers, exception handling, conditionallength of vector registers, exception handling, conditional operations

Fundamental design issue is memory bandwidth‐ Fundamental design issue is memory bandwidth‐ Especially with virtual address translation and caching

Page 35: Data Level Parallelism (Vector Processors)

Vector Summary

// N is the array sizedouble A[N+1],B[N];[ ], [ ]... arrays are initialized ...for(int i = 0; i < N; i++)

A[i] = A[i+1] + B[i];A[i] = A[i+1] + B[i];Can this code be vectorized? 

ADD  RC, RA, 8LV  VC, RCLV VB RBLV  VB, RBADDV  VA, VC, VBSV  VA, RA

Page 36: Data Level Parallelism (Vector Processors)

Vector Summary

// N is the array sizedouble A[N+1],B[N+1];[ ], [ ]... arrays are initialized ...for(int i = 1; i < N+1; i++)

A[i] = A[i-1] + B[i];A[i] = A[i-1] + B[i];

Will this vectorized code work correctly? ADD  RC, RA, ‐8  ; RC = &(A[i‐1])LV  VC, RCLV  VB, RB,ADDV  VA, VC, VB  ; A[i] = A[i‐1] + B[i]SV  VA, RA

Assume that A = {0, 1, 2, 3, 4, 5}; B = {0, 0, 0, 0, 0, 0}; and VLEN is 6

Page 37: Data Level Parallelism (Vector Processors)

Vector Summary

for(int i = 1; i < N+1; i++)A[i] = A[i-1] + B[i];[ ] [ ] [ ]

ADD  RC, RA, ‐8  ; RC = &(A[i‐1])LV  VC, RCLV  VB, RBADDV  VA, VC, VB  ; A[i] = A[i‐1] + B[i]SV  VA, RA

Computing A[i] in iteration “i” requires using 

Assume that A = {0, 1, 2, 3, 4, 5}; B = {0, 0, 0, 0, 0, 0}; and VLEN is 6

p g [ ] q gthe previously computed A[i‐1] fromiteration “i‐1”, which forces a serialization (you must compute the elements one at a(you must compute the elements one at a time, and in‐order).

Page 38: Data Level Parallelism (Vector Processors)

PART II: SIMD EXTENSION

Page 39: Data Level Parallelism (Vector Processors)

SIMD Extensions

‐Media applications operate on data types narrower than the native word sizethe native word size

‐ Graphics systems use 8 bits per primary color‐ Audio samples use 8‐16 bitsp‐ 256‐bit adder

‐ 16 simultaneous operations on 16 bitsl b‐ 32 simultaneous operations on 8 bits

Page 40: Data Level Parallelism (Vector Processors)

SIMD vs. Vector 

M l i di SIMD i fi h b f- Multimedia SIMD extensions fix the number of operands in the opcode

Vector architectures have a VLR to specify the- Vector architectures have a VLR to specify the number of operands

- Multimedia SIMD extensions: No sophisticated u t ed a S e te s o s o sop st catedaddressing modes (strided, scatter-gather)

- No mask registers- These features

- enable vector compiler to vectorize a larger set of applicationsapplications

- make it harder for compiler to generate SIMD code and make programming in SIMD assemblycode and make programming in SIMD assembly harder

Page 41: Data Level Parallelism (Vector Processors)

SIMD‐ Implementations:

I t l MMX (1996)‐ Intel MMX (1996)‐ Repurpose 64‐bit floating point registers

Example: disconnect carry chains to “partition” adderExample:  disconnect carry chains to  partition  adder‐ Eight 8‐bit integer ops or four 16‐bit integer ops

‐ Streaming SIMD Extensions (SSE) (1999)g ( ) ( )‐ Separate 128‐bit registers‐ Eight 16‐bit ops, Four 32‐bit ops or two 64‐bit ops‐ Single precision floating point arithmetic

‐ Double‐precision floating point inSSE2 (2001) SSE3(2004) SSE4(2007)‐ SSE2 (2001), SSE3(2004), SSE4(2007)

‐ Advanced Vector Extensions (2010)‐ Four 64‐bit integer/fp opsFour 64 bit integer/fp ops

‐ Operands must be consecutive and aligned memory locations

Page 42: Data Level Parallelism (Vector Processors)

SIMD extensions

‐ Meant for programmers to utilize‐ Not for compilers to generate

‐ Recent x86 compilersRecent x86 compilers‐ Capable for FP intensive apps

‐ Why is it popular? Costs little to add to the standard arithmetic unit‐ Costs little to add to the standard arithmetic unit

‐ Easy to implement‐ Need smallermemory bandwidth than vector‐ Separate data transfers aligned in memory 

‐ Vector: single instruction , 64 memory accesses, page fault in the middle of the vector likely!in the middle of the vector likely!

‐ Use much smaller register space‐ Fewer operandsNo need for sophisticated mechanisms of vector architecture‐ No need  for sophisticated mechanisms of vector architecture

Page 43: Data Level Parallelism (Vector Processors)

Example SIMD CodeExample SIMD Code

• Example DXPY:L.D F0,a ;load scalar aMOV F1, F0 ;copy a into F1 for SIMD MULMOV F2, F0 ;copy a into F2 for SIMD MULMOV F3 F0 ;copy a into F3 for SIMD MULMOV F3, F0 ;copy a into F3 for SIMD MULDADDIU R4,Rx,#512 ;last address to load

Loop: L.4D F4,0[Rx] ;load X[i], X[i+1], X[i+2], X[i+3]MUL.4D F4,F4,F0 ;a×X[i],a×X[i+1],a×X[i+2],a×X[i+3][ ] [ ] [ ] [ ]L.4D F8,0[Ry] ;load Y[i], Y[i+1], Y[i+2], Y[i+3]ADD.4D F8,F8,F4 ;a×X[i]+Y[i], ..., a×X[i+3]+Y[i+3]S.4D 0[Ry],F8 ;store into Y[i], Y[i+1], Y[i+2], Y[i+3]DADDIU R R #32 i i d XDADDIU Rx,Rx,#32 ;increment index to XDADDIU Ry,Ry,#32 ;increment index to YDSUBU R20,R4,Rx ;compute boundBNEZ R20,Loop ;check if doneBNEZ R20,Loop ;check if done

Page 44: Data Level Parallelism (Vector Processors)

Roofline Performance Model• Basic idea:

– Plot peak floating‐point throughput as a functionPlot peak floating point throughput as a function of arithmetic intensity

– Ties together floating‐point performance and g g p pmemory performance for a target machine

• Arithmetic intensity

– Floating‐point operations per byte read

Page 45: Data Level Parallelism (Vector Processors)

Examples• Attainable GFLOPs/sec Min = (Peak Memory BW × Arithmetic 

Intensity, Peak Floating Point Perf.)

Attainable GFLOPs/sec = Min (Peak Memory BW * Arithmetic intensity, Peak FP performance)

Page 46: Data Level Parallelism (Vector Processors)

PART III: GPUs

Page 47: Data Level Parallelism (Vector Processors)

Graphical Processing Units

• Original (and still today) main focus is on accelerating g ( y) ggraphics

• Basic idea:• Basic idea:‐ Heterogeneous execution model

• CPU is the host, GPU is the deviceCPU is the host, GPU is the device‐ GPU is multicore multithreaded vector processor 

• combine all kinds of parallelism (even ILP) ‐ HW is heavily optimized towards executing graphics and affected by programming model 

Page 48: Data Level Parallelism (Vector Processors)

Graphical Processing Units

• Image processing is highly parallel in natureImage processing is highly parallel in nature

• Perform the same operation on pixel

h d ill k i i b• The needs still keep increasing but parallelism is scalable 

• Mostly dot‐products (so multiply‐add units makes sense)

• Primary metric is throughput 

Page 49: Data Level Parallelism (Vector Processors)

GP computing: GPA sweet spotsGP computing: GPA sweet spots

• High arithmetic intensity:g y– Dense linear algerba, PDEs, n‐body, finite difference, …

• High bandwidth  (more pins >2000 pins, special GDDRAM ( ifi d i f b d id h)GDDRAM (sacrifice density for bandwidth) – At least 10x more than typical CPU– Sequencing (virus scanning genomics) sorting databaseSequencing (virus scanning, genomics), sorting, database, …

• Visual computing:– Graphics image processing, tomography, machine vision, …

• Computational modeling, science, engineering, finance

Page 50: Data Level Parallelism (Vector Processors)

GPU Architecture• Multiple cores

• Each core supports multithreading pp g

• i.e. each thread has its own PC,register file & other context 

• Each thread is SIMD b t• Each thread is SIMD but 

• The MD is decided (packed by HW)

• No OoO, branch prediction, cachep

• Instead rely heavily on multithreading

• 80 threads per SP

h d• 240 SP cores = 20K threads• Burden for programmer?

Page 51: Data Level Parallelism (Vector Processors)

GPU ArchitectureSP “Streaming processor “ in (Nvidea) GPU terminologySP  Streaming processor   in (Nvidea) GPU terminology“core” in classical terminology

CUDA processor in GPU   “Lane” in classical terminology 

Terminology is very confusing!  Textbook is doing a great job of showing the mapping  

Page 52: Data Level Parallelism (Vector Processors)

Clarification (using GPU terminology)Clarification (using GPU terminology)

CRAY t SIMD t i f 86CRAY vector processors, SIMD extensions of x86  

aka “lanes”

Page 53: Data Level Parallelism (Vector Processors)

Hiding Latency with MT

Page 54: Data Level Parallelism (Vector Processors)

Hiding Latency with MT

Page 55: Data Level Parallelism (Vector Processors)

Hiding Latency with MT

Page 56: Data Level Parallelism (Vector Processors)

Hiding Latency with MT

Page 57: Data Level Parallelism (Vector Processors)

Hiding Latency with MT

Page 58: Data Level Parallelism (Vector Processors)

Storing Context

HWmanages allHW manages all context

High latency hiding but light threads and …                 ….  low latency hiding

Page 59: Data Level Parallelism (Vector Processors)

Branch Implementation

Page 60: Data Level Parallelism (Vector Processors)

Branch Implementation

Page 61: Data Level Parallelism (Vector Processors)

Branch Implementation

Page 62: Data Level Parallelism (Vector Processors)

Multiple Branches?Multiple Branches? 

• Special on‐chip stack‐like storage for fragmentSpecial on chip stack like storage for fragment (lane) state

• Push/pop state into stack upon• Push/pop state into stack upon entering/exiting new branch 

Page 63: Data Level Parallelism (Vector Processors)

NVIDIA GPU Memory Structures

• Each SIMD Lane has private section of off‐chip DRAMDRAM– “Private memory”– Contains stack frame, spilling registers, and private variables

• Each multithreaded SIMD processor also has local memorymemory– Shared by SIMD lanes / threads within a block

• Memory shared by SIMD processors is GPU y y pMemory– Host can read and write GPU memory

Page 64: Data Level Parallelism (Vector Processors)

Vector Processor vs. GPU 

Note the address coalescing unit: schedule memory request to minimize bank conflicts (somewhat similar to merge buffer)

Page 65: Data Level Parallelism (Vector Processors)

NVidea GeForce GTX 580 “SM”( l )(again in GPU language)

Page 66: Data Level Parallelism (Vector Processors)

Advanced GPU: Fermi Architecture InnovationsInnovations

• Each SIMD processor has– Two SIMD thread schedulers, two instruction dispatch units– 16 SIMD lanes (SIMD width=32, chime=2 cycles), 16 load‐store units, 4 

special function units– Thus, two threads of SIMD instructions are scheduled every two clock 

cycles

• Fast double precision• Caches for GPU memory• 64‐bit addressing and unified address space

E ti d• Error correcting codes• Faster context switching• Faster atomic instructions

Page 67: Data Level Parallelism (Vector Processors)

Fermi Multithreaded SIMD Proc.

Page 68: Data Level Parallelism (Vector Processors)

Programming model: CUDAProgramming model: CUDA

• CUDA is standard CCUDA is standard C– Write a program for one thread

Instantiate it on many parallel threads– Instantiate it on many parallel threads

• CUDA is a scalable parallel programming d lmodel

– Program runs on any number of processors ith t iliwithout recompiling

Page 69: Data Level Parallelism (Vector Processors)

Threads and BlocksThreads and Blocks

• A thread is associated with each data elementA thread is associated with each data element

• Threads are organized into blocks

l k i d i id• Blocks are organized into a grid

• GPU hardware handles thread management, not applications or OSpp

Page 70: Data Level Parallelism (Vector Processors)

What is thread?

• Each thread:Each thread:– Its own state (program counter, register, even local memory)

– No implication about how threads are scheduled

• CUDA threads may be physical threads– As on NVIDIA GPUs

• CUDA threads may be virtual threadsy– As on multicore CPUs (mapped to SSE of CPU)– Pick 1 thread block == 1 CPU core physical thread

Page 71: Data Level Parallelism (Vector Processors)

What is a thread block?What is a thread block?

• Thread block == virtualized multiprocessorp– Freely choose thread count to fit data– Freely customize for each kernel launchTh d bl k (d ) ll l k• Thread block == a (data) parallel task– All blocks in kernel have the same entry point– But may execute any code they wantBut may execute any code they want

• Thread blocks of kernel must be independent tasks– Program valid for any interleaving of block executions– Enables scalability to more and fewer parallel cores

Page 72: Data Level Parallelism (Vector Processors)

Blocks must be independentBlocks must be independent 

• Any possible interleaving of blocks should beAny possible interleaving of blocks should be valid– Presumed to run to completion without pre‐emptionPresumed to run to completion without pre emption

– Can run in any order

– Can run concurently OR sequentiallyy q y

• Blocks may coordinate but not synchronize– Shared queue pointer: OKShared queue pointer: OK

– Shared lock:  … can easily deadlock

• Independence requirement gives scalabilityIndependence requirement gives scalability

Page 73: Data Level Parallelism (Vector Processors)
Page 74: Data Level Parallelism (Vector Processors)
Page 75: Data Level Parallelism (Vector Processors)

Hierarchy of Concurrent Threads

• Parallel kernels composed of many threadsll h d h l– All threads execute the same sequential program

– Use parallel threads rather than sequential loops

• Threads are grouped into thread blocks• Threads are grouped into thread blocks– Threads in the same block can cooperate and share memoryy

• Blocks are grouped into grids– Threads and blocks have unique IDsq

• ThreadIDx• BlockIdx

Page 76: Data Level Parallelism (Vector Processors)

CUDA vector addition kernelCUDA vector addition kernel//  Compute vector sum C = A+B//// Each thread performs one pair‐wise addition_global_void vecAdd (float* A, float* B, float *C){

// global thread number within a grid// global thread number within a gridint i = threadIdx.x + blockDim.x + blockIdx.x; C[i] = A[i] + B[i];

}}

int main(){{// Run N/256 blocks of 256 threads eachvecAdd <<< N/256, 256>>> (d_A, d_B, d_C);

}

Page 77: Data Level Parallelism (Vector Processors)

GPU Summary: Vector Processors vs. GPU

Multiple functional units as opposed to deeply pipelined fewer‐ Multiple functional units as opposed to deeply pipelined fewer functional units of Vector processor!‐ Two level scheduling: 

‐ thread block scheduler and thread scheduler‐ GPU (32‐wide thread of SIMD instructions, 16 lanes )  =  Vector (16 lanes with vector length of 32) = 2 chimesg )

Figure 4.14 Simplified block diagram of a Multithreaded SIMD Processor. It has 16 SIMD lanes. The SIMD Thread Scheduler has, say, 48 independentthreads of SIMD instructions that it schedules with a table of 48 PCs.

Page 78: Data Level Parallelism (Vector Processors)

AcknowledgementsAcknowledgements

Some of the slides contain material developedSome of the slides contain material developed and copyrighted by A. Akoglu (ASU), NVidea, AMD and instructor material for the textbookAMD,  and instructor material for the textbook

78