1 / 58

Chapter 4 Multiprocessor architecture

Chapter 4 Multiprocessor architecture. slides adapted from: http://www.cs.sunysb.edu/~cse502 David Patterson, UC-Berkeley cs252-s06 and Edelman, MIT. Currently popular models. Hardware Multicore chips (2009: mostly 2 cores and 4 cores, but doubling) (cores=processors)

padma
Download Presentation

Chapter 4 Multiprocessor architecture

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. Chapter 4 Multiprocessor architecture slides adapted from: http://www.cs.sunysb.edu/~cse502 David Patterson, UC-Berkeley cs252-s06 and Edelman, MIT

  2. Currently popular models Hardware Multicore chips (2009: mostly 2 cores and 4 cores, but doubling) (cores=processors) Servers (often 2 or 4 multicores sharing memory) Clusters (often several, to tens, and many more servers not sharing memory)

  3. Flynn’s taxonomy • SISD (uniprocessor) • SIMD (single-instruction, multiple data streams) data parallel machines • MIMD (multiple-instruction, multiple data streams) • SPMD is a special case, same program running on different processors

  4. other classifications • coarse-grained vs. fine-grained models • fine-grained: simple, identical set of processors, very large number (connection machine CM-2) • may also have a single clock driving them (synchronous processor system, e.g. systolic system) • coarse-grained: each processor is quite powerful, and can function independently

  5. Some historical machines

  6. Message passing model - MPI MPI: The Message Passing Interface Low level “lowest common denominator” language that the world has stuck with for nearly 20 years Can get performance, but can be a hindrance as well Some say that there are those that will pay for a 2x speedup, just make it easy Reality is that many want at least 10x and more for a qualitative difference in results People forget that serial performance can depend on many bottlenecks including time to memory Performance (and large problems) are the reason for parallel computing, but difficult to get the “ease of use” vs “performance” trade-off right.

  7. EXAMPLE – computing pi #include <math.h> #include "mpi.h" int main(int argc, char *argv[]) { int n, rank, size, i; double PI25DT = 3.141592653589793238462643; double mypi, pi, h, sum, x; MPI::Init(argc, argv); size = MPI::COMM_WORLD.Get_size(); rank = MPI::COMM_WORLD.Get_rank(); if (rank == 0) cin >> n;

  8. EXAMPLE – computing pi MPI::COMM_WORLD.Bcast(&n, 1, MPI::INT, 0); if (n!=0) { h = 1.0 / (double) n; sum = 0.0; for (i = rank + 1; i <= n; i += size) { x = h * ((double)i - 0.5); sum += (4.0 / (1.0 + x*x)); } mypi = h * sum; MPI::COMM_WORLD.Reduce(&mypi, &pi, 1, MPI::DOUBLE, MPI::SUM, 0); if (rank == 0) cout << "pi is approximately " << pi << ", Error is " << fabs(pi - PI25DT) << endl; } MPI::Finalize(); return 0; }

  9. Shared-memory model - OpenMP • Model for parallel programming • Shared-memory parallelism • Portable across shared-memory architectures • Scalable • Incremental parallelization • Compiler based • Extensions to existing programming languages • mainly by directives • a few library routines • Fortran and C/C++ binding • Supports data parallelism

  10. Simple OpenMP Program • Most OpenMP constructs are compiler directives or pragmas • The focus of OpenMP is to parallelize loops • OpenMP offers an incremental approach to parallelism

  11. OpenMP Programming Model • OpenMP is a shared memory model. • Workload is distributed between threads – Variables can be • shared among all threads • duplicated for each thread – Threads communicate by sharing variables • Unintended sharing of data can lead to race conditions: – race condition: when the program’s outcome changes as the threads are scheduled differently. • To control race conditions: – Use synchronization to protect data conflicts. • Careless use of synchronization can lead to dead-locks

  12. Thinking In Parallel Usually when we formulate a computation, we think of a sequential solution. Good parallel computations rarely result from transforming a sequential solution. A paradigm shift is required. So, it is essential to acquire a “parallel point of view” to produce good parallel computations from the start

  13. Parallel hardware design Many problems can be modeled as a prefix product problem: Given x1, x2, …, xn, compute: y1 = x1 y2 = x1 * x2 … yn = x1 * x2 * … * xn We will design an efficient hardware design for this problem.

  14. x1 x2 x3 x4 x5 x6 x7 x8 Parallel Prefix circuit P0 P1 P2 P3 x1 x1-2 x1-3 x1-4 x1-5 x1-6 x1-7 x1-8 c-- c1-2 c1-4 c1-6 c-- c1-4 s1-8 c1-4 s1-4 s5-8 c1-2 c5-6 s1,2 s3,4 s5,6 s7,8 c1 c3 c5 c7

  15. Two hardware models • “A parallel computer is a collection of processing elements that cooperate and communicate to solve large problems fast.” • Parallel Architecture = Processor Architecture + Communication Architecture • Two classes of multiprocessors with respect to memory: • Centralized Memory Multiprocessor • < few dozen processor chips (and < 100 cores) in 2006 • Small enough to share a single, centralized memory • Physically Distributed-Memory Multiprocessor • Larger number of chips and cores than centralized class 1. • BW demands  Memory distributed among processors • Distributed shared memory ≤ 256 processors, but easier to code • Distributed distinct memories > 1 million processors

  16. P P n 1 P P n 1 $ $ $ $ Mem Mem Inter connection network Inter connection network Mem Mem Centralized vs. Distributed Memory Distributed Memory Centralized Memory

  17. Processor-to-Memory Interconnection Network Butterfly and the related Beneš network as examples of processor-to-memory interconnection network in a multiprocessor.

  18. Centralized Memory Multiprocessor • Also called symmetric multiprocessors (SMPs) because single main memory has a symmetric relationship to all processors • Large caches  a single memory can satisfy the memory demands of small number of processors using a single, shared memory bus • Can scale to a few dozen processors by using a (crossbar) switch and many memory banks • Although scaling beyond that is technically conceivable, it becomes less attractive as the number of processors sharing centralized memory increases

  19. Distributed Memory Multiprocessor • Pro: Cost-effective way to scale memory bandwidth • If most accesses are to local memory (if < 1 to 10% remote, shared writes) • Pro: Reduces latency of local memory accesses • Con: Communicating data between processors more complex • Con: Must change software to take advantage of increased memory BW

  20. Two Models for Communication and Memory Architecture • Communication occurs by explicitly passing (high latency) messages among the processors: message-passing multiprocessors • Communication occurs through a shared addressspace (via loads and stores): distributed shared memory multiprocessorseither • UMA (Uniform Memory Access time) for shared address, centralized memory MP • NUMA (Non-Uniform Memory Access time multiprocessor) for shared address, distributed memory MP

  21. Challenges of Parallel Processing • First challenge is % of program that is inherently sequential • For 80X speedup from 100 processors, what fraction of original program can be sequential? • 10% • 5% • 1% • <1%

  22. Amdahl’s law

  23. Challenges of Parallel Processing • Challenge 2 is long latency to remote memory • Suppose 32 CPU MP, 2GHz, 200 ns (= 400 clocks) remote memory, all local accesses hit memory cache, and base CPI is 0.5. • How much slower if 0.2% of instructions access remote data? • 1.4X • 2.0X • 2.6X

  24. Challenges of Parallel Processing • Challenge 2 is long latency to remote memory • Suppose 32 CPU MP, 2GHz, 200 ns (= 400 clocks) remote memory, all local accesses hit memory cache, and base CPI is 0.5. • How much slower if 0.2% of instructions access remote data? • 1.4X • 2.0X • 2.6X CPI0.2% = Base CPI(no remote access) + Remote request rate x Remote request cost CPI0.2% = 0.5 + 0.2% x 400 = 0.5 + 0.8 = 1.3 No remote communication is 1.3/0.5 or 2.6 times faster than if 0.2% of instructions access one remote datum.

  25. Solving Challenges of Parallel Processing • Application parallelism  primarily need new algorithms with better parallel performance • Long remote latency impact  both by architect and by the programmer • For example, reduce frequency of remote accesses either by • Caching shared data (HW), efficient design to reduce the path between processors (HW) • Restructuring the data layout to make more accesses local (SW) • One approach is to reduce memory access latency via local caches

  26. Symmetric Shared-Memory Architectures • From multiple boards on a shared bus to multiple processors inside a single chip • Caches store both • Private data used by a single processor • Shared data used by multiple processors • Caching shared data  reduces both latency to shared data, memory bandwidth for shared data,and interconnect bandwidth needed;but  introduces cache coherence problem

  27. u = ? u = ? u =7 5 4 3 1 2 u u u :5 :5 :5 Cache Coherence Problem • Processors see different values for u after event 3 (new 7vs old 5) • With write-back caches, value written back to memory depends on happenstance of which cache flushes or writes back value when • Processes accessing main memory may see old values • Unacceptable for programming; writes to shared data frequent! P P P 2 1 3 $ $ $ I/O devices Memory

  28. Defining Coherent Memory System • Preserve Program Order: A read by processor P to location X that follows a write by P to X, with no writes of X by another processor occurring between the write and the read by P, always returns the value written by P • Coherent view of memory: A read by one processor to location X that follows a write by anotherprocessor to X returns the newly written value if the read and write are sufficiently separated in time and no other writes to X occur between the two accesses • Write serialization: Two writes to same location by any 2 processors are seen in the same order by all processors • For example, if the values 1 and then 2 are written to a location, processors can never read the value of the location as 2 and then later read it as 1

  29. Write Consistency (for writes to 2+ variables) For now assume • A write does not complete (and allow any next write to occur) until all processors have seen the effect of the write • The processor does not change the order of any write with respect to any other memory access  if a processor writes location A followed by location B, any processor that sees the new value of B must also see the new value of A These restrictions allow processors to reorder reads, but forces all processors to finish writes in program order

  30. Basic Schemes for Enforcing Coherence • A program on multiple processors will normally have copies of the same data in several caches • Unlike in the uniprocessor case • Rather than trying to avoid sharing, SMPs use a HW protocol to maintain coherent caches • Migration and replication are key to performance for shared data • Migration - data can be moved to a local cache and used there in a transparent fashion • Reduces both latency to access shared data that is allocated remotely and bandwidth demand on the shared memory and interconnection • Replication – for shared data being simultaneously read, since caches make a copy of data in local cache • Reduces both latency of access and contention for read-shared data

  31. Two Classes of Cache Coherence Protocols • Directory based — Sharing status of a block of physical memory is kept in just one location, the directory entry for that block • Snooping (“Snoopy”) — Every cache with a copy of a data block also has a copy of the sharing status of the block, but no centralized state is kept • All caches have access to writes and cache misses via some broadcast medium (a bus or switch) • All cache controllers monitor or snoop on the shared medium to determine whether or not they have a local cache copy of each block that is requested by a bus or switch access

  32. State Address Data Snoopy Cache-Coherence Protocols • Cache Controller “snoops” on all transactions on the shared medium (bus or switch) • a transaction is relevant if it is for a block the cache contains • If relevant, a cache controller takes action to ensure coherence • invalidate, update, or supply the latest value • depends on state of the block and the protocol • A cache either gets exclusive access before a write via write invalidate or updates all copies when it writes

  33. u = ? u = ? u = 7 5 4 3 1 2 u u u :5 :5 :5 u = 7 Example: Write-Thru Invalidate • Must invalidate P1’s cache copy u:5 before step 3 • Write update uses more broadcast medium BW (must share both address and new value) all recent MPUs use write invalidate (share address) P P P 2 1 3 $ $ $ I/O devices Memory

  34. Architectural Building Blocks • Cache block state transition diagram • FiniteStateMachine specifying how disposition of block changes • Minimum number of states 3: invalid, valid, dirty • Broadcast Medium Transactions (e.g., bus) • Fundamental system design abstraction • Logically single set of wires connect several devices • Protocol: arbitration, command/addr, data • Every device observes every transaction • Broadcast medium enforces serialization of read or write accesses  Write serialization • 1st processor to get medium invalidates others’ copies • Implies cannot complete write until it obtains bus • All coherence schemes require serializing accesses to same cache block • Also need to find up-to-date copy of cache block (may be in last written cache but not in memory)

  35. Locate up-to-date copy of data • Write-through: get up-to-date copy from memory • Write-through simpler if enough memory BW to support it • Write-back harder, but uses must less memory BW • Most recent copy can be in a cache • Can use same snooping mechanism • Snoop every address placed on the bus • If a processor has dirty copy of requested cache block, it provides it in response to a read request and aborts the memory access • Complexity of retrieving cache block from a processor cache, which can take longer than retrieving it from memory • Write-back needs lower memory bandwidth Support larger numbers of faster processors  Most multiprocessors use write-back

  36. Cache Resources for WriteBack Snooping • Normal cache indices + tags can be used for snooping • Valid bit per cache block makes invalidation easy • Read misses easy since rely on snooping • Writes  Need to know whether any other copies of the block are cached • No other copies  No need to place write on bus for WB • Other copies  Need to place invalidate on bus

  37. Cache Resources for WB Snooping (cont.) • To track whether a cache block is shared, add an extra state bit associated with each cache block, like the valid bit and the dirty bit • Write to Shared block  Need to place invalidate on bus and mark own cache block as exclusive (if have this option) • No further invalidations will be sent for that block • This processor is called the owner of the cache block • Owner then changes state from shared to unshared (or “exclusive”)

  38. Cache Behavior in Response to Bus • Every bus transaction must check the cache-address tags • could potentially interfere with processor cache accesses • one way to reduce interference is to duplicate tags • One set for CPU cache accesses, one set for bus accesses • Another way to reduce interference is to use L2 tags • Since Level2 caches less heavily used than L1 caches  Every entry in L1 cache must be present in the L2 cache, called the inclusion property • If Snoop gets a hit in L2 cache, then L2 must arbitrate for the L1 cache to update its block state and possibly retrieve the new data, which usually requires a stall of the processor

  39. Example Protocol • Snooping coherence protocol is usually implemented by incorporating a finite-state machine controller (FSM) in each node • Logically, think of a separate controller associated with each cache block • That is, snooping operations or cache requests for different blocks can proceed independently • In implementations, a single controller allows multiple operations to distinct blocks to proceed in interleaved fashion • that is, one operation may be initiated before another is completed, even through only one cache access or one bus access is allowed at a time

  40. PrRd/ -- PrWr / BusWr P P n 1 V $ $ BusWr / - Bus I/O devices Mem PrRd / BusRd I PrWr / BusWr “non-allocate” State Tag Data State Tag Data Write-through Snoopy Invalidate Protocol • 2 states per block in each cache • as in uniprocessor (Valid, Invalid) • state of a block is a p-vector of states • Hardware state bits are associated with blocks that are in the cache • other blocks can be seen as being in invalid (not-present) state in that cache • Writes invalidate all other cache copies • can have multiple simultaneous readers of a block, but each write invalidates other copies held by multiple readers PrRd:Processor Read PrWr: Processor Write BusRd: Bus Read BusWr: Bus Write

  41. Is Two-State Protocol Coherent? • Processor only observes state of memory system by issuing memory operations • Assume bus transactions and memory operations are atomic and each processor has a one-level cache • all phases of one bus transaction complete before next one starts • processor waits for memory operation to complete before issuing next • with one-level cache, assume invalidations applied during bus transaction • All writes go to bus + atomicity • Writes serialized by order in which they appear on bus (bus order) => invalidations applied to caches in bus order • How to insert reads in this order? • Important since processors see writes through reads, which determine whether write serialization is satisfied • But read hits may happen independently and do not appear on bus or enter directly in bus order • Let’s understand other ordering issues

  42. Ordering • Writes establish a partial order • Does not constrain ordering of reads, though shared-medium (bus) will order read misses too • any order of reads by different CPUs between writes is fine, so long as in program order for each CPU

  43. Example Write-Back Snoopy Protocol • Invalidation protocol, write-back cache • Each cache controller snoops every address on shared bus • If cache has a dirty copy of requested block, provides that block in response to the read request and aborts the memory access • Each memory block is in one state: • Clean in all caches and up-to-date in memory (Shared) • OR Dirty in exactly one cache (Exclusive) • OR Not in any caches • Each cache block is in one state (track these): • Shared : block can be read • OR Exclusive : cache has only copy, its writeable, and dirty • OR Invalid : block contains no data (used in uniprocessor cache too) • Read misses: cause all caches to snoop bus • Writes to clean blocks are treated as misses

  44. CPU Read hit Write-Back State Machine - CPU • State machinefor CPU requestsfor each cache block • Non-resident blocks invalid CPU Read Shared (read/only) Invalid Place read miss on bus Cache Block States CPU Write Place Write Miss on bus CPU Write Place Write Miss on Bus CPU read hit CPU write hit Exclusive (read/write) CPU Read or Write Miss (if must replace this block) Write back cache block Place read or write miss on bus (see 2nd slide after this)

  45. Write-Back State Machine - Bus Requests • State machinefor bus requests for each cache block (another CPU has accessed this block) Write missfor this block Shared (read/only) Invalid Cache Block States Write missfor this block Write Back Block; (abort memory access) Read miss for this block Write Back Block; (abort memory access) Exclusive (read/write)

  46. Block-Replacement CPU Read hit • State machinefor CPU requestsfor each cache block If must replace this block CPU Read Shared (read/only) Invalid Place read miss on bus CPU Write CPU Read miss Place read miss on bus CPU read miss Write back block, Place read miss on bus Place Write Miss on bus CPU Write Place Write Miss on Bus Cache Block States Exclusive (read/write) CPU Write Miss Write back cache block Place write miss on bus CPU read hit CPU write hit

  47. Write-back State Machine - All Requests CPU Read hit Write missfor this block • State machinefor CPU requestsfor each cache block andfor bus requests for each cache block Shared (read/only) CPU Read Invalid Place read miss on bus CPU Write Place Write Miss on bus Write missfor this block Write Back Block; (abort memory access) CPU Read miss Place read miss on bus CPU read miss Write back block, Place read miss on bus CPU Write Place Write Miss on Bus Read miss for this block Cache Block States Write Back Block; (abort memory access) Exclusive (read/write) CPU read hit CPU write hit CPU Write Miss Write back cache block Place write miss on bus

  48. Example Assumes A1 maps to the same cache block on both CPUs and each initial cache block state for A1 is invalid (last slide in this example also assumes that addresses A1 and A2 map to the same block index but have different address tags, so they are in different cache blocks that complete for the same location in the cache).

  49. Example Assumes A1 maps to the same cache block on both CPUs

  50. Example Assumes A1 maps to the same cache block on both CPUs

More Related