Presentation is loading. Please wait.

Presentation is loading. Please wait.

EEL 5708 1 Advanced Pipelining and Instruction Level Parallelism Lotzi Bölöni.

Similar presentations


Presentation on theme: "EEL 5708 1 Advanced Pipelining and Instruction Level Parallelism Lotzi Bölöni."— Presentation transcript:

1 EEL 5708 1 Advanced Pipelining and Instruction Level Parallelism Lotzi Bölöni

2 EEL 5708 2 Acknowledgements All the lecture slides were adopted from the slides of David Patterson (1998, 2001) and David E. Culler (2001), Copyright 1998-2002, University of California Berkeley

3 EEL 5708 3 Review: 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 Interrupts, Instruction Set, FP makes pipelining harder Compilers reduce cost of data and control hazards –Load delay slots –Branch delay slots –Branch prediction Today: Longer pipelines => Better branch prediction, more instruction parallelism?

4 EEL 5708 4 The CPI for pipelined processors Pipeline CPI = Ideal pipeline CPI + Structural stalls + Data hazard stalls + Control stalls There are a variety of techniques used for improving various components. What we have seen as of yet is just the beginning. Techniques can be: –Hardware (dynamic) –Software (static)

5 EEL 5708 5 Techniques for ILP TechniqueReduces Forwarding and bypassingPotential data hazard stalls Delayed branches & branch scheduling Control hazard stalls Basic dynamic scheduling (scoreboarding) Data hazards from true dependencies Dynamic scheduling with renaming Data hazards from antideps. and output deps. Dynamic branch predictionControl stalls Issuing multiple instr per cycleIdeal CPI SpeculationData and control hazard stalls Dynamic memory disambiguationData hazard stalls with memory

6 EEL 5708 6 Techniques for ILP (cont’d) TechniqueReduces Loop unrollingControl hazard stalls Basic compiler pipeline scheduling Data hazard stalls Compiler dependence analysisIdeal CPI, data hazard stalls Software pipelining, trace scheduling Ideal CPI, data hazard stalls Compiler speculationIdeal CPI, data, control stalls

7 EEL 5708 7 Loop unrolling (software, static method)

8 EEL 5708 8 FP Loop: Where are the Hazards? Loop:LDF0,0(R1);F0=vector element ADDDF4,F0,F2;add scalar from 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 Where are the stalls?

9 EEL 5708 9 FP Loop Hazards 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

10 EEL 5708 10 FP Loop Showing Stalls 9 clocks: 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 3ADDDF4,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

11 EEL 5708 11 Revised FP Loop Minimizing Stalls 6 clocks: Unroll loop 4 times code to make 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 3ADDDF4,F0,F2 4SUBIR1,R1,8 5BNEZR1,Loop;delayed branch 6 SD8(R1),F4;altered when move past SUBI Swap BNEZ and SD by changing address of SD

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

13 EEL 5708 13 Unrolled Loop That Minimizes Stalls 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) 2LDF6,-8(R1) 3LDF10,-16(R1) 4LDF14,-24(R1) 5ADDDF4,F0,F2 6ADDDF8,F6,F2 7ADDDF12,F10,F2 8ADDDF16,F14,F2 9SD0(R1),F4 10SD-8(R1),F8 11SD-16(R1),F12 12SUBIR1,R1,#32 13BNEZR1,LOOP 14SD8(R1),F16; 8-32 = -24 14 clock cycles, or 3.5 per iteration When safe to move instructions?

14 EEL 5708 14 Compiler Perspectives on Code Movement Definitions: compiler concerned about dependencies in program, whether or not a HW hazard depends on a given pipeline Try to schedule to avoid hazards (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. If dependent, can’t execute in parallel Easy to determine for registers (fixed names) Hard for memory: –Does 100(R4) = 20(R6)? –From different loop iterations, does 20(R6) = 20(R6)?

15 EEL 5708 15 Where are the data dependencies? 1 Loop:LDF0,0(R1) 2ADDDF4,F0,F2 3SUBIR1,R1,8 4BNEZR1,Loop;delayed branch 5 SD8(R1),F4;altered when move past SUBI

16 EEL 5708 16 Compiler Perspectives on Code Movement Another kind of dependence called name dependence: two instructions use same name (register or memory location) 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.

17 EEL 5708 17 Where are the name dependencies? 1 Loop:LDF0,0(R1) 2ADDDF4,F0,F2 3SD0(R1),F4 ;drop SUBI & BNEZ 4LDF0,-8(R1) 2ADDDF4,F0,F2 3SD-8(R1),F4 ;drop SUBI & BNEZ 7LDF0,-16(R1) 8ADDDF4,F0,F2 9SD-16(R1),F4 ;drop SUBI & BNEZ 10LDF0,-24(R1) 11ADDDF4,F0,F2 12SD-24(R1),F4 13SUBIR1,R1,#32;alter to 4*8 14BNEZR1,LOOP 15NOP How can remove them?

18 EEL 5708 18 Where are the name dependencies? 1 Loop:LDF0,0(R1) 2ADDDF4,F0,F2 3SD0(R1),F4 ;drop SUBI & BNEZ 4LDF6,-8(R1) 5ADDDF8,F6,F2 6SD-8(R1),F8 ;drop SUBI & BNEZ 7LDF10,-16(R1) 8ADDDF12,F10,F2 9SD-16(R1),F12 ;drop SUBI & BNEZ 10LDF14,-24(R1) 11ADDDF16,F14,F2 12SD-24(R1),F16 13SUBIR1,R1,#32;alter to 4*8 14BNEZR1,LOOP 15NOP Called “register renaming”

19 EEL 5708 19 Compiler Perspectives on Code Movement Again name dependencies are 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 by each other

20 EEL 5708 20 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.

21 EEL 5708 21 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 (address in register checked by branch before use) and data flow (value in register depends on branch)

22 EEL 5708 22 Where are the control dependencies? 1 Loop:LDF0,0(R1) 2ADDDF4,F0,F2 3SD0(R1),F4 4SUBIR1,R1,8 5BEQZR1,exit 6LDF0,0(R1) 7ADDDF4,F0,F2 8SD0(R1),F4 9SUBIR1,R1,8 10BEQZR1,exit 11LDF0,0(R1) 12ADDDF4,F0,F2 13SD0(R1),F4 14SUBIR1,R1,8 15BEQZR1,exit....

23 EEL 5708 23 When Safe to Unroll 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 prior example; each iteration was distinct

24 EEL 5708 24 Summary Instruction Level Parallelism (ILP) in SW or HW Loop level parallelism is easiest to see SW parallelism dependencies defined for program, hazards if HW cannot resolve SW dependencies/compiler sophistication determine if compiler can unroll loops –Memory dependencies hardest to determine


Download ppt "EEL 5708 1 Advanced Pipelining and Instruction Level Parallelism Lotzi Bölöni."

Similar presentations


Ads by Google