Download Instruction Level Parallelism - Advance Computers Architectures - Lecture Slides and more Slides Computer Architecture and Organization in PDF only on Docsity!
CIS 600 Advanced Computer
Architecture
Lecture 5 – Instruction Level
Parallelism
Outline
• ILP
• Compiler techniques to increase ILP
• Loop Unrolling
• Static Branch Prediction
• Dynamic Branch Prediction
• Overcoming Data Hazards with Dynamic
Scheduling
• (Start) Tomasulo Algorithm
• Conclusion
Instruction Level Parallelism
• Instruction-Level Parallelism (ILP): overlap the
execution of instructions to improve
performance
• 2 approaches to exploit ILP:
1) Rely on hardware to help discover and exploit the
parallelism dynamically (e.g., Pentium 4, AMD
Opteron, IBM Power) , and
2) Rely on software technology to find parallelism,
statically at compile-time (e.g., Itanium 2)
Instruction-Level Parallelism (ILP)
- Basic Block (BB) ILP is quite small
- BB: a straight-line code sequence with no branches in except to the entry and no branches out except at the exit
- average dynamic branch frequency 15% to 25% => 4 to 7 instructions execute between a pair of branches
- Plus instructions in BB likely to depend on each other
- To obtain substantial performance enhancements, we must exploit ILP across multiple basic blocks
- Simplest: loop-level parallelism to exploit parallelism among iterations of a loop. E.g., for (i=1; i<=1000; i=i+1) x[i] = x[i] + y[i];
Data Dependence and Hazards
• InstrJ is data dependent (aka true dependence) on InstrI:
- Instr (^) J tries to read operand before Instr (^) I writes it
- or Instr (^) J is data dependent on Instr (^) K which is dependent on Instr (^) I
• If two instructions are data dependent, they cannot
execute simultaneously or be completely overlapped
• Data dependence in instruction sequence
⇒ data dependence in source code ⇒ effect of original
data dependence must be preserved
• If data dependence caused a hazard in pipeline,
called a Read After Write (RAW) hazard
I: add r1,r2,r J: sub r4,r1,r
ILP and Data
Dependencies,Hazards
- HW/SW must preserve program order: order instructions would execute in if executed sequentially as determined by original source program - Dependences are a property of programs
- Presence of dependence indicates potential for a hazard, but actual hazard and length of any stall is property of the pipeline
- Importance of the data dependencies
- indicates the possibility of a hazard
- determines order in which results must be calculated
- sets an upper bound on how much parallelism can possibly be exploited
- HW/SW goal: exploit parallelism by preserving program order only where it affects the outcome of the program
Name Dependence #2: Output
dependence
- InstrJ writes operand before InstrI writes it.
- Called an “output dependence” by compiler writers This also results from the reuse of name “r1”
- If anti-dependence caused a hazard in the pipeline, called a Write After Write (WAW) hazard
- Instructions involved in a name dependence can execute simultaneously if name used in instructions is changed so instructions do not conflict - Register renaming resolves name dependence for regs - Either by compiler or by HW
I: sub r1,r4,r J: add r1,r2,r K: mul r6,r1,r
Control Dependencies
• Every instruction is control dependent
on some set of branches, and, in
general, these control dependencies
must be preserved to preserve program
order
if p1 { S1; }; if p2 { S2; }
• S1 is control dependent on p1, and S
is control dependent on p2 but not on
Exception Behavior
• Preserving exception behavior
⇒ any changes in instruction execution order
must not change how exceptions are raised in
program
(⇒ no new exceptions)
• Example:
DADDU R2,R3,R
BEQZ R2,L
LW R1,0(R2)
L1:
Data Flow
• Data flow: actual flow of data values among
instructions that produce results and those
that consume them
– branches make flow dynamic, determine which
instruction is supplier of data
• Example:
DADDU R1,R2,R
BEQZ R4,L
DSUBU R1,R5,R
L: …
Software Techniques -
Example
• This code, add a scalar to a vector:
for (i=1000; i>0; i=i–1)
x[i] = x[i] + s;
• Assume following latencies for all
examples
– Ignore delayed branch in these examples
Instruction Instruction Latency stalls between producing result using result in cycles in cycles FP ALU op Another FP ALU op 4 3 FP ALU op Store double 3 2 Load double FP ALU op 1 1 Load double Store double 1 0 Integer op Integer op 1 0
FP Loop: Where are the Hazards?
Loop: L.D F0,0(R1) ;F0=vector element ADD.D F4,F0,F2 ;add scalar from F S.D 0(R1),F4 ;store result DADDUI R1,R1,-8 ;decrement pointer 8B (DW) BNEZ R1,Loop ;branch R1!=zero
- First translate into MIPS code:
-To simplify, assume 8 is lowest address
Revised FP Loop Minimizing Stalls
7 clock cycles, but just 3 for execution (L.D, ADD.D,S.D), 4 for loop overhead; How make faster?
Instruction Instruction Latency in producing result using result clock cycles FP ALU op Another FP ALU op 3 FP ALU op Store double 2 Load double FP ALU op 1
1 Loop: L.D F0,0(R1) 2 DADDUI R1,R1,- 3 ADD.D F4,F0,F 4 stall 5 stall 6 S.D 8(R1),F4 ;altered offset when move DSUBUI 7 BNEZ R1,Loop Swap DADDUI and S.D by changing address of S.D
Unroll Loop Four Times
(straightforward way)
Rewrite loop to
minimize
stalls?
1 Loop: L.D F0,0(R1) 3 ADD.D F4,F0,F 6 S.D 0(R1),F4 ;drop DSUBUI & BNEZ 7 L.D F6,-8(R1) 9 ADD.D F8,F6,F 12 S.D -8(R1),F8 ;drop DSUBUI & BNEZ 13 L.D F10,-16(R1) 15 ADD.D F12,F10,F 18 S.D -16(R1),F12 ;drop DSUBUI & BNEZ 19 L.D F14,-24(R1) 21 ADD.D F16,F14,F 24 S.D -24(R1),F 25 DADDUI R1,R1,#-32 ;alter to 4 26 BNEZ R1,LOOP*
27 clock cycles, or 6.75 per iteration (Assumes R1 is multiple of 4)
1 cycle stall 2 cycles stall