Intro to Computer Org. Pipelining, Part 2 – Data hazards + Stalls.

Slides:



Advertisements
Similar presentations
Morgan Kaufmann Publishers The Processor
Advertisements

CMSC 611: Advanced Computer Architecture Pipelining Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted.
COMP25212 Further Pipeline Issues. Cray 1 COMP25212 Designed in 1976 Cost $8,800,000 8MB Main Memory Max performance 160 MFLOPS Weight 5.5 Tons Power.
Data Dependencies Describes the normal situation that the data that instructions use depend upon the data created by other instructions, or data is stored.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Pipeline Computer Organization II 1 Hazards Situations that prevent starting the next instruction in the next cycle Structural hazards – A required resource.
Lecture Objectives: 1)Define pipelining 2)Calculate the speedup achieved by pipelining for a given number of instructions. 3)Define how pipelining improves.
Chapter 8. Pipelining.
Pipelining I (1) Fall 2005 Lecture 18: Pipelining I.
Chapter Six 1.
Instruction-Level Parallelism (ILP)
Pipelining II (1) Fall 2005 Lecture 19: Pipelining II.
Instructor: Senior Lecturer SOE Dan Garcia CS 61C: Great Ideas in Computer Architecture Pipelining Hazards 1.
Mary Jane Irwin ( ) [Adapted from Computer Organization and Design,
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
EECS 470 Pipeline Hazards Lecture 4 Coverage: Appendix A.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania Computer Organization Pipelined Processor Design 1.
1  2004 Morgan Kaufmann Publishers Chapter Six. 2  2004 Morgan Kaufmann Publishers Pipelining The laundry analogy.
Pipelining Andreas Klappenecker CPSC321 Computer Architecture.
CSCE 212 Quiz 9 – 3/30/11 1.What is the clock cycle time based on for single-cycle and for pipelining? 2.What two actions can be done to resolve data hazards?
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
7/2/ _23 1 Pipelining ECE-445 Computer Organization Dr. Ron Hayne Electrical and Computer Engineering.
1  1998 Morgan Kaufmann Publishers Chapter Six Enhancing Performance with Pipelining.
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 17 - Pipelined.
Pipelining. Overview Pipelining is widely used in modern processors. Pipelining improves system performance in terms of throughput. Pipelined organization.
1 Pipelining Reconsider the data path we just did Each instruction takes from 3 to 5 clock cycles However, there are parts of hardware that are idle many.
1 Appendix A Pipeline implementation Pipeline hazards, detection and forwarding Multiple-cycle operations MIPS R4000 CDA5155 Spring, 2007, Peir / University.
Chapter 4 The Processor. Chapter 4 — The Processor — 2 Introduction We will examine two MIPS implementations A simplified version A more realistic pipelined.
Pipeline Hazards. CS5513 Fall Pipeline Hazards Situations that prevent the next instructions in the instruction stream from executing during its.
CSE 340 Computer Architecture Summer 2014 Basic MIPS Pipelining Review.
CS.305 Computer Architecture Enhancing Performance with Pipelining Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from.
CMPE 421 Parallel Computer Architecture
Pipeline Data Hazards Warning, warning, warning! Read 4.8 Peer Instruction Lecture Materials for Computer Architecture by Dr. Leo Porter is licensed under.
1 Designing a Pipelined Processor In this Chapter, we will study 1. Pipelined datapath 2. Pipelined control 3. Data Hazards 4. Forwarding 5. Branch Hazards.
1 COMP541 Pipelined MIPS Montek Singh Mar 30, 2010.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CS 1104 Help Session IV Five Issues in Pipelining Colin Tan, S
CECS 440 Pipelining.1(c) 2014 – R. W. Allison [slides adapted from D. Patterson slides with additional credits to M.J. Irwin]
CSIE30300 Computer Architecture Unit 04: Basic MIPS Pipelining Hsin-Chou Chi [Adapted from material by and
5/13/99 Ashish Sabharwal1 Pipelining and Hazards n Hazards occur because –Don’t have enough resources (ALU’s, memory,…) Structural Hazard –Need a value.
1  1998 Morgan Kaufmann Publishers Chapter Six. 2  1998 Morgan Kaufmann Publishers Pipelining Improve perfomance by increasing instruction throughput.
Pipelining Example Laundry Example: Three Stages
Instructor: Senior Lecturer SOE Dan Garcia CS 61C: Great Ideas in Computer Architecture Pipelining Hazards 1.
LECTURE 7 Pipelining. DATAPATH AND CONTROL We started with the single-cycle implementation, in which a single instruction is executed over a single cycle.
10/11: Lecture Topics Execution cycle Introduction to pipelining
Introduction to Computer Organization Pipelining.
Lecture 9. MIPS Processor Design – Pipelined Processor Design #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System.
Chapter Six.
Lecture 18: Pipelining I.
CSCI206 - Computer Organization & Programming
Single Clock Datapath With Control
Pipeline Implementation (4.6)
Morgan Kaufmann Publishers The Processor
Lecture 6: Advanced Pipelines
Single-cycle datapath, slightly rearranged
Pipelining in more detail
CSCI206 - Computer Organization & Programming
CSCI206 - Computer Organization & Programming
How to improve (decrease) CPI
Chapter Six.
Chapter Six.
Daxia Ge Friday February 9th, 2007
Instruction Execution Cycle
Lecture 4: Advanced Pipelines
Pipelining.
Pipelining Chapter 6.
Introduction to Computer Organization and Architecture
Pipelining Chapter 6.
Guest Lecturer: Justin Hsia
Presentation transcript:

Intro to Computer Org. Pipelining, Part 2 – Data hazards + Stalls

Core Idea of Pipelining If we can’t make the “useful work” faster… what if we could do more of it at the same time?

Core Idea of Pipelining In technical terms, if you cannot improve the latency, try improving throughput. Latency – time required to complete a single task. Throughput – amount of tasks which can be handled at once.

Pipelined Instructions Blue =being actively used.

Pipelined Datapath

Impact On Performance If we examine the impact this will have on performance, under ideal circumstances… Each instruction now takes 5 cycles. We can run 5 instructions in parallel. CPI = 1.

Impact On Performance If we examine the impact this will have on performance, under ideal circumstances… Why might we not have ideal circumstances? Can we always run 5 instructions in parallel? No!

Pipelining – Hazards Hazard ­A situation where the next instruction cannot execute in the following cycle for a pipelined datapath There are three different types of hazards that we will examine.

Pipelining – Hazards Structural Hazard ­A hazard resulting from particular sets of instructions that we wish to execute simultaneously ­Happens when we try to use the same structural unit simultaneously for more than one task

Pipelining – Hazards Structural Hazard This is why we must have two different memory units in our datapath – one for instruction fetches and the other for data access.

Pipelining – Hazards Structural Hazard A similar problem could happen with the register file. (Used in IF and WB.) However, we noted that the register file is so fast that WB can happen in a different part of the cycle than IF. This fact is why the register file isn’t involved in a structural hazard.

Pipelining – Hazards Data Hazard ­A hazard caused by dependencies in data across instructions being pipelined Such a dependency requires that we force an instruction to wait for the data to be available for use, wasting a cycle of pipelining.

Pipelining – Hazards Consider the following instruction sequence: add $s0, $t0, $t1 sub $t2, $s0, $t3

Pipelining – Hazards Consider the following instruction sequence: add $s0, $t0, $t1 sub $t2, $s0, $t3 The value of $s0 won’t be available until written back!

add $s0, $t0, $t1 Pipelining – Hazards As a result, we must stall the sub instruction until the value of $s0 is ready. add $s0, $t0, $t1 sub $t2, $s0, $t3

add $s0, $t0, $t1 Pipelining – Hazards As a result, we must stall the sub instruction until the value of $s0 is ready. Really? sub $t2, $s0, $t3 Disclaimer: We’ll see how stalls are actually handled on a later slide in this lecture.

Pipelining – Hazards If we really think about it, isn’t the value of $s0 already calculated by the time we need it? We just haven’t written it back yet! add $s0, $t0, $t1 sub $t2, $s0, $t3

Overcoming Data Hazards Much of the time, it is possible to remove data hazards! The technique: forwarding. ­Adding extra hardware to retrieve data from early from already evaluated sources in the pipeline. ­Also called bypassing.

Pipelining – Forwarding Since the value of $s0 is already calculated, let’s forward it! add $s0, $t0, $t1 sub $t2, $s0, $t3

Pipelining – Forwarding Since the value of $s0 is already calculated, let’s forward it! Remember, we only need the value once we reach the EXE stage. add $s0, $t0, $t1 sub $t2, $s0, $t3

Pipelining – Forwarding In this case, we can still keep our throughput at its maximum. This isn’t always possible, though… add $s0, $t0, $t1 sub $t2, $s0, $t3

Pipelining – Forwarding Consider the case below. lw $s0, 20($t1) sub $t2, $s0, $t3 Can we avoid stalling an instruction? lw $s0, 20($t1) sub $t2, $s0, $t3

Pipelining – Forwarding When will the value of $s0 be available? When do we need the value of $s0? We have to stall! lw $s0, 20($t1) sub $t2, $s0, $t3

Pipelining – Forwarding When will the value of $s0 be available? When do we need the value of $s0? We have to stall! lw $s0, 20($t1) Stalled (nop) sub $t2, $s0, $t3

Pipelining – Forwarding When will the value of $s0 be available? When do we need the value of $s0? We have to stall! lw $s0, 20($t1) sub $t2, $s0, $t3 Stalled (nop) That is how stalls are actually implemented.

Pipelining – Forwarding Really? With forwarding, yes. Other techniques exist. lw $s0, 20($t1) sub $t2, $s0, $t3 Stalled (nop)

Overcoming Data Hazards If you must have a data hazard between two instructions, try to squeeze useful work inside. The technique: code reordering. ­Changing the order of instructions so that useful work may be done in what would otherwise be a stall.

Pipelining – Code Reordering Consider the case below. lw $s0, 20($t1) addi $t1, $t1, 4 sub $t2, $s0, $t3 lw $s0, 20($t1) sub $t2, $s0, $t3 addi $t1, $t1, 4

Pipelining – Code Reordering Do we still need to stall? Check for when data will be available and when it will be needed. lw $s0, 20($t1) sub $t2, $s0, $t3 addi $t1, $t1, 4

Pipelining – Code Reordering No stall required! The second instruction may execute because $t1 isn’t modified by the previous instruction. lw $s0, 20($t1) sub $t2, $s0, $t3 addi $t1, $t1, 4

Overcoming Data Hazards For the purposes of this class, code reordering must be done by compilers. Knowing how the pipelining system works allows us to optimize for these scenarios!

Overcoming Data Hazards In production CPUs, the processor itself can perform code reordering. This is referred to as out-of-order execution.

Overcoming Data Hazards The next question – how do we implement forwarding and stalls in hardware?

Overcoming Data Hazards 1. Note the type of operation at each stage. 2. Save the register fields used by each instruction – especially the destination register. 3. If a source register in one stage matches the destination register in another, forward the data!

Overcoming Data Hazards

Wait! Weren’t there supposed to be three different types of hazards?