Академический Документы
Профессиональный Документы
Культура Документы
1
Introduction
Rich space of techniques and issues
• Trade off and interact with one another
Issues can be addressed/helped by software or hardware
• Algorithmic or programming techniques
• Architectural techniques
Focus here on performance issues and software techniques
• Why should architects care?
– understanding the workloads for their machines
– hardware/software tradeoffs: where should/shouldn’t architecture help
• Point out some architectural implications
• Architectural techniques covered in rest of class
2
Programming as Successive Refinement
Not all issues dealt with up front
Partitioning often independent of architecture, and done first
• View machine as a collection of communicating processors
– balancing the workload
– reducing the amount of inherent communication
– reducing extra work
• Tug-o-war even among these three issues
Then interactions with architecture
• View machine as extended memory hierarchy
– extra communication due to architectural interactions
– cost of communication depends on how it is structured
• May inspire changes in partitioning
Discussion of issues is one at a time, but identifies tradeoffs
• Use examples, and measurements on SGI Origin2000
3
Outline
Partitioning for performance
Relationship of communication, data locality and architecture
Programming for performance
For each issue:
• Techniques to address it, and tradeoffs with previous issues
• Illustration using case studies
• Application to grid solver
• Some architectural implications
5
Load Balance and Synch Wait Time
Sequential Work
Limit on speedup: Speedupproblem(p) <
Max Work on any Processor
• Work includes data access and other costs
• Not just equal work, but must be busy at same time
6
Identifying Concurrency
Techniques seen for equation solver:
• Loop structure, fundamental dependences, new algorithms
Data Parallelism versus Function Parallelism
Often see orthogonal levels of parallelism; e.g. VLSI routing
W1 W2 W3
(a)
(b)
(c)
7
Identifying Concurrency (contd.)
Function parallelism:
• entire large tasks (procedures) that can be done in parallel
• on same or different data
• e.g. different independent grid computations in Ocean
• pipelining, as in video encoding/decoding, or polygon rendering
• degree usually modest and does not grow with input size
• difficult to load balance
• often used to reduce synch between data parallel phases
8
Deciding How to Manage Concurrency
Static versus Dynamic techniques
Static:
• Algorithmic assignment based on input; won’t change
• Low runtime overhead
• Computation must be predictable
• Preferable when applicable (except in multiprogrammed/heterogeneous
environment)
Dynamic:
• Adapt at runtime to balance load
• Can increase communication and reduce locality
• Can increase task management overheads
9
Dynamic Assignment
Profile-based (semi-static):
• Profile work distribution at runtime, and repartition dynamically
• Applicable in many computations, e.g. Barnes-Hut, some graphics
Dynamic Tasking:
• Deal with unpredictability in program or environment (e.g. Raytrace)
– computation, communication, and memory system interactions
– multiprogramming and heterogeneity
– used by runtime systems and OS too
• Pool of tasks; take and add tasks until done
• E.g. “self-scheduling” of loop iterations (shared loop counter)
10
Dynamic Tasking with Task Queues
Centralized versus distributed queues
Task stealing with distributed queues
• Can compromise comm and locality, and increase synchronization
• Whom to steal from, how many tasks to steal, ...
• Termination detection
• Maximum imbalance related to size of task
All processes
insert tasks P0 inserts P1 inserts P2 inserts P3 inserts
QQ 0 Q1 Q2 Q3
Others may
steal
All remove tasks P0 removes P1 removes P2 removes P3 removes
(a) Centralized task queue (b) Distributed task queues (one per pr ocess)
11
Impact of Dynamic Assignment
On SGI Origin 2000 (cache-coherent shared memory):
Speedup
15 15
10 10
5 5
(a) 0 (b) 0
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31
Number of processors Number of processors
12
Determining Task Granularity
Task granularity: amount of work associated with a task
General rule:
• Coarse-grained => often less load balance
• Fine-grained => more overhead; often more comm., contention
13
Reducing Serialization
Careful about assignment and orchestration (including scheduling)
Event synchronization
• Reduce use of conservative synchronization
– e.g. point-to-point instead of barriers, or granularity of pt-to-pt
• But fine-grained synch more difficult to program, more synch ops.
Mutual exclusion
• Separate locks for separate data
– e.g. locking records in a database: lock per process, record, or field
– lock per task in task queue, not per queue
– finer grain => less contention/serialization, more space, less reuse
• Smaller, less frequent critical sections
– don’t do reading/testing in critical section, only modification
– e.g. searching for task to dequeue in task queue, building tree
• Stagger critical sections in time
14
Implications of Load Balance
Sequential Work
Extends speedup limit expression to: <
Max (Work + Synch Wait Time)
Generally, responsibility of software
15
Reducing Inherent Communication
Communication is expensive!
Measure: communication to computation ratio
Focus here on inherent communication
• Determined by assignment of tasks to processes
• Later see that actual communication can be greater
16
Domain Decomposition
Works well for scientific, engineering, graphics, ... applications
Exploits local-biased nature of physical problems
• Information requirements often short-range
• Or long-range but fall off with distance
P4 P5 P6 P7
n n
p
P8 P9 P10 P11
17
Domain Decomposition (contd)
Best domain decomposition depends on information requirements
Nearest neighbor example: block versus strip decomposition:
n
-----
-
p n
P0 P1 P2 P3
P4 P5 P6 P7
n
-----
- n
p P8 P9 P10 P11
4*√p 2*p
Comm to comp: n
for block, n
for strip
• Retain block from here on
Application dependent: strip may be better in other cases
• E.g. particle flow in tunnel
18
Finding a Domain Decomposition
Static, by inspection
• Must be predictable: grid example above, and Ocean
Static, but not by inspection
• Input-dependent, require analyzing input structure
• E.g sparse matrix computations, data mining (assigning itemsets)
Semi-static (periodic repartitioning)
• Characteristics change but slowly; e.g. Barnes-Hut
Static or semi-static, with dynamic task stealing
• Initial decomposition, but highly unpredictable; e.g ray tracing
19
Other Techniques
Scatter Decomposition, e.g. initial partition in Raytrace
12 12 12 12
3 4 3 4 3 4 3 4
12
12 12 12 12
3 4 3 4 3 4 3 4
12 12 12 12
3 4 3 4 3 4 3 4
3 4
12 12 12 12
3 4 3 4 3 4 3 4
21
Reducing Extra Work
Common sources of extra work:
• Computing a good partition
– e.g. partitioning in Barnes-Hut or sparse matrix
• Using redundant computation to avoid communication
• Task, data and process management overhead
– applications, languages, runtime systems, OS
• Imposing structure on communication
– coalescing messages, allowing effective naming
Architectural Implications:
• Reduce need by making communication and orchestration efficient
Sequential Work
Speedup <
Max (Work + Synch Wait Time + Comm Cost + Extra Work)
22
Summary: Analyzing Parallel Algorithms
Requires characterization of multiprocessor and algorithm
Historical focus on algorithmic aspects: partitioning, mapping
PRAM model: data access and communication are free
• Only load balance (including serialization) and extra work matter
Sequential Instructions
Speedup <
Max (Instructions + Synch Wait Time + Extra Instructions)
• Useful for early development, but unrealistic for real performance
• Ignores communication and also the imbalances it causes
• Can lead to poor choice of partitions as well as orchestration
• More recent models incorporate comm. costs; BSP, LogP, ...
23
Limitations of Algorithm Analysis
Inherent communication in parallel algorithm is not all
• artifactual communication caused by program implementation and
architectural interactions can even dominate
• thus, amount of communication not dealt with adequately
Cost of communication determined not only by amount
• also how communication is structured
• and cost of communication in system
24
What is a Multiprocessor?
A collection of communicating processors
• View taken so far
• Goals: balance load, reduce inherent communication and extra work
25
Memory-oriented View
Multiprocessor as Extended Memory Hierarchy
– as seen by a given processor
26
Uniprocessor
Performance depends heavily on memory hierarchy
Time spent by a program
Timeprog(1) = Busy(1) + Data Access(1)
• Divide by cycles to get CPI equation
27
Extended Hierarchy
Idealized view: local cache hierarchy + single main memory
But reality is more complex
• Centralized Memory: caches of other processors
• Distributed Memory: some local, some remote; + network topology
• Management of levels
– caches managed by hardware
– main memory depends on programming model
• SAS: data movement between local and remote transparent
• message passing: explicit
28
Artifactual Comm. in Extended Hierarchy
Accesses not satisfied in local portion cause communication
• Inherent communication, implicit or explicit, causes transfers
– determined by program
• Artifactual communication
– determined by program implementation and arch. interactions
– poor allocation of data across distributed memories
– unnecessary data in a transfer
– unnecessary transfers due to system granularities
– redundant communication of data
– finite replication capacity (in cache or main memory)
•Inherent communication assumes unlimited capacity, small transfers,
perfect knowledge of what is needed.
• More on artifactual later; first consider replication-induced further
29
Communication and Replication
Comm induced by finite capacity is most fundamental artifact
• Like cache size and miss rate or memory traffic in uniprocessors
• Extended memory hierarchy view useful for this relationship
30
Working Set Perspective
•At a given level of the hierarchy (to the next further one)
Data traffic
First working set
Capacity-generated traffic
(including conflicts)
Second working set
Inherent communication
31
Orchestration for Performance
Reducing amount of communication:
• Inherent: change logical data sharing patterns in algorithm
• Artifactual: exploit spatial, temporal locality in extended hierarchy
– Techniques often similar to those on uniprocessors
32
Reducing Artifactual Communication
Message passing model
• Communication and replication are both explicit
• Even artifactual communication is in explicit messages
33
Exploiting Temporal Locality
• Structure algorithm so working sets map well to hierarchy
– often techniques to reduce inherent communication do well here
– schedule tasks for data reuse once assigned
• Multiple data structures in same phase
– e.g. database records: local versus remote
• Solver example: blocking
(a) Unblocked access pattern in a sweep (b) Blocked access pattern with B = 4
P0 P1 P2 P3 P0 P1 P2 P3
P4 P5 P6 P7 P4 P5 P6 P7
P8 P8
36
Tradeoffs with Inherent Communication
Partitioning grid solver: blocks versus rows
• Blocks still have a spatial locality problem on remote data
• Rowwise can perform better despite worse inherent c-to-c ratio
Good spacial locality on
nonlocal accesses at
row-oriented boudary
30 50
Rows 4D
45
4D 4D-rr
25
2D 40 Rows
35
Rows-rr
20 2D
30 2D-rr
Speedup
Speedup
15 25
20
10
15
10
5
5
0 0
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31
Number of processors Number of processors
38
Architectural Implications of Locality
Communication abstraction that makes exploiting it easy
For cache-coherent SAS, e.g.:
• Size and organization of levels of memory hierarchy
– cost-effectiveness: caches are expensive
– caveats: flexibility for different and time-shared workloads
• Replication in main memory useful? If so, how to manage?
– hardware, OS/runtime, program?
39
Structuring Communication
Given amount of comm (inherent or artifactual), goal is to reduce cost
Cost of communication as seen by process:
C = f * ( o + l + n /m + tc - overlap)
c
B
– f = frequency of messages
– o = overhead per message (at both ends)
– l = network delay per message
– nc = total data sent
– m = number of messages
– B = bandwidth along path (determined by network, NI, assist)
– tc = cost induced by contention per message
– overlap = amount of latency hidden by overlap with comp. or comm.
• Portion in parentheses is cost of a message (as seen by processor)
• That portion, ignoring overlap, is latency of a message
41
Reducing Network Delay
Network delay component = f*h*th
– h = number of hops traversed in network
– th = link+switch latency per hop
42
Reducing Contention
All resources have nonzero occupancy
• Memory, communication controller, network link, etc.
• Can only handle so many transactions per unit time
Effects of contention:
• Increased end-to-end cost for messages
• Reduced available bandwidth for individual messages
• Causes imbalances across processors
43
Types of Contention
Network contention and end-point contention (hot-spots)
Location and Module Hot-spots
• Location: e.g. accumulating into global variable, barrier
– solution: tree-structured communication
Contention Little contention
Flat
Tree structured
45
Summary of Tradeoffs
Different goals often have conflicting demands
• Load Balance
– fine-grain tasks
– random or dynamic assignment
• Communication
– usually coarse grain tasks
– decompose to obtain locality: not random/dynamic
• Extra Work
– coarse grain tasks
– simple assignment
• Communication Cost:
– big transfers: amortize overhead and latency
– small transfers: reduce contention
46
Processor-Centric Perspective
100 100
Synchronization Data-remote
Busy-overhead Busy-useful
Data-local
75 75
Time (s)
Time (s)
50 50
25 25
P 0 P1 P 2 P 3
47
Relationship between Perspectives
Orchestration/ Communication
mapping structure
48
Summary
Busy(1) + Data(1)
Speedupprob(p) =
Busyuseful(p)+Datalocal(p)+Synch(p)+Dateremote(p)+Busyoverhead(p)
49
Parallel Application Case Studies
Examine Ocean and Barnes-Hut (others in book)
Assume cache-coherent shared address space
Five parts for each application
• Sequential algorithms and data structures
• Partitioning
• Orchestration
• Mapping
• Components of execution time on SGI Origin2000
50
Case Study 1: Ocean
Computations in a Time-step:
Put Laplacian Put Laplacian Copy 1, 3 Put 1 3 Put computed 2 Initialize
of 1 in W11 of 3 in W13 into T1, T3 in W2 values in W3 and
a b
51
Partitioning
52
Orchestration and Mapping
Spatial Locality similar to equation solver
• Except lots of grids, so cache conflicts across grids
Complex working set hierarchy
• A few points for near-neighbor reuse, three subrows, partition of one grid,
partitions of multiple grids…
• First three or four most important
• Large working sets, but data distribution easy
Synchronization
• Barriers between phases and solver sweeps
• Locks for global variables
• Lots of work between synchronization events
Mapping: easy mapping to 2-d array topology or richer
53
Execution Time Breakdown
•1030 x 1030 grids with block partitioning on 32-processor Origin2000
Data Data
7 Synch 7 Synch
Busy Busy
6 6
5 5
4 4
Time (s)
Time (s)
3 3
2 2
1 1
0 0
13579 11 13 15 17 19 21 23 25 27 29 31 13579 11 13 15 17 19 21 23 25 27 29 31
Process Process
• 4-d grids much better than 2-d, despite very large caches on machine
– data distribution is much more crucial on machines with smaller caches
• Major bottleneck in this configuration is time waiting at barriers
– imbalance in memory stall times as well
54
Case Study 2: Barnes-Hut
Locality Goal:
• Particles close together in space should be on same processor
Difficulties: Nonuniform, dynamically changing
55
Application Structure
Build tree
Compute
Compute
forces
moments of cells
Time-steps
Update
Traverse tree
properties
to compute forces
56
Partitioning
Decomposition: bodies in most phases, cells in computing moments
Challenges for assignment:
• Nonuniform body distribution => work and comm. Nonuniform
– Cannot assign by inspection
• Distribution changes dynamically across time-steps
– Cannot assign statically
• Information needs fall off with distance from body
– Partitions should be spatially contiguous for locality
• Different phases have different work distributions across bodies
– No single assignment ideal for all
– Focus on force calculation phase
• Communication needs naturally fine-grained and irregular
57
Load Balancing
58
A Partitioning Approach: ORB
Orthogonal Recursive Bisection:
• Recursively bisect space into subspaces with equal work
– Work is associated with bodies, as before
• Continue until one partition per processor
P1 P2 P3 P4 P5 P6 P 7 P8
60
Performance Comparison
128.0 ideal
|
costzones: simulator
112.0 ORB: simulator
|
• Speedups on costzones: DASH
simulated costzones: KSR-1
multiprocessor 96.0
|
costzones: Challenge
(16K
particles) 80.0 |
64.0
|
• Extra work in
ORB
partitioning is 48.0
|
key difference
32.0
|
16.0
|
61
Orchestration and Mapping
Spatial locality: Very different than in Ocean, like other aspects
• Data distribution is much more difficult than
– Redistribution across time-steps
– Logical granularity (body/cell) much smaller than page
– Partitions contiguous in physical space does not imply contiguous in array
– But, good temporal locality, and most misses logically non-local anyway
• Long cache blocks help within body/cell record, not entire partition
Temporal locality and working sets:
• Important working set scales as 1/2log n
• Slow growth rate, and fits in second-level caches, unlike Ocean
Synchronization:
• Barriers between phases
• No synch within force calculation: data written different from data read
• Locks in tree-building, pt. to pt. event synch in center of mass phase
Mapping: ORB maps well to hypercube, costzones to linear array
62
Execution Time Breakdown
•512K bodies on 32-processor Origin2000
–Static, quite randomized in space, assignment of bodies versus costzones
Data Data
Synch Synch
40 Busy 40 Busy
35 35
30 30
Time (s)
25 25
Time (s)
20 20
15 15
10 10
5 5
0 0
13579 11 13 15 17 19 21 23 25 27 29 31 13579 11 13 15 17 19 21 23 25 27 29 31
Process Process
(a) Static assignment of bodies (b) Semistatic costzone assignment
64
Partitioning
Scene-oriented approach
• Partition scene cells, process rays while they are in an assigned cell
Ray-oriented approach
• Partition primary rays (pixels), access scene data as needed
• Simpler; used here
Need dynamic assignment; use contiguous blocks to exploit spatial
coherence among neighboring rays, plus tiles for task stealing
A block, A tile,
the unit of the unit of decomposition
assignment and stealing
Temporal locality
• Working sets much larger and more diffuse than Barnes-Hut
• But still a lot of reuse in modern second-level caches
– SAS program does not replicate in main memory
Synchronization:
• One barrier at end, locks on task queues
Mapping: natural to 2-d mesh for image, but likely not important
66
Execution Time Breakdown
200 Data 200
180 Synch 180
160 Busy 160
140 140
Time (s)
Time (s)
120 120
100 100
80 80
60 60
40 40
20 20
0 0
13579 11 13 15 17 19 21 23 25 27 29 31 13579 11 13 15 17 19 21 23 25 27 29 31
Process Process
67
Implications for Programming Models
Shared address space and explicit message passing
• SAS may provide coherent replication or may not
• Focus primarily on former case
68
Issues to Consider
Functional issues:
• Naming
• Replication and coherence
• Synchronization
Organizational issues:
• Granularity at which communication is performed
Performance issues
• Endpoint overhead of communication
– (latency and bandwidth depend on network so considered similar)
• Ease of performance modeling
Cost Issues
• Hardware cost and design complexity
69
Naming
SAS: similar to uniprocessor; system does it all
MP: each process can only directly name the data in its address space
• Need to specify from where to obtain or where to transfer nonlocal data
• Easy for regular applications (e.g. Ocean)
• Difficult for applications with irregular, time-varying data needs
– Barnes-Hut: where the parts of the tree that I need? (change with time)
– Raytrace: where are the parts of the scene that I need (unpredictable)
• Solution methods exist
– Barnes-Hut: Extra phase determines needs and transfers data before
computation phase
– Raytrace: scene-oriented rather than ray-oriented approach
– both: emulate application-specific shared address space using hashing
70
Replication
Who manages it (i.e. who makes local copies of data)?
• SAS: system, MP: program
Where in local memory hierarchy is replication first done?
• SAS: cache (or memory too), MP: main memory
At what granularity is data allocated in replication store?
• SAS: cache block, MP: program-determined
How are replicated data kept coherent?
• SAS: system, MP: program
How is replacement of replicated data managed?
• SAS: dynamically at fine spatial and temporal grain (every access)
• MP: at phase boundaries, or emulate cache in main memory in software
Of course, SAS affords many more options too (discussed later)
71
Amount of Replication Needed
Mostly local data accessed => little replication
Cache-coherent SAS:
• Cache holds active working set
– replaces at fine temporal and spatial grain (so little fragmentation too)
• Small enough working sets => need little or no replication in memory
Message Passing or SAS without hardware caching:
• Replicate all data needed in a phase in main memory
– replication overhead can be very large (Barnes-Hut, Raytrace)
– limits scalability of problem size with no. of processors
• Emulate cache in software to achieve fine-temporal-grain replacement
– expensive to manage in software (hardware is better at this)
– may have to be conservative in size of cache used
– fine-grained message generated by misses expensive (in message passing)
– programming cost for cache and coalescing messages
72
Communication Overhead and Granularity
Overhead directly related to hardware support provided
• Lower in SAS (order of magnitude or more)
Major tasks:
• Address translation and protection
– SAS uses MMU
– MP requires software protection, usually involving OS in some way
• Buffer management
– fixed-size small messages in SAS easy to do in hardware
– flexible-sized message in MP usually need software involvement
• Type checking and matching
– MP does it in software: lots of possible message types due to flexibility
• A lot of research in reducing these costs in MP, but still much larger
Naming, replication and overhead favor SAS
• Many irregular MP applications now emulate SAS/cache in software
73
Block Data Transfer
Fine-grained communication not most efficient for long messages
• Latency and overhead as well as traffic (headers for each cache line)
SAS: can using block data transfer
• Explicit in system we assume, but can be automated at page or object
level in general (more later)
• Especially important to amortize overhead when it is high
– latency can be hidden by other techniques too
Message passing:
• Overheads are larger, so block transfer more important
• But very natural to use since message are explicit and flexible
– Inherent in model
74
Synchronization
SAS: Separate from communication (data transfer)
• Programmer must orchestrate separately
Message passing
• Mutual exclusion by fiat
• Event synchronization already in send-receive match in synchronous
– need separate orchestratation (using probes or flags) in asynchronous
75
Hardware Cost and Design Complexity
Higher in SAS, and especially cache-coherent SAS
But both are more complex issues
• Cost
– must be compared with cost of replication in memory
– depends on market factors, sales volume and other nontechnical issues
• Complexity
– must be compared with complexity of writing high-performance programs
– Reduced by increasing experience
76
Performance Model
Three components:
• Modeling cost of primitive system events of different types
• Modeling occurrence of these events in workload
• Integrating the two in a model to predict performance
Second and third are most challenging
Second is the case where cache-coherent SAS is more difficult
• replication and communication implicit, so events of interest implicit
– similar to problems introduced by caching in uniprocessors
• MP has good guideline: messages are expensive, send infrequently
• Difficult for irregular applications in either case (but more so in SAS)
Block transfer, synchronization, cost/complexity, and performance
modeling advantageus for MP
77
Summary for Programming Models
Given tradeoffs, architect must address:
• Hardware support for SAS (transparent naming) worthwhile?
• Hardware support for replication and coherence worthwhile?
• Should explicit communication support also be provided in SAS?
Current trend:
• Tightly-coupled multiprocessors support for cache-coherent SAS in hw
• Other major platform is clusters of workstations or multiprocessors
– currently don’t support SAS in hardware, mostly use message passing
78
Summary
Crucial to understand characteristics of parallel programs
• Implications for a host or architectural issues at all levels
Architectural convergence has led to:
• Greater portability of programming models and software
– Many performance issues similar across programming models too
• Clearer articulation of performance issues
– Used to use PRAM model for algorithm design
– Now models that incorporate communication cost (BSP, logP,….)
– Emphasis in modeling shifted to end-points, where cost is greatest
– But need techniques to model application behavior, not just machines
79