48
Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science, NCSU

Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen

Tackling Memory and Concurrency Barriers for Modern Parallel Computing

Computer Science, NCSU

Page 2: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Unprecedented Scale

!2sources: SciDAC, IBM

Y201120 petaflops

Y20201000 petaflops

Exascale Roadmap

Page 3: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Key Factors

!3sources: SciDAC, IBM

• Concurrency

• Memory Performance

Page 4: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !4

Expected Performance [DOE SciDAC]

5-10X

50-100X

>300X

Page 5: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Memory Gets More Complex

!5

Tesla K20 (NVIDIA)More than 8 types of memory

Non-volatile memory

3D stacked memory

Page 6: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

!6

Hardware Trends

• Rapidly growing node concurrency

• Increasingly complex memory

systems

Pivotal Role of Program Optimizers

• Expose & exploit parallelism• Capitalize on memory systems

potential

Implications to COSMIC

Page 7: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] 7

Two Recent Advancements

• 1. Data Placement Optimizations (MICRO’14)

- Memory Performance of GPU

• 2. Principled Speculative Parallelization (ASPLOS’14, ASPLOS’15)

- Execution Concurrency of FSM

Page 8: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] 8

a SIMD group(warp)

Graphic Processing Unit (GPU)

• Massive parallelism• Favorable

• computing power• cost effectiveness• energy efficiency

Page 9: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

Complex Memory

!9

Global memory

Texture memory

Shared memory

Constant memory

L1/L2 cache

Read-only cache

Texture cache

Page 10: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

Complex Memory

!10

Global memory

Texture memory

Shared memory

Constant memory

L1/L2 cache

Read-only cache

Texture cache

coalescing; cache hierarchy

2D/3D locality; texture cache; read-only (except surface write)

on-chip; bank conflicts

broadcasting; cached; read-only

private/shared

read-only data

2D/3D locality; read-only

Page 11: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

Data Placement Problem

!11

Global memory

Texture memory

Shared memory

Constant memory

(L1/L2 cache)

(Read-only cache)

(Texture cache)

A

B

C

D

Data in a program

?????

3X performance difference

Page 12: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

Data Placement Problem

!12

Properties:Machine dependent

Changes across models/generationsInput dependent

Changes across runs

Options:Manual efforts by programmers? Offline autotuning?

Page 13: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

PORPLE: Portable Data Placement Engine

!13

PLACER(placing engine)

MSL(mem. spec. lang.)

PORPLE-C(compiler)

architect

org. program

desired placement

efficient execution

input

PORPLE

microkernels

Page 14: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !14

MSL(mem. spec. lang.)architect/user

mem spec

microkernels

MSL(Memory Specification Language)

OFFLINE

Expose memory properties formally for automatic analysis.

Separate hw. complexities.

Page 15: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !15

Keywords: address1, address2, index1, index 2, banks, blockSize, warp, block, grid, sm, core, tpc, die, clk, ns, ms, sec, na, om, ?; // na: not applicable; om: omitted; ?: unknown; // om and ? can be used in all fields

Operators: C-like arithmetic and relational operators, and a scope operator {};

Syntax: • specList ::= processorSpec memSpec* • processorSpec ::= die=Integer tpc; tpc=Integer sm; sm=Integer core; end-of-line • memSpec ::= name id swmng rw dim size blockSize banks latency upperLevels

lowerLevels shareScope concurrencyFactor serialCondition ; end-of-line • name ::= String • id ::= Integer • swmng ::= Y | N // software manageable or not • rw ::= R|W|RW // allow read or write accesses • dim ::= na | Integer // special for arrays of a particular dimensionality • sz ::= Integer[K|M|G|T|ε][E|B] // E for data elements • size ::= sz | <sz sz> | <sz sz sz> • blockSize ::= sz | <sz sz> | <sz sz sz> • lat ::= Integer[clk|ns|ms|sec] // clk for clocks • latency ::= lat | <lat lat> • upperLevels ::= <[id | name]*> • lowerLevels ::= <id*> • shareScope ::= core | sm | tpc | die • concurrencyFactor ::= < Number Number> • serialCondition ::= scope{RelationalExpr} • scope ::= warp | block | grid

latency,hierarchy,size,sharing,constraints,serializationcondition,……

MSL(Memory Specification Language)

Page 16: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !16

Serialization Condition• Key to handle peculiar properties of some memory• Insight: they are all about when accesses get serialized.

Examples of serialization conditions: constant mem: warp{address1 != address2} shared mem: block{word1!=word2 && word1%banks == word2%banks} global mem: warp{⌊address1/blockSize⌋ != ⌊address2/blockSize⌋}

broadcasting

bankconflict

coalescing

Page 17: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

Example of Mem Spec (Tesla M2075)

!17

One-time effort by experts.Encapsulate hw complexity (extensibility; portability).

Mem spec of Tesla M2075:

die =1 tpc; tpc = 16 sm; sm = 32 core; globalMem 8 Y rw na 5375M 128B ? 600clk <L2 L1> <> die <0.1 0.5> warp{⌊address1/blockSize⌋ != ⌊address2/blockSize⌋}; L1 9 N rw na 16K 128B ? 80clk <> <L2 globalMem> sm ? warp{⌊address1/blockSize⌋ != ⌊address2/blockSize⌋}; L2 7 N rw na 768K 32B ? 390clk om om die ? warp{⌊address1/blockSize⌋ != ⌊address2/blockSize⌋};

constantMem 1 Y r na 64K ? ? 360clk <cL2 cL1> <> die ? warp{address1 != address2}; cL1 3 N r na 4K 64B ? 48clk <> <cL2 constantMem> sm ? warp{⌊address1/blockSize⌋ != ⌊address2/blockSize⌋}; cL2 2 N r na 32K 256B ? 140clk <cL1> <cL2 constantMem> die ? warp{⌊address1/blockSize⌋ != ⌊address2/blockSize⌋};

sharedMem 4 Y rw na 48K ? 32 48clk <> <> sm ? block{word1!=word2 && word1%banks ==word2%banks};

… …

sharedMem 4 Y rw na 48K ? 32 48clk <> <> sm ? block{word1!=word2 && word1%banks ==word2%banks};

Page 18: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

PORPLE: Portable Data Placement Engine

!18

PLACER(placing engine)

MSL(mem. spec. lang.)

PORPLE-C(compiler)

architect

org. program

desired placement

efficient execution

input

PORPLE

microkernels

Page 19: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !19

PORPLE-C(compiler)org. program

access patterns

staged program

PORPLE-C Compiler(source-to-source compiler)

Finding out data access patternsComplemented by online profiler

Making code placement-agnosticCode can work regardless of data placement

OFFLINE

Page 20: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

Enable Placement-Agnostic

!20

// host code float * A; cudaMalloc(A,...); cudaMemcopy(A, hA, ...);

// device code x = A[tid];

// host code float * A; cudaMalloc(A,...); cudaMemcopy(A, hA, ...); texture <float, ...> Atex; cudaBindTexture(null, Atex, A);

// device code x = tex1Dfetch(Atex, tid);

// host code float * A; cudaMalloc(A,...); cudaMemcopy(A, hA, ...); // device code __shared__ float s[sz]; s[localTid] = A[tid]; __synchthreads(); x = s[localTid];

// host code float * A; cudaMalloc(A,...); cudaMemcopy(A, hA, ...); // device code x = __ldg(&A[tid]);

(a) from global mem.

(d) from texture mem. (e) from shared mem.

(b) through read-only cache

// global declaration __constant__ float * A[sz];

// host code cudaMemcpyToSymbol (A, hA, ...); // device code x = A[tid];

(c) from constant mem.

Page 21: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Enable Placement-Agnostic

Coarse-grained & fine-grained versioning:code size V.S. time overhead

if (memSpace[A0_id]==TXR && memSpace[A1_id]==SHR)kernel_1(…); // version 1

elsekernel_others (…); // version 2

if (memSpace[A1_id]==SHR)sA1[…] = _tempA0;

elseA1[j] = _tempA0;

// host code

// code in kernel_others

Coarse

Fine

Page 22: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

PORPLE: Portable Data Placement Engine

!22

PLACER(placing engine)

MSL(mem. spec. lang.)

PORPLE-C(compiler)

architect

org. program

desired placement

efficient execution

input

PORPLE

microkernels

Page 23: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !23

PLACER(placing engine)

mem spec

access patterns

staged program

online profile

desired placement

efficient execution

online

input

Placer

Page 24: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected]

Lightweight On-Line Profiling

!24

• Array Sizes• Lightweight profiling on CPU for irreg. programs

• Work of the first thread block• At most 10 iterations for a loop

Page 25: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !25

• Search for the best placement• A placement: how all data are placed on men

• Key component: Performance model M

Mem perf. = M (a placement, access patterns, mem spec)

Placer

Page 26: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !26

Lightweight Performance Model

• Reuse Distance for cache miss rate estimation• Consideration of interferences on shared cache

• Maximal transfer time among data paths

numberofaccesseslatencyofmemoryj

concurrencyfactor

arraysthroughpathpalldatapaths

Page 27: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !27

PLACER(placing engine)

MSL(mem. spec. lang.)

PORPLE-C(compiler)

architect/usermem spec

org. program

access patterns

staged program

online profile

desired placement

efficient execution

offline online

microkernels

input

PORPLE in a Whole

MoredetailsinMicro’2014.

Page 28: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !28

Properties of PORPLE• Easy expansion to new memory

• New MSL spec• Good portability to new memory

• Program runs with new suitable placement automatically• Adaptivity to new program inputs

• On-the-fly placement with placement-agnostic code.• Generality to regular & irregular programs

• Static analysis + lightweight online profiling

Page 29: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] !29

Evaluation• 3 generations of NVIDIA GPU: K20c, M2075, C1060

• Different• mem size, cache, latency,

etc.• 14 benchmarks

• from SDK, SHOC, Rodinia• 9 regular, 5 irregular

Page 30: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

RegularBenchmarksonK20c

Rule-basedmethodfromJang+:TPDS.

Page 31: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

IrregularBenchmarksonK20c

Page 32: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

• K20c

• M2075

• C1060

Page 33: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

• Crossarchitectures

• Crossinputs

spmv particlefilter

Portability

Page 34: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

RuntimeOverheadBreakdown

Page 35: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Xipeng Shen [email protected] 35

• 1. Data Placement Optimizations (MICRO’14)

- Memory Performance of GPU

• 2. Principled Speculative Parallelization (ASPLOS’14, ASPLOS’15)

- Execution Concurrency of FSM

Two Recent Advancements

Page 36: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

�36

FiniteStateMachine(FSM)

Example:Checkwhetherastringcontains“aabaaabb”.

WebBrowsers(HTMLlexing/parsing)Decompression(Huffmandecoding)PatternMatching(grep)Security(intrusiondetection)SoftwareEngineer(modelchecking)Hardwaredesign(VHDLstatemachine)

Widelyused:

Page 37: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

�37

“EmbarrassinglySequential”

input string: a a b a b a b b a a a b a b a a b b a b a a a

thread1 thread2startingfromwhichstate?

—The Landscape of Parallel Computing Research: A View from Berkeley

Page 38: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

�38

SpeculativeParallelization

input string: a a b a b a b b a a a b a b a a b b a b a a a

thread1 thread2startingfromwhichstate?

• Basicidea• Pickaguesstostartprocessing• Reprocessinguponawrongguess

Page 39: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

�39

KeyOpenQuestion

input string: a a b a b a b b a a a b a b a a b b a b a a a

thread1 thread2startingfromwhichstate?

• Previousapproaches• Exhaustive(e.g.,NFA)—cost&scalability• Selective(e.g.,Jones+’09,Prabhu+’10)• Tricks:lookback;partialcommit

Howtomaketheguesstomaximizeperformance?

0"

2"

4"

6"

8"

huff" lexing" str1" str2" pval" xval" div"

Speedu

p"(8"cores)"

the$state$of$the$art$(Prabhu+: PLDI’10)

Page 40: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

�40

KeyOpenQuestion

Howtomaketheguesstomaximizeperformance?

• How far should lookback go?

• Which state should be used to start lookback ?

• Would starting from multiple states help ? If so, which state should be chosen after lookback ?

• How to combine lookback and partial commit effectively ?

• How to characterize FSMs and their inputs so that the speculation can be FSM and input-aware ?

Page 41: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Benefits & Best Design�

FSM Properties�

Spec. Para. Scheme�

PrincipledSpeculation—Arigorouswaytodesignspeculativeparallelization

Obtained through offline profiling�41

Page 42: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Performance

Page 43: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

InputSensitivity

Page 44: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

EnablingOnlineDeploymentASPLOS’2015

Page 45: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Overhead&Performance

Page 46: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Summary

Systematic�

Ad Hoc�

Rigor�

Design of Speculative Parallelization of FSM

Concurrency: Principled Speculation

Memory:Portable Data Placement Opt.

Page 47: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

Tobeexplored…Concurrency: Principled Speculation

Memory:Portable Data Placement Opt.

• Interplay w/ data layout

• Beyond GPU

• Emerging memory technology

• 3D stacked mem

• non-volatile mem

• …

• Energy efficiency

• Beyond FSM

• Dyn. programming

• Other sequential prog.

• Unified framework

• …

Page 48: Tackling Memory and Concurrency Barriers for Modern Parallel … · 2019-03-11 · Xipeng Shen Tackling Memory and Concurrency Barriers for Modern Parallel Computing Computer Science,

FinalTakeaways

• Twokeyfactors:Memory&Concurrency

• Softwaresolutioniscritical&promising

• PORPLE:portability,extensibility,inputadaptivity

• Principledspeculation:rigorispowerful