CS 61C: Great Ideas in Computer Architecture Lecture 18: Parallel - - PowerPoint PPT Presentation

cs 61c great ideas in computer architecture lecture 18
SMART_READER_LITE
LIVE PREVIEW

CS 61C: Great Ideas in Computer Architecture Lecture 18: Parallel - - PowerPoint PPT Presentation

CS 61C: Great Ideas in Computer Architecture Lecture 18: Parallel Processing SIMD Bernhard Boser & Randy Katz http://inst.eecs.berkeley.edu/~cs61c Reference Problem Matrix multiplication Basic operation in many engineering,


slide-1
SLIDE 1

CS 61C: Great Ideas in Computer Architecture Lecture 18: Parallel Processing – SIMD

Bernhard Boser & Randy Katz http://inst.eecs.berkeley.edu/~cs61c

slide-2
SLIDE 2

Reference Problem

  • Matrix multiplication

−Basic operation in many engineering, data, and imaging processing tasks −Image filtering, noise reduction, … −Many closely related operations

§ E.g. stereo vision (project 4)

  • dgemm

−double precision floating point matrix multiplication

CS 61c Lecture 18: Parallel Processing - SIMD 5

slide-3
SLIDE 3

Application Example: Deep Learning

  • Image classification (cats …)
  • Pick “best” vacation photos
  • Machine translation
  • Clean up accent
  • Fingerprint verification
  • Automatic game playing

CS 61c Lecture 18: Parallel Processing - SIMD 6

slide-4
SLIDE 4

Matrices

CS 61c Lecture 18: Parallel Processing - SIMD 7

𝑑"#

  • Square (or rectangular) N x N

array of numbers

− Dimension N

𝐷 = 𝐵 ' 𝐶 𝑑"# = ) 𝑏"+𝑐+#

  • +

𝑗 𝑘

N-1 N-1

slide-5
SLIDE 5

Matrix Multiplication

CS 61c 8

𝑫 = 𝑩 ' 𝑪

𝑑"# = ) 𝑏"+𝑐+#

  • +

𝑗 𝑘 𝑙 𝑙

slide-6
SLIDE 6

Reference: Python

  • Matrix multiplication in Python

CS 61c Lecture 18: Parallel Processing - SIMD 9

N Python [Mflops] 32 5.4 160 5.5 480 5.4 960 5.3

  • 1 Mflop = 1 Million floating

point operations per second (fadd, fmul)

  • dgemm(N …) takes

2*N3 flops

slide-7
SLIDE 7

C

  • c = a x b
  • a, b, c are N x N matrices

CS 61c Lecture 18: Parallel Processing - SIMD 10

slide-8
SLIDE 8

Timing Program Execution

CS 61c Lecture 18: Parallel Processing - SIMD 11

slide-9
SLIDE 9

C versus Python

CS 61c Lecture 18: Parallel Processing - SIMD 12

N C [Gflops] Python [Gflops] 32 1.30 0.0054 160 1.30 0.0055 480 1.32 0.0054 960 0.91 0.0053

Which class gives you this kind of power? We could stop here … but why? Let’s do better!

240x !

slide-10
SLIDE 10

New-School Machine Structures (It’s a bit more complicated!)

  • Parallel Requests

Assigned to computer e.g., Search “Katz”

  • Parallel Threads

Assigned to core e.g., Lookup, Ads

  • Parallel Instructions

>1 instruction @ one time e.g., 5 pipelined instructions

  • Parallel Data

>1 data item @ one time e.g., Add of 4 pairs of words

  • Hardware descriptions

All gates @ one time

  • Programming Languages

16

Smart Phone Warehouse Scale Computer

Software Hardware

Harness Parallelism & Achieve High Performance

Logic Gates Core Core … Memory (Cache) Input/Output Computer Cache Memory Core Instruction Unit(s) Functional Unit(s)

A3+B3 A2+B2 A1+B1 A0+B0

Today’s Lecture

slide-11
SLIDE 11

Multiple-Instruction/Single-Data Stream (MISD)

  • Multiple-Instruction,

Single-Data stream computer that exploits multiple instruction streams against a single data stream.

  • Historical significance

20 CS 61c Lecture 18: Parallel Processing - SIMD

This has few applications. Not covered in 61C.

slide-12
SLIDE 12

SIMD Applications & Implementations

  • Applications

− Scientific computing

§ Matlab, NumPy

− Graphics and video processing

§ Photoshop, …

− Big Data

§ Deep learning

− Gaming − …

  • Implementations

− x86 − ARM − …

CS 61c Lecture 18: Parallel Processing - SIMD 24

slide-13
SLIDE 13

Raw Double Precision Throughput

(Bernhard’s Powerbook Pro)

Characteristic Value CPU i7-5557U Clock rate (sustained) 3.1 GHz Instructions per clock (mul_pd) 2 Parallel multiplies per instruction 4 Peak double flops 24.8 Gflops

CS 61c Lecture 18: Parallel Processing - SIMD 36

Actual performance is lower because of overhead

https://www.karlrupp.net/2013/06/cpu-gpu-and-mic-hardware-characteristics-over-time/

slide-14
SLIDE 14

Vectorized Matrix Multiplication

CS 61c 37

𝑗

𝑘

𝑙 𝑙

Inner Loop: for i …; i+=4 for j ...

i += 4

slide-15
SLIDE 15

“Vectorized” dgemm

CS 61c Lecture 18: Parallel Processing - SIMD 38

slide-16
SLIDE 16

Performance

N Gflops scalar avx 32 1.30 4.56 160 1.30 5.47 480 1.32 5.27 960 0.91 3.64

CS 61c Lecture 18: Parallel Processing - SIMD 39

  • 4x faster
  • But still << theoretical 25 Gflops!
slide-17
SLIDE 17

Pipeline Hazards – dgemm

CS 61c Lecture 18: Parallel Processing - SIMD 54

slide-18
SLIDE 18

Loop Unrolling

CS 61c Lecture 18: Parallel Processing - SIMD 55

Compiler does the unrolling How do you verify that the generated code is actually unrolled? 4 registers

slide-19
SLIDE 19

Performance

N Gflops scalar avx unroll 32 1.30 4.56 12.95 160 1.30 5.47 19.70 480 1.32 5.27 14.50 960 0.91 3.64 6.91

CS 61c Lecture 18: Parallel Processing - SIMD 56