16 482 16 561 Computer Architecture and Design

  • Slides: 24
Download presentation
16. 482 / 16. 561 Computer Architecture and Design Instructor: Dr. Michael Geiger Fall

16. 482 / 16. 561 Computer Architecture and Design Instructor: Dr. Michael Geiger Fall 2013 Lecture 8: Speculation Multithreading

Lecture outline n Announcements/reminders q q n HW 5 to be posted; due 11/18

Lecture outline n Announcements/reminders q q n HW 5 to be posted; due 11/18 No lecture Monday, 11/11 (Veterans Day) Today’s lecture q q 11/9/2020 Speculation Multithreading Computer Architecture Lecture 8 2

Review: Dynamic scheduling n Dynamic scheduling - hardware rearranges the instruction execution to reduce

Review: Dynamic scheduling n Dynamic scheduling - hardware rearranges the instruction execution to reduce stalls while maintaining data flow and exception behavior q q Key idea: Allow instructions behind stall to proceed Allow out-of-order execution and out-of-order completion We use Tomasulo’s Algorithm Decode stage now handles: n Issue—check for structural hazards and assign instruction to functional unit (via reservation station) q q Reservation stations implicitly perform register renaming n q 11/9/2020 Check for register values Resolves potential WAW, WAR hazards Results broadcast over common data bus Computer Architecture Lecture 8 3

Speculation to greater ILP 3 components of HW-based speculation: Dynamic branch prediction n 1.

Speculation to greater ILP 3 components of HW-based speculation: Dynamic branch prediction n 1. Need BTB to get target in 1 cycle q Ability to speculate past branches Dynamic scheduling In Tomasulo’s algorithm, separate instruction completion from commit 2. 3. n q q Once instruction is non-speculative, it can update registers/memory Reorder buffer tracks program order n n 11/9/2020 Head of ROB can commit when ready ROB supplies data between complete and commit Computer Architecture Lecture 8 4

Reorder Buffer Entry n 1. Each entry in the ROB contains four fields: Instruction

Reorder Buffer Entry n 1. Each entry in the ROB contains four fields: Instruction type • 2. Destination • 3. Register number (for loads and ALU operations) or memory address (for stores) where the instruction result should be written Value • 4. a branch (has no destination result), a store (has a memory address destination), or a register operation (ALU operation or load, which has register destinations) Value of instruction result until the instruction commits Ready • 11/9/2020 Indicates that instruction has completed execution, and the value is ready Computer Architecture Lecture 8 5

Speculative Tomasulo’s Algorithm 1. 2. q 3. q 4. Instruction fetch--get instruction from memory;

Speculative Tomasulo’s Algorithm 1. 2. q 3. q 4. Instruction fetch--get instruction from memory; place in Op Queue Issue—get instruction from FP Op Queue If reservation station and reorder buffer slot free, issue instr & send operands & reorder buffer no. for destination (this stage sometimes called “dispatch”) Execution—operate on operands (EX) When both operands ready then execute; if not ready, watch CDB for result; when both in reservation station, execute; checks RAW (sometimes called “issue”) Memory access--if needed (MEM) q 5. q 6. q NOTE: Stores update memory at commit, not MEM Write result—finish execution (WB) Write on Common Data Bus to all awaiting FUs & reorder buffer; mark reservation station available. Commit—update register with reorder result When instr. at head of reorder buffer & result present, update register with result (or store to memory) and remove instr from reorder buffer. Mispredicted branch flushes reorder buffer (sometimes called “graduation”) 11/9/2020 Computer Architecture Lecture 8 6

Tomasulo’s With Reorder buffer: Done? FP Op Queue ROB 7 ROB 6 Newest ROB

Tomasulo’s With Reorder buffer: Done? FP Op Queue ROB 7 ROB 6 Newest ROB 5 Reorder Buffer ROB 4 ROB 3 ROB 2 F 0 LD F 0, 10(R 2) Registers Dest 11/9/2020 ROB 1 Oldest To Memory from Memory Dest FP adders N Reservation Stations Dest 1 10+R 2 FP multipliers Computer Architecture Lecture 8 7

Revisiting stores with speculation n n With ROB, store buffers eliminated Why? q q

Revisiting stores with speculation n n With ROB, store buffers eliminated Why? q q q Can’t write memory until you know value is nonspeculative Once address is calculated, store in “destination” field of ROB entry Need additional field in ROB for stores: equivalent to “Q” fields in reservation stations n 11/9/2020 Indicates what instruction is writing value to be stored Computer Architecture Lecture 8 8

Reorder buffer example n Given the following code: L. D MUL. D S. D

Reorder buffer example n Given the following code: L. D MUL. D S. D DADDIU BNE n n F 0, F 4, R 1, 0(R 1) F 0, F 2 0(R 1) R 1, #-8 R 2, Loop Walk through two iterations of the loop Assume q q 11/9/2020 2 cycles for add, load 1 cycle for address calculation 6 cycles for multiply Forwarding via CDB Computer Architecture Lecture 8 9

Reorder buffer example: key n Execution stages points q q q n Fetch &

Reorder buffer example: key n Execution stages points q q q n Fetch & issue: always in order Execution & completion: may be out of order Commit: always in order Hardware q Reservation stations n q Occupied from IS to WB Reorder buffer n n Occupied from IS to C Used to q q q Register result status n 11/9/2020 Maintain program order for in-order commit Supply register values between WB and C Rename registers based on ROB entries Computer Architecture Lecture 8 10

Memory hazards, exceptions n Reorder buffer helps limit memory hazards q q q With

Memory hazards, exceptions n Reorder buffer helps limit memory hazards q q q With additional logic for disambiguation (determine if addresses match) WAW / WAR automatically removed RAW maintained by n n n Stalling loads if store with same address is in flight Ensuring that effective addresses are computed in order Precise exceptions logical extension of ROB q q 11/9/2020 If instruction causes exception, flag in ROB Handle exception when instruction commits Computer Architecture Lecture 8 11

Getting CPI below 1 n n CPI ≥ 1 if issue only 1 instruction

Getting CPI below 1 n n CPI ≥ 1 if issue only 1 instruction every clock cycle Multiple-issue processors come in 3 flavors: q q q n statically-scheduled superscalar processors, dynamically-scheduled superscalar processors, and VLIW (very long instruction word) processors 2 types of superscalar processors issue varying numbers of instructions per clock q q 11/9/2020 use in-order execution if they are statically scheduled, or out-of-order execution if they are dynamically scheduled Computer Architecture Lecture 8 12

Performance beyond single thread ILP n There can be much higher natural parallelism in

Performance beyond single thread ILP n There can be much higher natural parallelism in n n some applications (e. g. , Database or Scientific codes) Explicit Thread Level Parallelism or Data Level Parallelism Thread: process with own instructions and data q q n thread may be a process part of a parallel program of multiple processes, or it may be an independent program Each thread has all the state (instructions, data, PC, register state, and so on) necessary to allow it to execute Data Level Parallelism: Perform identical operations on data, and lots of data 11/9/2020 Computer Architecture Lecture 8 13

Thread Level Parallelism (TLP) n n n ILP exploits implicit parallel operations within a

Thread Level Parallelism (TLP) n n n ILP exploits implicit parallel operations within a loop or straight-line code segment TLP explicitly represented by the use of multiple threads of execution that are inherently parallel Goal: Use multiple instruction streams to improve q q n Throughput of computers that run many programs Execution time of multi-threaded programs TLP could be more cost-effective to exploit than ILP 11/9/2020 Computer Architecture Lecture 8 14

New Approach: Mulithreaded Execution n Multithreading: multiple threads to share the functional units of

New Approach: Mulithreaded Execution n Multithreading: multiple threads to share the functional units of 1 processor via overlapping q q q n processor must duplicate independent state of each thread e. g. , a separate copy of register file, a separate PC, and for running independent programs, a separate page table memory shared through the virtual memory mechanisms, which already support multiple processes HW for fast thread switch; much faster than full process switch 100 s to 1000 s of clocks When switch? q q 11/9/2020 Alternate instruction per thread (fine grain) When a thread is stalled, perhaps for a cache miss, another thread can be executed (coarse grain) Computer Architecture Lecture 8 15

Fine-Grained Multithreading n n n Switch on each instruction Usually done in a round-robin

Fine-Grained Multithreading n n n Switch on each instruction Usually done in a round-robin fashion, skipping any stalled threads CPU must be able to switch threads every clock Advantage: Hide both short/long stalls Disadvantage: slows individual threads 11/9/2020 Computer Architecture Lecture 8 16

Coarse-Grained Multithreading n n Switches only on costly stalls, such as L 2 cache

Coarse-Grained Multithreading n n Switches only on costly stalls, such as L 2 cache misses Advantages q q n Disadvantage: hard to overcome throughput losses on shorter stalls, due to pipeline start-up costs q q n Relieves need to have very fast thread-switching Doesn’t slow down individual thread Since CPU issues instructions from 1 thread, when a stall occurs, the pipeline must be emptied or frozen New thread must fill pipeline before instructions can complete Because of this start-up overhead, coarse-grained multithreading is better for reducing penalty of high cost stalls, where pipeline refill << stall time 11/9/2020 Computer Architecture Lecture 8 17

Do both ILP and TLP? n n TLP and ILP exploit two different kinds

Do both ILP and TLP? n n TLP and ILP exploit two different kinds of parallel structure in a program Could a processor oriented at ILP exploit TLP? q n n Functional units are often idle in data path designed for ILP because of either stalls or dependences in the code Could the TLP be used as a source of independent instructions that might keep the processor busy during stalls? Could TLP be used to employ the functional units that would otherwise lie idle when insufficient ILP exists? 11/9/2020 Computer Architecture Lecture 8 18

Simultaneous Multi-threading. . . One thread, 8 units Cycle M M FX FX FP

Simultaneous Multi-threading. . . One thread, 8 units Cycle M M FX FX FP FP BR CC Two threads, 8 units Cycle M M FX FX FP FP BR CC 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 M = Load/Store, FX = Fixed Point, FP = Floating Point, BR = Branch, CC = Condition Codes 11/9/2020 Computer Architecture Lecture 8 19

Simultaneous Multithreading n Simultaneous multithreading (SMT): insight that (SMT) dynamically scheduled processor already has

Simultaneous Multithreading n Simultaneous multithreading (SMT): insight that (SMT) dynamically scheduled processor already has many HW mechanisms to support multithreading q q q n Large set of virtual registers that can be used to hold the register sets of independent threads Register renaming provides unique register identifiers, so instructions from multiple threads can be mixed in datapath without confusing sources and destinations across threads Out-of-order completion allows the threads to execute out of order, and get better utilization of the HW Just adding a per thread renaming table and keeping separate PCs q 11/9/2020 Independent commitment can be supported by logically keeping a separate reorder buffer for each thread Computer Architecture Lecture 8 Source: Microprocessor Report, December 6, 1999 “Compaq Chooses SMT for Alpha” 20

Time (processor cycle) Multithreaded Categories Superscalar Simultaneous Fine-Grained. Coarse-Grained. Multiprocessing. Multithreading Thread 1 Thread

Time (processor cycle) Multithreaded Categories Superscalar Simultaneous Fine-Grained. Coarse-Grained. Multiprocessing. Multithreading Thread 1 Thread 2 11/9/2020 Thread 3 Thread 4 Computer Architecture Lecture 8 Thread 5 Idle slot 21

Design Challenges in SMT n n Since SMT makes sense only with fine-grained implementation,

Design Challenges in SMT n n Since SMT makes sense only with fine-grained implementation, impact of fine-grained scheduling on single thread performance? q A preferred thread approach sacrifices neither throughput nor single-thread performance (? ) q Unfortunately, with a preferred thread, the processor is likely to sacrifice some throughput, when preferred thread stalls Larger register file needed to hold multiple contexts Not affecting clock cycle time, especially in q Instruction issue - more candidate instructions need to be considered q Instruction completion - choosing which instructions to commit may be challenging Ensuring that cache and TLB conflicts generated by SMT do not degrade performance 11/9/2020 Computer Architecture Lecture 8 22

Multithreading examples n Assume processor with following characteristics q 4 functional units n n

Multithreading examples n Assume processor with following characteristics q 4 functional units n n n q n In-order scheduling Given 3 threads, show execution using q q Fine-grained multithreading Coarse-grained multithreading n q Assume any stall longer than 2 cycles causes switch Simultaneous multithreading n n 2 ALU 1 memory port (either load or store) 1 branch Thread 1 is preferred, followed by Thread 2 & Thread 3 Assume any two instructions without stalls between them are independent 11/9/2020 Computer Architecture Lecture 8 23

Final notes n Next time q q n Memory hierarchies Caching Reminders q q

Final notes n Next time q q n Memory hierarchies Caching Reminders q q 11/9/2020 HW 5 to be posted; due 11/18 No lecture Monday, 11/11 Computer Architecture Lecture 8 24