1 / 52

Hardware/Software Performance Tradeoffs (plus Msg Passing Finish)

Hardware/Software Performance Tradeoffs (plus Msg Passing Finish). CS 258, Spring 99 David E. Culler Computer Science Division U.C. Berkeley. SAS Recap. Partitioning = Decomposition + Assignment Orchestration = coordination and communication SPMD, Static Assignment Implicit communication

betty_james
Télécharger la présentation

Hardware/Software Performance Tradeoffs (plus Msg Passing Finish)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hardware/Software Performance Tradeoffs(plus Msg Passing Finish) CS 258, Spring 99 David E. Culler Computer Science Division U.C. Berkeley

  2. SAS Recap • Partitioning = Decomposition + Assignment • Orchestration = coordination and communication • SPMD, Static Assignment • Implicit communication • Explicit Synchronization: barriers, mutex, events CS258 S99.5

  3. Message Passing Grid Solver • Cannot declare A to be global shared array • compose it logically from per-process private arrays • usually allocated in accordance with the assignment of work • process assigned a set of rows allocates them locally • Transfers of entire rows between traversals • Structurally similar to SPMD SAS • Orchestration different • data structures and data access/naming • communication • synchronization • Ghost rows CS258 S99.5

  4. P 0 P 0 P 1 P 1 P 2 P 4 P 2 Data partition allocated per processor Add ghost rows to hold boundary data Send edges to neighbors P 4 Receive into ghost rows Data Layout and Orchestration Compute as in sequential program CS258 S99.5

  5. CS258 S99.5

  6. Notes on Message Passing Program • Use of ghost rows • Receive does not transfer data, send does • unlike SAS which is usually receiver-initiated (load fetches data) • Communication done at beginning of iteration, so no asynchrony • Communication in whole rows, not element at a time • Core similar, but indices/bounds in local rather than global space • Synchronization through sends and receives • Update of global diff and event synch for done condition • Could implement locks and barriers with messages • REDUCE and BROADCAST simplify code CS258 S99.5

  7. Send/Receive Synchronous Asynchronous Blocking asynch. Nonblocking asynch. Send and Receive Alternatives • extended functionality: stride, scatter-gather, groups • Sychronization semantics • Affect when data structures or buffers can be reused at either end • Affect event synch (mutual excl. by fiat: only one process touches data) • Affect ease of programming and performance • Synchronous messages provide built-in synch. through match • Separate event synchronization may be needed with asynch. messages • With synch. messages, our code may hang. Fix? CS258 S99.5

  8. Orchestration: Summary • Shared address space • Shared and private data (explicitly separate ??) • Communication implicit in access patterns • Data distribution not a correctness issue • Synchronization via atomic operations on shared data • Synchronization explicit and distinct from data communication • Message passing • Data distribution among local address spaces needed • No explicit shared structures • implicit in comm. patterns • Communication is explicit • Synchronization implicit in communication • mutual exclusion by fiat CS258 S99.5

  9. Correctness in Grid Solver Program • Decomposition and Assignment similar in SAS and message-passing • Orchestration is different • Data structures, data access/naming, communication, synchronization • Performance? CS258 S99.5

  10. Performance Goal => Speedup • Architect Goal • observe how program uses machine and improve the design to enhance performance • Programmer Goal • observe how the program uses the machine and improve the implementation to enhance performance • What do you observe? • Who fixes what? CS258 S99.5

  11. Sequential Work Speedup < Max (Work + Synch Wait Time + Comm Cost + Extra Work) Analysis Framework • Solving communication and load balance NP-hard in general case • But simple heuristic solutions work well in practice • Fundamental Tension among: • balanced load • minimal synchronization • minimal communication • minimal extra work • Good machine design mitigates the trade-offs CS258 S99.5

  12. Sequential Work Sequential Work Max Work on any Processor Speedup problem(p) < Max (Work + Synch Wait Time) P0 P0 P1 P1 P2 P2 P3 P3 Load Balance and Synchronization • Instantaneous load imbalance revealed as wait time • at completion • at barriers • at receive • at flags, even at mutex CS258 S99.5

  13. P 0 P 1 P 2 P 4 Improving Load Balance • Decompose into more smaller tasks (>>P) • Distribute uniformly • variable sized task • randomize • bin packing • dynamic assignment • Schedule more carefully • avoid serialization • estimate work • use history info. for_all i = 1 to n do for_all j = i to n do A[ i, j ] = A[i-1, j] + A[i, j-1] + ... CS258 S99.5

  14. Example: Barnes-Hut • Divide space into roughly equal # particles • Particles close together in space should be on same processor • Nonuniform, dynamically changing CS258 S99.5

  15. Dynamic Scheduling 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 CS258 S99.5

  16. Impact of Dynamic Assignment • Barnes-Hut on SGI Origin 2000 (cache-coherent shared memory): CS258 S99.5

  17. Self-Scheduling volatile int row_index = 0; /* shared index variable */ while (not done) { initialize row_index; barrier; while ((i = fetch_and_inc(&row_index) < n) { for (j = i; j < n; j++) { A[ i, j ] = A[i-1, j] + A[i, j-1] + ... } } } CS258 S99.5

  18. 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 • Stagger critical sections in time CS258 S99.5

  19. Impact of Efforts to Balance Load • Parallelism Management overhead? • Communication? • amount, size, frequency? • Synchronization? • type? frequency? • Opportunities for replication? • What can architecture do? CS258 S99.5

  20. Arch. Implications of Load Balance • Naming • global position independent naming separates decomposition from layout • allows diverse, even dynamic assignments • Efficient Fine-grained communication & synch • more, smaller • msgs • locks • point-to-point • Automatic replication CS258 S99.5

  21. Sequential Work Speedup < Max (Work + Synch Wait Time + Comm Cost + Extra Work) 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 CS258 S99.5

  22. Sequential Work Speedup < Max (Work + Synch Wait Time + Comm Cost) Reducing Inherent Communication • Communication is expensive! • Measure: communication to computation ratio • Inherent communication • Determined by assignment of tasks to processes • One produces data consumed by others => Use algorithms that communicate less => Assign tasks that access same data to same process • same row or block to same process in each iteration CS258 S99.5

  23. 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 • Simple example: nearest-neighbor grid computation • Perimeter to Area comm-to-comp ratio (area to volume in 3-d) • Depends on n,p: decreases with n, increases with p CS258 S99.5

  24. 4*√p n Domain Decomposition (contd) Best domain decomposition depends on information requirements Nearest neighbor example: block versus strip decomposition: • Comm to comp: for block, for strip • Application dependent: strip may be better in other cases • E.g. particle flow in tunnel 2*p n CS258 S99.5

  25. Relation to load balance • Scatter Decomposition, e.g. initial partition in Raytrace • Preserve locality in task stealing • Steal large tasks for locality, steal from same queues, ... CS258 S99.5

  26. Sequential Work Speedup < Max (Work + Synch Wait Time + Comm Cost) Implications of Comm-to-Comp Ratio • Architects examine application needs to see where to spend effort • bandwidth requirements (operations / sec) • latency requirements (sec/operation) • time spent waiting • Actual impact of comm. depends on structure and cost as well • Need to keep communication balanced across processors as well CS258 S99.5

  27. nc/m B Structuring Communication • Given amount of comm, goal is to reduce cost • Cost of communication as seen by process: C = f * ( o + l + + tc - overlap) • 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) • ignoring overlap, is latency of a message • Goal: reduce terms in latency and increase overlap CS258 S99.5

  28. Reducing Overhead • Can reduce no. of messages m or overhead per message o • o is usually determined by hardware or system software • Program should try to reduce m by coalescing messages • More control when communication is explicit • Coalescing data into larger messages: • Easy for regular, coarse-grained communication • Can be difficult for irregular, naturally fine-grained communication • may require changes to algorithm and extra work • coalescing data and determining what and to whom to send • will discuss more in implications for programming models later CS258 S99.5

  29. Reducing Network Delay • Network delay component = f*h*th • h = number of hops traversed in network • th= link+switch latency per hop • Reducing f: communicate less, or make messages larger • Reducing h: • Map communication patterns to network topology • e.g. nearest-neighbor on mesh and ring; all-to-all • How important is this? • used to be major focus of parallel algorithms • depends on no. of processors, how th, compares with other components • less important on modern machines • overheads, processor count, multiprogramming CS258 S99.5

  30. 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 • Particularly insidious performance problem • Easy to ignore when programming • Slow down messages that don’t even need that resource • by causing other dependent resources to also congest • Effect can be devastating: Don’t flood a resource! CS258 S99.5

  31. 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 • Module: all-to-all personalized comm. in matrix transpose • solution: stagger access by different processors to same node temporally • In general, reduce burstiness; may conflict with making messages larger CS258 S99.5

  32. Overlapping Communication • Cannot afford to stall for high latencies • even on uniprocessors! • Overlap with computation or communication to hide latency • Requires extra concurrency (slackness), higher bandwidth • Techniques: • Prefetching • Block data transfer • Proceeding past communication • Multithreading CS258 S99.5

  33. Communication Scaling (NPB2) Normalized Msgs per Proc Average Message Size CS258 S99.5

  34. Communication Scaling: Volume CS258 S99.5

  35. What is a Multiprocessor? • A collection of communicating processors • View taken so far • Goals: balance load, reduce inherent communication and extra work • A multi-cache, multi-memory system • Role of these components essential regardless of programming model • Prog. model and comm. abstr. affect specific performance tradeoffs CS258 S99.5

  36. Memory-oriented View • Multiprocessor as Extended Memory Hierarchy • as seen by a given processor • Levels in extended hierarchy: • Registers, caches, local memory, remote memory (topology) • Glued together by communication architecture • Levels communicate at a certain granularity of data transfer • Need to exploit spatial and temporal locality in hierarchy • Otherwise extra communication may also be caused • Especially important since communication is expensive CS258 S99.5

  37. 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 • Data access time can be reduced by: • Optimizing machine: bigger caches, lower latency... • Optimizing program: temporal and spatial locality CS258 S99.5

  38. 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 • Levels closer to processor are lower latency and higher bandwidth • Improve performance through architecture or program locality • Tradeoff with parallelism; need good node performance and parallelism CS258 S99.5

  39. Artifactual Communication • Accesses not satisfied in local portion of memory hierachy 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. CS258 S99.5

  40. 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 • View as three level hierarchy for simplicity • Local cache, local memory, remote memory (ignore network topology) • Classify “misses” in “cache” at any level as for uniprocessors • compulsory or cold misses (no size effect) • capacity misses (yes) • conflict or collision misses (yes) • communication or coherence misses (no) • Each may be helped/hurt by large transfer granularity (spatial locality) CS258 S99.5

  41. fic First working set Data traf Capacity-generated traf fic (including conflicts) Second working set Other capacity-independent communication Inher ent communication Cold-start (compulsory) traf fic Replication capacity (cache size) Working Set Perspective • At a given level of the hierarchy (to the next further one) • Hierarchy of working sets • At first level cache (fully assoc, one-word block), inherent to algorithm • working set curve for program • Traffic from any type of miss can be local or nonlocal (communication) CS258 S99.5

  42. 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 • Structuring communication to reduce cost CS258 S99.5

  43. Reducing Artifactual Communication • Message passing model • Communication and replication are both explicit • Even artifactual communication is in explicit messages • send data that is not used • Shared address space model • More interesting from an architectural perspective • Occurs transparently due to interactions of program and system • sizes and granularities in extended memory hierarchy • Use shared address space to illustrate issues CS258 S99.5

  44. (a) Unblocked access pattern in a sweep (b) Blocked access pattern with B = 4 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 • More useful when O(nk+1)computation on O(nk) data • many linear algebra computations (factorization, matrix multiply) CS258 S99.5

  45. Exploiting Spatial Locality • Besides capacity, granularities are important: • Granularity of allocation • Granularity of communication or data transfer • Granularity of coherence • Major spatial-related causes of artifactual communication: • Conflict misses • Data distribution/layout (allocation granularity) • Fragmentation (communication granularity) • False sharing of data (coherence granularity) • All depend on how spatial access patterns interact with data structures • Fix problems by modifying data structures, or layout/alignment • Examine later in context of architectures • one simple example here: data distribution in SAS solver CS258 S99.5

  46. Contiguity in memory layout P P P P P P P P 0 1 2 3 0 1 2 3 P P P P 4 5 6 7 P P P P 4 5 6 7 P P 8 8 Page straddles partition boundaries: difficult to distribute memory well Page does not straddle partition boundary Cache block straddles partition boundary Cache block is within a partition (a) Two-dimensional array (b) Four-dimensional array Spatial Locality Example • Repeated sweeps over 2-d grid, each time adding 1 to elements • Natural 2-d versus higher-dimensional array representation CS258 S99.5

  47. 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? • Granularities of allocation, communication, coherence (?) • small granularities => high overheads, but easier to program • Machine granularity (resource division among processors, memory...) CS258 S99.5

  48. 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 Poor spacial locality on nonlocal accesses at column-oriented boundary • Result depends on n and p CS258 S99.5

  49. Example Performance Impact • Equation solver on SGI Origin2000 CS258 S99.5

  50. Working Sets Change with P 8-fold reduction in miss rate from 4 to 8 proc CS258 S99.5

More Related