Lecture 5: Pipelining & Instruction Level Parallelism Professor Alvin R. Lebeck Computer Science 220 Fall 2001.

Slides:



Advertisements
Similar presentations
Instruction-level Parallelism Compiler Perspectives on Code Movement dependencies are a property of code, whether or not it is a HW hazard depends on.
Advertisements

1 Lecture 3 Pipeline Contd. (Appendix A) Instructor: L.N. Bhuyan CS 203A Advanced Computer Architecture Some slides are adapted from Roth.
ENGS 116 Lecture 101 ILP: Software Approaches Vincent H. Berk October 12 th Reading for today: , 4.1 Reading for Friday: 4.2 – 4.6 Homework #2:
CPE 631: ILP, Static Exploitation Electrical and Computer Engineering University of Alabama in Huntsville Aleksandar Milenkovic,
1 4/20/06 Exploiting Instruction-Level Parallelism with Software Approaches Original by Prof. David A. Patterson.
FTC.W99 1 Advanced Pipelining and Instruction Level Parallelism (ILP) ILP: Overlap execution of unrelated instructions gcc 17% control transfer –5 instructions.
Eliminating Stalls Using Compiler Support. Instruction Level Parallelism gcc 17% control transfer –5 instructions + 1 branch –Reordering among 5 instructions.
ILP: Loop UnrollingCSCE430/830 Instruction-level parallelism: Loop Unrolling CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
Lecture 6: ILP HW Case Study— CDC 6600 Scoreboard & Tomasulo’s Algorithm Professor Alvin R. Lebeck Computer Science 220 Fall 2001.
EECC551 - Shaaban #1 Fall 2003 lec# Pipelining and Exploiting Instruction-Level Parallelism (ILP) Pipelining increases performance by overlapping.
EEL Advanced Pipelining and Instruction Level Parallelism Lotzi Bölöni.
Computer Architecture Instruction Level Parallelism Dr. Esam Al-Qaralleh.
COMP 4211 Seminar Presentation Based On: Computer Architecture A Quantitative Approach by Hennessey and Patterson Presenter : Feri Danes.
CS 152 Lec 14.1 CS 152: Computer Architecture and Engineering Lecture 14 Advanced Pipelining/Compiler Scheduling Randy H. Katz, Instructor Satrajit Chatterjee,
EENG449b/Savvides Lec /24/04 March 24, 2004 Prof. Andreas Savvides Spring EENG 449bG/CPSC 439bG Computer.
CS152 Lec15.1 Advanced Topics in Pipelining Loop Unrolling Super scalar and VLIW Dynamic scheduling.
Instruction Set Issues MIPS easy –Instructions are only committed at MEM  WB transition Other architectures are more difficult –Instructions may update.
Lecture 3: Chapter 2 Instruction Level Parallelism Dr. Eng. Amr T. Abdel-Hamid CSEN 601 Spring 2011 Computer Architecture Text book slides: Computer Architec.
Static Scheduling for ILP Professor Alvin R. Lebeck Computer Science 220 / ECE 252 Fall 2008.
CS252 Graduate Computer Architecture Lecture 6 Static Scheduling, Scoreboard February 6 th, 2012 John Kubiatowicz Electrical Engineering and Computer Sciences.
DAP.F96 1 Lecture 4: Hazards, Introduction to Compiler Techniques, Chapter 2.
Lecture 6: Pipelining MIPS R4000 and More Kai Bu
Pipeline ComplicationsCS510 Computer ArchitecturesLecture Lecture 8 Advanced Pipeline.
1 IF IDEX MEM L.D F4,0(R2) MUL.D F0, F4, F6 ADD.D F2, F0, F8 L.D F2, 0(R2) WB IF IDM1 MEM WBM2M3M4M5M6M7 stall.
1 Lecture: Pipeline Wrap-Up and Static ILP Topics: multi-cycle instructions, precise exceptions, deep pipelines, compiler scheduling, loop unrolling, software.
EECC551 - Shaaban #1 Winter 2002 lec# Pipelining and Exploiting Instruction-Level Parallelism (ILP) Pipelining increases performance by overlapping.
CS152 Computer Architecture and Engineering Lecture 13 Static Pipeline Scheduling Compiler Optimizations March 15, 2004 John Kubiatowicz (http.cs.berkeley.edu/~kubitron)
EECC551 - Shaaban #1 Spring 2006 lec# Pipelining and Instruction-Level Parallelism. Definition of basic instruction block Increasing Instruction-Level.
EECC551 - Shaaban #1 Fall 2005 lec# Pipelining and Instruction-Level Parallelism. Definition of basic instruction block Increasing Instruction-Level.
CS252/Kubiatowicz Lec 5.1 9/10/99 CS252 Graduate Computer Architecture Lecture 5 Introduction to Advanced Pipelining September 10, 1999 Prof. John Kubiatowicz.
1 Lecture 5: Pipeline Wrap-up, Static ILP Basics Topics: loop unrolling, VLIW (Sections 2.1 – 2.2) Assignment 1 due at the start of class on Thursday.
Chapter 2 Instruction-Level Parallelism and Its Exploitation
EECC551 - Shaaban #1 Fall 2002 lec# Floating Point/Multicycle Pipelining in MIPS Completion of MIPS EX stage floating point arithmetic operations.
COMP381 by M. Hamdi 1 Pipelining Control Hazards and Deeper pipelines.
EENG449b/Savvides Lec /24/05 February 24, 2005 Prof. Andreas Savvides Spring EENG 449bG/CPSC 439bG.
DAP.F96 1 Lecture 9: Introduction to Compiler Techniques Chapter 4, Sections L.N. Bhuyan CS 203A.
EECC551 - Shaaban #1 Winter 2011 lec# Pipelining and Instruction-Level Parallelism (ILP). Definition of basic instruction block Increasing Instruction-Level.
ENGS 116 Lecture 61 Pipelining Difficulties and MIPS R4000 Vincent H. Berk October 6, 2008 Reading for today: A.3 – A.4, article: Yeager Reading for Wednesday:
EECC551 - Shaaban #1 Spring 2004 lec# Definition of basic instruction blocks Increasing Instruction-Level Parallelism & Size of Basic Blocks.
COMP381 by M. Hamdi 1 Loop Level Parallelism Instruction Level Parallelism: Loop Level Parallelism.
CS252/Kubiatowicz Lec 4.1 9/13/00 CS252 Graduate Computer Architecture Lecture 4 Control flow and interrupts (cont’d) Software Scheduling around hazards.
Pipelining and Exploiting Instruction-Level Parallelism (ILP)
ENGS 116 Lecture 51 Pipelining and Hazards Vincent H. Berk September 30, 2005 Reading for today: Chapter A.1 – A.3, article: Patterson&Ditzel Reading for.
EECC551 - Shaaban #1 Fall 2001 lec# Floating Point/Multicycle Pipelining in DLX Completion of DLX EX stage floating point arithmetic operations.
CS252 Graduate Computer Architecture Lecture 5 Software Scheduling around Hazards Out-of-order Scheduling February 2 nd, 2011 John Kubiatowicz Electrical.
CS252 Graduate Computer Architecture Lecture 5 Interrupts, Software Scheduling around Hazards February 1 st, 2012 John Kubiatowicz Electrical Engineering.
1 Appendix A Pipeline implementation Pipeline hazards, detection and forwarding Multiple-cycle operations MIPS R4000 CDA5155 Spring, 2007, Peir / University.
CSC 4250 Computer Architectures September 26, 2006 Appendix A. Pipelining.
Pipeline ComplicationsCS510 Computer ArchitecturesLecture Lecture 8 Advanced Pipeline.
CIS 662 – Computer Architecture – Fall Class 16 – 11/09/04 1 Compiler Techniques for ILP  So far we have explored dynamic hardware techniques for.
LECTURE 10 Pipelining: Advanced ILP. EXCEPTIONS An exception, or interrupt, is an event other than regular transfers of control (branches, jumps, calls,
Review Professor Alvin R. Lebeck Compsci 220 / ECE 252 Fall 2006.
Instruction-Level Parallelism and Its Dynamic Exploitation
Compiler Techniques for ILP
Lecture 07: Pipelining Multicycle, MIPS R4000, and More
CS203 – Advanced Computer Architecture
Appendix C Pipeline implementation
CSCE430/830 Computer Architecture
Lecture 3: Introduction to Advanced Pipelining
Pipelining: Advanced ILP
Pipelining Multicycle, MIPS R4000, and More
Pipelining and Exploiting Instruction-Level Parallelism (ILP)
Pipelining and Exploiting Instruction-Level Parallelism (ILP)
CS252 Graduate Computer Architecture Lecture 5 Software Scheduling around Hazards Out-of-order Scheduling John Kubiatowicz Electrical Engineering and.
Pipelining and Exploiting Instruction-Level Parallelism (ILP)
Pipelining and Exploiting Instruction-Level Parallelism (ILP)
Pipelining and Exploiting Instruction-Level Parallelism (ILP)
Pipelining and Exploiting Instruction-Level Parallelism (ILP)
CMSC 611: Advanced Computer Architecture
Pipelining and Exploiting Instruction-Level Parallelism (ILP)
Presentation transcript:

Lecture 5: Pipelining & Instruction Level Parallelism Professor Alvin R. Lebeck Computer Science 220 Fall 2001

2 © Alvin R. Lebeck 2001 CPS 220 Todo Homework #1 Due Read Chapter 4 Homework #2 Due September 25 Project selection by October 1 Today Finish simple pipelining Start ILP and Scheduling to expose ILP

3 © Alvin R. Lebeck 2001 CPS 220 Review: Hazards Data Hazards RAW –only one that can occur in current DLX pipeline WAR, WAW Data Forwarding (Register Bypassing) –send data from one stage to another bypassing the register file Still have load use delay Structural Hazards Replicate Hardware, scheduling Control Hazards Compute condition and target early (delayed branch)

4 © Alvin R. Lebeck 2001 CPS 220 Review: Speed Up Equation for Pipelining CPI pipelined = Ideal CPI + Pipeline stall clock cycles per instr Speedup = Ideal CPI x Pipeline depth Clock Cycle unpipelined Ideal CPI + Pipeline stall CPI Clock Cycle pipelined Speedup = Pipeline depth Clock Cycle unpipelined 1 + Pipeline stall CPI Clock Cycle pipelined x x

5 © Alvin R. Lebeck 2001 CPS 220 Review: Evaluating Branch Alternatives SchedulingBranchCPIspeedup v.speedup v. scheme penaltyunpipelinedstall Stall pipeline Predict taken Predict not taken Delayed branch Two part solution: – Determine branch taken or not sooner, AND – Compute taken branch address earlier

6 © Alvin R. Lebeck 2001 CPS 220 Pipeline Complications Complex Addressing Modes and Instructions Address modes: Autoincrement causes register change during instruction execution –Interrupts? Need to restore register state –Adds WAR and WAW hazards since writes no longer last stage Memory-Memory Move Instructions –Must be able to handle multiple page faults –Long-lived instructions: partial state save on interrupt Condition Codes

7 © Alvin R. Lebeck 2001 Pipeline Complications: Floating Point

8 © Alvin R. Lebeck 2001 CPS 220 Pipelining Complications Floating Point: long execution time Also, may pipeline FP execution unit so we can initiate new instructions without waiting full latency FP InstructionLatencyInitiation Rate (MIPS R4000) Add, Subtract43 Multiply84 Divide3635(interrupts, Square root112111WAW, WAR) Negate21 Absolute value21 FP compare32 Cycles before use result Cycles before issue instr of same type

9 © Alvin R. Lebeck 2001 Floating Point RAW Stalls LD F4, 0(r2) MULTD F0, F4, F6 ADDD F2, F0, F8 SD F2, 0(R2)

10 © Alvin R. Lebeck 2001 Floating Point Structural Hazard MULTD F0, F4, F6WB stage in what cycle? … ADDD F2, F4, F6 … LD F8, 0(R2)

11 © Alvin R. Lebeck 2001 Hazard Detection Assume all hazard detection in ID stage 1.Check for structural hazards. 2.Check for RAW data hazard. 3.Check for WAW data hazard. If any occur stall at ID stage This is called an in-order issue/execute machine, if any instruction stalls all later instructions stall. – Note that instructions may complete execution out of order.

12 © Alvin R. Lebeck 2001 CPS 220 Case Study: MIPS R Stage Pipeline: –IF–first half of fetching of instruction; PC selection happens here as well as initiation of instruction cache access. –IS–second half of access to instruction cache. –RF–instruction decode and register fetch, hazard checking and also instruction cache hit detection. –EX–execution, which includes effective address calculation, ALU operation, and branch target computation and condition evaluation. –DF–data fetch, first half of access to data cache. –DS–second half of access to data cache. –TC–tag check, determine whether the data cache access hit. –WB–write back for loads and register-register operations. 8 Stages: What is impact on Load delay? Branch delay? Why?

13 © Alvin R. Lebeck 2001 CPS 220 Case Study: MIPS R4000 IFIS IF RF IS IF EX RF IS IF DF EX RF IS IF DS DF EX RF IS IF TC DS DF EX RF IS IF WB TC DS DF EX RF IS IF TWO Cycle Load Latency IFIS IF RF IS IF EX RF IS IF DF EX RF IS IF DS DF EX RF IS IF TC DS DF EX RF IS IF WB TC DS DF EX RF IS IF THREE Cycle Branch Latency (conditions evaluated during EX phase) Delay slot plus two stalls Branch likely cancels delay slot if not taken

14 © Alvin R. Lebeck 2001 CPS 220 MIPS R4000 Floating Point FP Adder, FP Multiplier, FP Divider Last step of FP Multiplier/Divider uses FP Adder HW 8 kinds of stages in FP units: –StageFunctional unitDescription –AFP adderMantissa ADD stage –DFP dividerDivide pipeline stage –EFP multiplierException test stage –MFP multiplierFirst stage of multiplier –NFP multiplierSecond stage of multiplier –RFP adderRounding stage –SFP adderOperand shift stage –UUnpack FP numbers

15 © Alvin R. Lebeck 2001 CPS 220 MIPS FP Pipe Stages FP Instr … Add, SubtractUS+AA+RR+S MultiplyUE+MMMMNN+AR DivideUARD 28 …D+AD+R, D+R, D+A, D+R, A, R Square rootUE(A+R) 108 …AR NegateUS Absolute valueUS FP compareUAR Stages: MFirst stage of multiplier NSecond stage of multiplier RRounding stage SOperand shift stage UUnpack FP numbers AMantissa ADD stage DDivide pipeline stage EException test stage

16 © Alvin R. Lebeck 2001 CPS 220 R4000 Performance Not ideal CPI of 1: –Load stalls (1 or 2 clock cycles) –Branch stalls (2 cycles + unfilled slots) –FP result stalls: RAW data hazard (latency) –FP structural stalls: Not enough FP hardware (parallelism)

17 © Alvin R. Lebeck 2001 CPS 220 Summary of Pipelining Basics Hazards limit performance –Structural: need more HW resources –Data: need forwarding, compiler scheduling –Control: early evaluation & PC, delayed branch, prediction Increasing length of pipe increases impact of hazards; pipelining helps instruction bandwidth, not latency Compilers reduce cost of data and control hazards –Load delay slots –Branch delay slots –Branch prediction Interrupts, Instruction Set, FP makes pipelining harder Handling context switches.

18 © Alvin R. Lebeck 2001 CPS 220 Advanced Pipelining and Instruction Level Parallelism Deep Pipelines –Hazards increase with pipeline depth –Need more independent instructions gcc 17% control transfer –5 instructions + 1 branch –Beyond single basic block to get more instruction level parallelism Loop level parallelism one opportunity, SW and HW Do examples and then explain nomenclature DLX Floating Point as example –Measurements suggests R4000 performance FP execution has room for improvement

19 © Alvin R. Lebeck 2001 CPS 220 FP Loop: Where are the Hazards? Loop:LDF0,0(R1);F0=vector element ADDDF4,F0,F2;add scalar in F2 SD0(R1),F4;store result SUBIR1,R1,8;decrement pointer 8B (DW) BNEZR1,Loop;branch R1!=zero NOP;delayed branch slot InstructionInstructionLatency in producing resultusing result clock cycles FP ALU opAnother FP ALU op3 FP ALU opStore double2 Load doubleFP ALU op1 Load doubleStore double0 Integer opInteger op0

20 © Alvin R. Lebeck 2001 CPS 220 FP Loop Hazards Where are the stalls? InstructionInstructionLatency in producing resultusing result clock cycles FP ALU opAnother FP ALU op3 FP ALU opStore double2 Load doubleFP ALU op1 Load doubleStore double0 Integer opInteger op0 Loop:LDF0,0(R1);F0=vector element ADDDF4,F0,F2;add scalar in F2 SD0(R1),F4;store result SUBIR1,R1,8;decrement pointer 8B (DW) BNEZR1,Loop;branch R1!=zero NOP;delayed branch slot

21 © Alvin R. Lebeck 2001 CPS 220 FP Loop Showing Stalls Rewrite code to minimize stalls? InstructionInstructionLatency in producing resultusing result clock cycles FP ALU opAnother FP ALU op3 FP ALU opStore double2 Load doubleFP ALU op1 1 Loop:LDF0,0(R1);F0=vector element 2stall 3 ADDDF4,F0,F2;add scalar in F2 4stall 5stall 6 SD0(R1),F4;store result 7 SUBIR1,R1,8;decrement pointer 8B (DW) 8 BNEZR1,Loop;branch R1!=zero 9stall ;delayed branch slot

22 © Alvin R. Lebeck 2001 CPS 220 Revised FP Loop Minimizing Stalls How do we make this faster? InstructionInstructionLatency in producing resultusing result clock cycles FP ALU opAnother FP ALU op3 FP ALU opStore double2 Load doubleFP ALU op1 1 Loop:LDF0,0(R1) 2stall 3 ADDDF4,F0,F2 4 SUBIR1,R1,8 5 BNEZR1,Loop;delayed branch 6 SD8(R1),F4;altered when move past SUBI

23 © Alvin R. Lebeck 2001 CPS 220 Unroll Loop Four Times Rewrite loop to minimize stalls? 1 Loop:LDF0,0(R1) 2 ADDDF4,F0,F2 3 SD0(R1),F4 ;drop SUBI & BNEZ 4 LDF6,-8(R1) 5 ADDDF8,F6,F2 6 SD-8(R1),F8 ;drop SUBI & BNEZ 7 LDF10,-16(R1) 8 ADDDF12,F10,F2 9 SD-16(R1),F12 ;drop SUBI & BNEZ 10 LDF14,-24(R1) 11 ADDDF16,F14,F2 12 SD-24(R1),F16 13 SUBIR1,R1,#32;alter to 4*8 14 BNEZR1,LOOP 15 NOP x (1+2) = 27 clock cycles, or 6.8 per iteration Assumes R1 is multiple of 4

24 © Alvin R. Lebeck 2001 CPS 220 What assumptions made when moved code? –OK to move store past SUBI even though changes register –OK to move loads before stores: get right data? –When is it safe for compiler to do such changes? 1 Loop:LDF0,0(R1) 2 LDF6,-8(R1) 3 LDF10,-16(R1) 4 LDF14,-24(R1) 5 ADDDF4,F0,F2 6 ADDDF8,F6,F2 7 ADDDF12,F10,F2 8 ADDDF16,F14,F2 9 SD0(R1),F4 10 SD-8(R1),F8 11 SD-16(R1),F12 12 SUBIR1,R1,#32 13 BNEZR1,LOOP 14 SD8(R1),F16; 8-32 = clock cycles, or 3.5 per iteration Unrolled Loop That Minimizes Stalls

25 © Alvin R. Lebeck 2001 CPS 220 Compiler Perspectives on Code Movement Definitions: compiler concerned about dependencies in program, whether or not a HW hazard exists depends on a given pipeline (True) Data dependencies (RAW if a hazard for HW) –Instruction i produces a result used by instruction j, or –Instruction j is data dependent on instruction k, and instruction k is data dependent on instruction i. Easy to determine for registers (fixed names) Hard for memory: –Does 100(R4) = 20(R6)? –From different loop iterations, does 20(R6) = 20(R6)?

26 © Alvin R. Lebeck 2001 CPS 220 Compiler Perspectives on Code Movement Name dependence two instructions use same name but don’t exchange data Antidependence (WAR if a hazard for HW) –Instruction j writes a register or memory location that instruction i reads from and instruction i is executed first Output dependence (WAW if a hazard for HW) –Instruction i and instruction j write the same register or memory location; ordering between instructions must be preserved.

27 © Alvin R. Lebeck 2001 CPS 220 Compiler Perspectives on Code Movement Again Hard for Memory Accesses –Does 100(R4) = 20(R6)? –From different loop iterations, does 20(R6) = 20(R6)? Our example required compiler to know that if R1 doesn’t change then: 0(R1)  -8(R1)  -16(R1)  -24(R1) There were no dependencies between some loads and stores so they could be moved past each other

28 © Alvin R. Lebeck 2001 CPS 220 Compiler Perspectives on Code Movement Final kind of dependence called control dependence Example if p1 {S1;}; if p2 {S2;} S1 is control dependent on p1 and S2 is control dependent on p2 but not on p1.

29 © Alvin R. Lebeck 2001 CPS 220 Compiler Perspectives on Code Movement Two (obvious) constraints on control dependences: –An instruction that is control dependent on a branch cannot be moved before the branch so that its execution is no longer controlled by the branch. –An instruction that is not control dependent on a branch cannot be moved to after the branch so that its execution is controlled by the branch. Control dependencies relaxed to get parallelism; get same effect if preserve order of exceptions and data flow

30 © Alvin R. Lebeck 2001 CPS 220 When is it Safe to Unroll a Loop? Example: Where are data dependencies? (A,B,C distinct & nonoverlapping) for (i=1; i<=100; i=i+1) { A[i+1] = A[i] + C[i]; /* S1 */ B[i+1] = B[i] + A[i+1];} /* S2 */ 1. S2 uses the value, A[i+1], computed by S1 in the same iteration. 2. S1 uses a value computed by S1 in an earlier iteration, since iteration i computes A[i+1] which is read in iteration i+1. The same is true of S2 for B[i] and B[i+1]. This is a “loop-carried dependence”: between iterations Implies that iterations are dependent, and can’t be executed in parallel Not the case for our example; each iteration was independent

31 © Alvin R. Lebeck 2001 CPS 220 Summary Need to expose parallelism to exploit HW Loop level parallelism is easiest to see SW dependencies defined for program, hazards if HW cannot resolve SW dependencies/compiler sophistication determine if compiler can unroll loops

32 © Alvin R. Lebeck 2001 Can we do better? Problem: Stall in ID stage if any data hazard. Your task: Teams of two, propose a design to eliminate these stalls. MULD F2, F3, F4Long latency… ADDD F1, F2, F3 ADDD F3, F4, F5 ADDD F1, F4, F5

33 © Alvin R. Lebeck 2001 Next Time Hardware ILP: Scoreboarding & Tomasulo’s Algorithm