Instruction-Level Parallelism (ILP)

Similar documents
EE 4683/5683: COMPUTER ARCHITECTURE

EEC 581 Computer Architecture. Lec 4 Instruction Level Parallelism

Administrivia. CMSC 411 Computer Systems Architecture Lecture 14 Instruction Level Parallelism (cont.) Control Dependencies

ELEC 5200/6200 Computer Architecture and Design Fall 2016 Lecture 9: Instruction Level Parallelism

Instruction Level Parallelism. Taken from

Page 1. CISC 662 Graduate Computer Architecture. Lecture 8 - ILP 1. Pipeline CPI. Pipeline CPI (I) Pipeline CPI (II) Michela Taufer

Page # CISC 662 Graduate Computer Architecture. Lecture 8 - ILP 1. Pipeline CPI. Pipeline CPI (I) Michela Taufer

Lecture 15: Instruc.on Level Parallelism -- Introduc.on, Compiler Techniques, and Advanced Branch Predic.on

Recall from Pipelining Review. Lecture 16: Instruction Level Parallelism and Dynamic Execution #1: Ideas to Reduce Stalls

Pipelining and Exploiting Instruction-Level Parallelism (ILP)

Page 1. Recall from Pipelining Review. Lecture 16: Instruction Level Parallelism and Dynamic Execution #1: Ideas to Reduce Stalls

Instruction Level Parallelism

Lecture 6 MIPS R4000 and Instruction Level Parallelism. Computer Architectures S

NOW Handout Page 1. Review from Last Time. CSE 820 Graduate Computer Architecture. Lec 7 Instruction Level Parallelism. Recall from Pipelining Review

Instruction Level Parallelism. ILP, Loop level Parallelism Dependences, Hazards Speculation, Branch prediction

NOW Handout Page 1. Outline. Csci 211 Computer System Architecture. Lec 4 Instruction Level Parallelism. Instruction Level Parallelism

CS425 Computer Systems Architecture

Computer Science 246 Computer Architecture

Page 1. Recall from Pipelining Review. Lecture 15: Instruction Level Parallelism and Dynamic Execution

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Computer Architecture ECE 568

ESE 545 Computer Architecture Instruction-Level Parallelism (ILP) and Static & Dynamic Instruction Scheduling Instruction level parallelism

CSE 502 Graduate Computer Architecture. Lec 8-10 Instruction Level Parallelism

CMSC 611: Advanced Computer Architecture

Advanced Pipelining and Instruction- Level Parallelism 4

Exploiting ILP with SW Approaches. Aleksandar Milenković, Electrical and Computer Engineering University of Alabama in Huntsville

Floating Point/Multicycle Pipelining in DLX

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

ILP: Instruction Level Parallelism

Advanced Computer Architecture

Copyright 2012, Elsevier Inc. All rights reserved.

Compiler Optimizations. Lecture 7 Overview of Superscalar Techniques. Memory Allocation by Compilers. Compiler Structure. Register allocation

Outline EEL 5764 Graduate Computer Architecture. Chapter 2 - Instruction Level Parallelism. Recall from Pipelining Review

Multi-cycle Instructions in the Pipeline (Floating Point)

Getting CPI under 1: Outline

Lecture 9: Case Study MIPS R4000 and Introduction to Advanced Pipelining Professor Randy H. Katz Computer Science 252 Spring 1996

Hardware-based Speculation

Adapted from David Patterson s slides on graduate computer architecture

NOW Handout Page 1. COSC 5351 Advanced Computer Architecture

Computer Architecture A Quantitative Approach, Fifth Edition. Chapter 3. Instruction-Level Parallelism and Its Exploitation

HY425 Lecture 09: Software to exploit ILP

Lecture 4: Introduction to Advanced Pipelining

CPE 631 Lecture 09: Instruction Level Parallelism and Its Dynamic Exploitation

Lecture: Pipeline Wrap-Up and Static ILP

HY425 Lecture 09: Software to exploit ILP

Super Scalar. Kalyan Basu March 21,

Four Steps of Speculative Tomasulo cycle 0

Lecture: Static ILP. Topics: compiler scheduling, loop unrolling, software pipelining (Sections C.5, 3.2)

Hiroaki Kobayashi 12/21/2004

Review: Evaluating Branch Alternatives. Lecture 3: Introduction to Advanced Pipelining. Review: Evaluating Branch Prediction

Instruction Level Parallelism. Appendix C and Chapter 3, HP5e

計算機結構 Chapter 4 Exploiting Instruction-Level Parallelism with Software Approaches

Lecture 10: Static ILP Basics. Topics: loop unrolling, static branch prediction, VLIW (Sections )

What is ILP? Instruction Level Parallelism. Where do we find ILP? How do we expose ILP?

Multicycle ALU Operations 2/28/2011. Diversified Pipelines The Path Toward Superscalar Processors. Limitations of Our Simple 5 stage Pipeline

TDT 4260 lecture 7 spring semester 2015

Lecture: Static ILP. Topics: loop unrolling, software pipelines (Sections C.5, 3.2)

Instruction-Level Parallelism and Its Exploitation

NOW Handout Page 1. Review from Last Time #1. CSE 820 Graduate Computer Architecture. Lec 8 Instruction Level Parallelism. Outline

ILP concepts (2.1) Basic compiler techniques (2.2) Reducing branch costs with prediction (2.3) Dynamic scheduling (2.4 and 2.5)

Superscalar Architectures: Part 2

ECE 505 Computer Architecture

Instruction-Level Parallelism. Instruction Level Parallelism (ILP)

5008: Computer Architecture

ECSE 425 Lecture 11: Loop Unrolling

CSE 820 Graduate Computer Architecture. week 6 Instruction Level Parallelism. Review from Last Time #1

CISC 662 Graduate Computer Architecture Lecture 13 - CPI < 1

Lecture 8 Dynamic Branch Prediction, Superscalar and VLIW. Computer Architectures S

Lecture: Static ILP. Topics: predication, speculation (Sections C.5, 3.2)

Chapter 4. Advanced Pipelining and Instruction-Level Parallelism. In-Cheol Park Dept. of EE, KAIST

Donn Morrison Department of Computer Science. TDT4255 ILP and speculation

HW 2 is out! Due 9/25!

Hardware-Based Speculation

ELE 818 * ADVANCED COMPUTER ARCHITECTURES * MIDTERM TEST *

Chapter 3: Instruction Level Parallelism (ILP) and its exploitation. Types of dependences

TDT 4260 TDT ILP Chap 2, App. C

CS433 Midterm. Prof Josep Torrellas. October 19, Time: 1 hour + 15 minutes

Updated Exercises by Diana Franklin

EECC551 Exam Review 4 questions out of 6 questions

Computer Science 146. Computer Architecture

CSE 502 Graduate Computer Architecture

Exploitation of instruction level parallelism

Preventing Stalls: 1

EEC 581 Computer Architecture. Instruction Level Parallelism (3.6 Hardware-based Speculation and 3.7 Static Scheduling/VLIW)

Outline Review: Basic Pipeline Scheduling and Loop Unrolling Multiple Issue: Superscalar, VLIW. CPE 631 Session 19 Exploiting ILP with SW Approaches

Metodologie di Progettazione Hardware-Software

EEC 581 Computer Architecture. Lec 7 Instruction Level Parallelism (2.6 Hardware-based Speculation and 2.7 Static Scheduling/VLIW)

Computer Architecture Practical 1 Pipelining

Topics. Digital Systems Architecture EECE EECE Software Approaches to ILP Part 2. Ideas To Reduce Stalls. Processor Case Studies

CS433 Homework 3 (Chapter 3)

Review: Compiler techniques for parallelism Loop unrolling Ÿ Multiple iterations of loop in software:

HY425 Lecture 05: Branch Prediction

Load1 no Load2 no Add1 Y Sub Reg[F2] Reg[F6] Add2 Y Add Reg[F2] Add1 Add3 no Mult1 Y Mul Reg[F2] Reg[F4] Mult2 Y Div Reg[F6] Mult1

CPI < 1? How? What if dynamic branch prediction is wrong? Multiple issue processors: Speculative Tomasulo Processor

Lecture: Out-of-order Processors. Topics: out-of-order implementations with issue queue, register renaming, and reorder buffer, timing, LSQ

Instruction Frequency CPI. Load-store 55% 5. Arithmetic 30% 4. Branch 15% 4

Chapter 4 The Processor 1. Chapter 4D. The Processor

As the amount of ILP to exploit grows, control dependences rapidly become the limiting factor.

Static vs. Dynamic Scheduling

Reduction of Data Hazards Stalls with Dynamic Scheduling So far we have dealt with data hazards in instruction pipelines by:

Hardware-Based Speculation

Transcription:

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]; 1 2 1

Loop-Level Parallelism Exploit loop-level parallelism to parallelism by unrolling loop either by 1. dynamic via branch prediction or 2. static via loop unrolling by compiler Another way is by using vectors Determining instruction dependence is critical to Loop Level Parallelism If 2 instructions are parallel, they can execute simultaneously in a pipeline of arbitrary depth without causing any stalls (assuming no structural hazards) dependent, they are not parallel and must be executed in order, although they may often be partially overlapped Data Dependence and Hazards Instr J is data dependent (or true dependence) on Instr I if: Instr J tries to read operand before Instr I writes it I: add r1,r2,r3 J: sub r4,r1,r3 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 3 9/15/084 2

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 1. indicates the possibility of a hazard 2. determines order in which results must be calculated 3. 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 #1: Anti-dependence Name dependence: when 2 instructions use same register or memory location, called a name, but no flow of data between the instructions associated with that name; 2 versions of name dependence Instr J writes operand before Instr I reads it I: sub r4,r1,r3 J: add r1,r2,r3 K: mul r6,r1,r7 Called an anti-dependence by compiler writers. This results from reuse of the name r1 If anti-dependence caused a hazard in the pipeline, called a Write After Read (WAR) hazard 3

Name Dependence #2: Output dependence Instr J writes operand before Instr I writes it. I: sub r1,r4,r3 J: add r1,r2,r3 K: mul r6,r1,r7 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 Register Renaming Example I3 can not exec before I2 because I3 will overwrite R6 I5 can not go before I2 because I2, when it goes, will overwrite R2 with a stale value Program code I1: ADD R1, R2, R3 I2: SUB R2, R1, R6 I3: AND R6, R11, R7 I4: OR R8, R5, R2 I5: XOR R2, R4, R11 RAW WAR WAW 4

Register Renaming Solution: Program code Let s give I2 temporary name/ location (e.g., S) for the value it produces. But I4 uses that value, so we must also change that to S In fact, all uses of R2 from I2 to the next instruction that writes to R2 again must now be changed to S! We remove WAW deps in the same way: change R2 in I5 (and subsequent instrs) to T. I1: ADD R1, R2, R3 I2: SUB R2, S, R1, R6 I3: AND R6, U, R11, R7 R7 I4: OR R8, R5, R2 S I5: XOR R2, T, R4, R11 Register Renaming Implementation Space for S, T, U etc. How do we know when to rename a register? Simple Solution Do renaming for every instruction Change the name of a register each time we decode an instruction that will write to it. Program code I1: ADD R1, R2, R3 I2: SUB S, R1, R5 I3: AND U, R11, R7 I4: OR R8, R5, S I5: XOR T, R4, R11 5

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 S2 is control dependent on p2 but not on p1. Control Dependence Ignored Control dependence need not be preserved Willing to execute instructions that should not have been executed, thereby violating the control dependences, if can do so without affecting correctness of the program Instead, 2 properties critical to program correctness are 1. exception behavior and 2. data flow 6

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,R4 BEQZ R2,L1 LW R1,0(R2) L1: (Assume branches not delayed) Problem with moving LW before BEQZ? 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,R3 BEQZ R4,L L: OR DSUBU R1,R5,R6 R7,R1,R8 OR depends on DADDU or DSUBU? Must preserve data flow on execution 7

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 3 3 FP ALU op Store double 2 2 Load double FP ALU op 1 1 Load double Store double 0 0 Integer op Integer op 0 0 FP Loop: Where are the Hazards? First translate into MIPS code: To simplify, assume 8 is lowest address Loop:L.D F0,0(R1) ;F0=vector element ADD.D F4,F0,F2 add scalar from F2 S.D 0(R1),F4 ;store result DADDUI R1,R1,-8 ;decrement pointer 8B BNEZ R1,Loop ;branch R1!=zero 8

FP Loop Showing Stalls 1 Loop: L.D F0,0(R1) ;F0=vector element 2 stall 3 ADD.D F4,F0,F2 ;add scalar in F2 4 stall 5 stall 6 S.D 0(R1),F4 ;store result 7 DADDUI R1,R1,-8;decrement pointer 8B (DW) 8 stall ;assumes can t forward to branch 9 BNEZ R1,Loop ;branch R1!=zero 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 9 clock cycles: Rewrite code to minimize stalls? Revised FP Loop Minimizing Stalls 1 Loop: L.D F0,0(R1) 2 DADDUI R1,R1,-8 3 ADD.D F4,F0,F2 4 stall 5 stall 6 S.D 8(R1),F4 ;altered offset when 7 BNEZ R1,Loop ; move DSUBUI Swap DADDUI and S.D by changing address of S.D 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 7 clock cycles, but just 3 for execution (L.D, ADD.D,S.D), 4 for loop overhead How can we make this faster? 9

Unroll Loop Four Times (straightforward way) 1 Loop:L.D F0,0(R1) 3 ADD.D F4,F0,F2 1 cycle stall 2 cycles stall 6 S.D 0(R1),F4 ;drop DSUBUI & BNEZ 7 L.D F6,-8(R1) 9 ADD.D F8,F6,F2 12 S.D -8(R1),F8 ;drop DSUBUI & BNEZ 13 L.D F10,-16(R1) 15 ADD.D F12,F10,F2 18 S.D -16(R1),F12 ;drop DSUBUI & BNEZ 19 L.D F14,-24(R1) 21 ADD.D F16,F14,F2 24 S.D -24(R1),F16 25 DADDUI R1,R1,#-32 ;alter to 4*8 26 BNEZ R1,LOOP Rewrite loop to minimize stalls? 27 clock cycles, or 6.75 per iteration (Assumes R1 is multiple of 4) Unrolled Loop That Minimizes Stalls 1 Loop: L.D F0,0(R1) 2 L.D F6,-8(R1) 3 L.D F10,-16(R1) 4 L.D F14,-24(R1) 5 ADD.DF4,F0,F2 6 ADD.DF8,F6,F2 7 ADD.DF12,F10,F2 8 ADD.DF16,F14,F2 9 S.D 0(R1),F4 10 S.D -8(R1),F8 11 S.D -16(R1),F12 12 DSUBUI R1,R1,#32 13 S.D 8(R1),F16 ; 8-32 = -24 14 BNEZ R1,LOOP 14 clock cycles, or 3.5 per iteration 10

5 Loop Unrolling Decisions Requires understanding how one instruction depends on another and how the instructions can be changed or reordered given the dependences: 1. Determine loop unrolling useful by finding that loop iterations were independent (except for maintenance code) 2. Use different registers to avoid unnecessary constraints forced by using same registers for different computations 3. Eliminate the extra test and branch instructions and adjust the loop termination and iteration code 4. Determine that loads and stores in unrolled loop can be interchanged by observing that loads and stores from different iterations are independent 5. Schedule the code, preserving any dependences needed to yield the same result as the original code 3 Limits to Loop Unrolling Growth in code size For larger loops, concern it increases the instruction cache miss rate Register pressure: potential shortfall in registers created by aggressive unrolling and scheduling If not be possible to allocate all live values to registers, may lose some or all of its advantage Loop unrolling reduces branch impact on pipeline; another way is branch prediction (next time) 9/15/08 22 11