CS1104: Computer Organisation School of Computing National University of Singapore.

Slides:



Advertisements
Similar presentations
PipelineCSCE430/830 Pipeline: Introduction CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Prof. Yifeng Zhu, U of Maine Fall,
Advertisements

CMPT 334 Computer Organization
Chapter 8. Pipelining.
Review: Pipelining. Pipelining Laundry Example Ann, Brian, Cathy, Dave each have one load of clothes to wash, dry, and fold Washer takes 30 minutes Dryer.
Pipelining I (1) Fall 2005 Lecture 18: Pipelining I.
Pipelining Hwanmo Sung CS147 Presentation Professor Sin-Min Lee.
EECS 318 CAD Computer Aided Design LECTURE 2: DSP Architectures Instructor: Francis G. Wolff Case Western Reserve University This presentation.
Goal: Describe Pipelining
CS252/Patterson Lec 1.1 1/17/01 Pipelining: Its Natural! Laundry Example Ann, Brian, Cathy, Dave each have one load of clothes to wash, dry, and fold Washer.
Chapter Six 1.
Pipelining II (1) Fall 2005 Lecture 19: Pipelining II.
CS61C L29 CPU Design : Pipelining to Improve Performance II (1) Garcia, Fall 2006 © UCB Running away with it  Our #8 football team had a great effort.
CS61C L24 Review Pipeline © UC Regents 1 CS61C - Machine Structures Lecture 24 - Review Pipelined Execution November 29, 2000 David Patterson
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 29 – CPU Design : Pipelining to Improve Performance II Designed for the.
CS Computer Architecture 1 CS 430 – Computer Architecture Pipelined Execution - Review William J. Taffe using slides of David Patterson.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 29 – CPU Design : Pipelining to Improve Performance II Cal researcher Marty.
inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 28 – CPU Design : Pipelining to Improve Performance The College Board.
CS61C L29 CPU Design : Pipelining to Improve Performance (1) Garcia, Spring 2007 © UCB Wirelessly recharge batt  Powercast & Philips have developed a.
Mary Jane Irwin ( ) [Adapted from Computer Organization and Design,
CS61C L30 CPU Design : Pipelining to Improve Performance II (1) Garcia, Spring 2007 © UCB E-voting bill in congress!  Rep Rush Holt (D-NJ) has a bill.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania Computer Organization Pipelined Processor Design 1.
Pipelining Andreas Klappenecker CPSC321 Computer Architecture.
CS61C L28 CPU Design : Pipelining to Improve Performance I (1) Garcia, Fall 2006 © UCB 100 Msites!  Sometimes it’s nice to stop and reflect. The web was.
Computer ArchitectureFall 2007 © October 22nd, 2007 Majd F. Sakr CS-447– Computer Architecture.
CS61C L21 Pipeline © UC Regents 1 CS61C - Machine Structures Lecture 21 - Introduction to Pipelined Execution November 15, 2000 David Patterson
CS61C L31 Pipelined Execution, part II (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS430 – Computer Architecture Introduction to Pipelined Execution
1 COMP 206: Computer Architecture and Implementation Montek Singh Mon., Sep 9, 2002 Topic: Pipelining Basics.
CS61C L21 Pipelining I (1) Chae, Summer 2008 © UCB Albert Chae, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #21 – Pipelining.
1 Atanasoff–Berry Computer, built by Professor John Vincent Atanasoff and grad student Clifford Berry in the basement of the physics building at Iowa State.
Scott Beamer, Instructor
CS 61C L30 Introduction to Pipelined Execution (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS 61C L18 Pipelining I (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #18: Pipelining
Computer ArchitectureFall 2008 © October 6th, 2008 Majd F. Sakr CS-447– Computer Architecture.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 17 - Pipelined.
CS61C L19 Introduction to Pipelined Execution (1) Garcia, Fall 2005 © UCB Lecturer PSOE, new dad Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS 61C L38 Pipelined Execution, part II (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Introduction to Pipelining Rabi Mahapatra Adapted from the lecture notes of Dr. John Kubiatowicz (UC Berkeley)
CS3350B Computer Architecture Winter 2015 Lecture 6.2: Instructional Level Parallelism: Hazards and Resolutions Marc Moreno Maza
Integrated Circuits Costs
EEL5708 Lotzi Bölöni EEL 5708 High Performance Computer Architecture Pipelining.
Pipelining (I). Pipelining Example  Laundry Example  Four students have one load of clothes each to wash, dry, fold, and put away  Washer takes 30.
Analogy: Gotta Do Laundry
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.
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.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
ECE 232 L18.Pipeline.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 18 Pipelining.

Cs 152 L1 3.1 DAP Fa97,  U.CB Pipelining Lessons °Pipelining doesn’t help latency of single task, it helps throughput of entire workload °Multiple tasks.
Chap 6.1 Computer Architecture Chapter 6 Enhancing Performance with Pipelining.
CSIE30300 Computer Architecture Unit 04: Basic MIPS Pipelining Hsin-Chou Chi [Adapted from material by and
CS 61C L5.2.2 Pipelining I (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Pipelining I Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
Pipelining Example Laundry Example: Three Stages
CS252/Patterson Lec 1.1 1/17/01 معماري کامپيوتر - درس نهم pipeline برگرفته از درس : Prof. David A. Patterson.
CDA 3101 Summer 2003 Introduction to Computer Organization Pipeline Control And Pipeline Hazards 17 July 2003.
Lecture 9. MIPS Processor Design – Pipelined Processor Design #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Advanced Computer Architecture CS 704 Advanced Computer Architecture Lecture 10 Computer Hardware Design (Pipeline Datapath and Control Design) Prof. Dr.
Lecture 18: Pipelining I.
Pipelines An overview of pipelining
CDA 3101 Spring 2016 Introduction to Computer Organization
CMSC 611: Advanced Computer Architecture
ECE232: Hardware Organization and Design
Lecturer: Alan Christopher
Chapter 8. Pipelining.
Pipelining Appendix A and Chapter 3.
Presentation transcript:

CS1104: Computer Organisation School of Computing National University of Singapore

CS1104-P2-7Pipelining2 PII Lecture 7: Pipelining  Pipelining Analogy  Pipelining Instruction Execution  Hazards  Advanced Pipelining Concepts by Analogy

CS1104-P2-7Pipelining3 PII Lecture 7: Pipelining  Reading:  Chapter 10 of textbook, which is Chapter 8 in “Computer Organization” by Hamacher, Vranesic and Zaky.  Optional reading: Chapter 5 in “Computer Organization & Design” by Patterson and Hennessy.

CS1104-P2-7Pipelining4 Recap: Datapath PC instruction memory +4 rt rs rd registers ALU Data memory imm 1. Instruction Fetch 2. Decode/ Register Read 3. Execute4. Memory5. Reg. Write

CS1104-P2-7Pipelining5 Gotta Do Laundry  Ann, Brian, Cathy, Dave each have one load of clothes to wash, dry, fold, and put away.  Washer takes 30 minutes.  Dryer takes 30 minutes.  “Folder” takes 30 minutes.  “Stasher” takes 30 minutes to put clothes into drawers. ABCD

CS1104-P2-7Pipelining6 Sequential Laundry  Sequential laundry takes 8 hours for 4 loads. TaskOrderTaskOrder B C D A 6 PM AM 30 Time

CS1104-P2-7Pipelining7 Pipelined Laundry  Pipelined laundry takes 3.5 hours for 4 loads. TaskOrderTaskOrder B C D A 6 PM AM 30 Time

CS1104-P2-7Pipelining8 General Definitions  Latency: time to completely execute a certain task.  For example, time to read a sector from disk is disk access time or disk latency.  Throughput: amount of work that can be done over a period of time.

CS1104-P2-7Pipelining9 Pipelining Lessons  Pipelining doesn’t help latency of single task, it helps throughput of entire workload.  Multiple tasks operating simultaneously using different resources.  Potential speedup = number of pipe stages.  Time to “fill” pipeline and time to “drain” it reduces speedup: 2.3 times versus 4 times (optimal) in this example. 6 PM Time TaskOrderTaskOrder B C D A

CS1104-P2-7Pipelining10 Pipelining Lessons (2)  Suppose new Washer takes 20 minutes, new Stasher takes 20 minutes. How much faster is the pipeline?  Pipeline rate limited by slowest pipeline stage.  Unbalanced lengths of pipe stages also reduces speedup. 6 PM Time TaskOrderTaskOrder B C D A

CS1104-P2-7Pipelining11 Pipelining Lessons (3)  Improve performance by increasing instruction throughput. Program execution order lw $1, 100($0) lw $2, 200($0) lw $3, 300($0) Instruction fetch Reg ALU Data access Instruction fetch 8 ns … Time Instruction fetch Reg ALU Data access 8 ns Program execution order lw $1, 100($0) lw $2, 200($0) lw $3, 300($0) Instruction fetch Reg ALU Data access 2 ns Time Instruction fetch Reg ALU Data access 2 ns Instruction fetch Reg ALU Data access 2 ns Ideal speedup = number of stages

CS1104-P2-7Pipelining12 Steps in Executing MIPS Instructions  IFetch: Fetch instruction, increment PC.  Decode instruction, read registers.  Execute: Memory reference (calculate address), perform arithmetic/logic operation.  Memory: Load (read data from memory), Store (write data to memory).  Write back: Write data to register.

CS1104-P2-7Pipelining13 Pipelined Execution Representation  Every instruction must take same number of steps, also called pipeline “stages”, so some will go idle sometimes. Time IFtchDcdExecMemWB IFtchDcdExecMemWB IFtchDcdExecMemWB IFtchDcdExecMemWB IFtchDcdExecMemWB IFtchDcdExecMemWB

CS1104-P2-7Pipelining14 Why cache is needed  Pipelining achieves its best effect if each stage of the pipeline takes the same amount of time (one clock cycle).  However, the first stage, instruction fetch, involves accessing the memory, which is slow.  How do we improve the time? By using cache. (To be covered later.)

CS1104-P2-7Pipelining15 Datapath Figures  Use datapath figures to represent pipeline. IFtchDcdExecMemWB ALU I$Reg D$ Reg

CS1104-P2-7Pipelining16 Graphical Pipeline Representation  In Reg, right-half is read, left-half write. Time I n s t r. o r d e r Load Add Store Sub Or I$ ALU Reg I$ D$ ALU Reg D$ Reg I$ D$ Reg ALU Reg D$ Reg D$ ALU Reg I$

CS1104-P2-7Pipelining17 Example  Suppose 2 ns for memory access, 2 ns for ALU operation, and 1 ns for register file read or write.  Non-pipelined execution:  lw : IF + Read Reg + ALU + Memory + Write Reg = = 8 ns  add: IF + Read Reg + ALU + Write Reg = = 6 ns  Pipelined execution:  Max(IF,Read Reg,ALU,Memory,Write Reg) = 2 ns

CS1104-P2-7Pipelining18 Pipelining  What makes it easy?  All instructions are the same length  Just a few instruction formats  Memory operands appear only in loads and stores  What makes it hard?  Structural hazards: suppose we had only one memory.  Control hazards: need to worry about branch instructions.  Data hazards: an instruction depends on a previous instruction.

CS1104-P2-7Pipelining19 Pipeline Hazard: Matching socks in later load A depends on D; stall since “folder” tied up. TaskOrderTaskOrder B C D A E F bubble 12 2 AM 6 PM Time 30

CS1104-P2-7Pipelining20 Problems for Computers  Limits to pipelining: Hazards prevent next instruction from executing during its designated clock cycle.  Structural hazards: Hardware cannot support this combination of instructions (single person to fold and put clothes away).  Control hazards: Pipelining of branches and other instructions stall the pipeline until the hazard “bubbles” in the pipeline.  Data hazards: Instruction depends on result of prior instruction still in the pipeline (missing sock).

CS1104-P2-7Pipelining21 Data Hazard Data hazard: an instruction depends on the results of a previous instruction still in the pipeline. Data dependencies: sub $2, $1, $3 # Reg $2 written by sub and $12, $2, $5 # 1 st operand($2) depends on sub or $13, $6, $2 # 2 nd operand($2) depends on sub and $14, $2, $2 # 1 st ($2) and 2 nd ($2) depend on sub sw $15, 100($2) # Base ($2) depends on sub

CS1104-P2-7Pipelining22 Data Hazard (2)  Data hazard could stall the pipeline.  The add instruction does not write its result until the fifth stage, meaning that we would have to add three bubbles to the pipelines. Memory bus data lines add $s0, $t0, $t1 sub $12, $s0, $t3 ALU I$ Reg D$Reg ALU Reg D$Reg I$ bubble add sub

CS1104-P2-7Pipelining23 Data Hazard (3)  Solution: Forwarding  We do not need to wait for the instruction to complete before trying to resolve the data hazard. As soon as the ALU creates the sum for the add, we can supply it as input for the subtract. ALU I$ Reg D$Reg ALU Reg D$Reg I$ add sub

CS1104-P2-7Pipelining24 Data Hazard (4)  However, forwarding cannot solve all data hazards.  Suppose the first instruction is a load instead. lw sub lw $s0, 20($t1) sub $12, $s0, $t3 ALU I$ Reg D$Reg ALU Reg D$Reg I$ bubble Even with forwarding, we would have to stall one stage.

CS1104-P2-7Pipelining25 Structural Hazard #1: Single Memory Read some memory twice in the same clock cycle. Time I n s t r. o r d e r Load Instr 1 Instr 2 Instr 3 Instr 4 I$ ALU Reg I$ D$ ALU Reg D$ Reg I$ D$ Reg ALU Reg D$ Reg D$ ALU Reg I$

CS1104-P2-7Pipelining26 Structural Hazard #1: Single Memory (2)  Solution:  infeasible and inefficient to create second memory  so simulate this by having two level 1 caches  have both an L1 instruction cache and an L1 data cache  need more complex hardware to control when both caches miss

CS1104-P2-7Pipelining27 Structural Hazard #2: Register Cannot read and write to register simultaneously. Time I n s t r. o r d e r Load Instr 1 Instr 2 Instr 3 Instr 4 I$ ALU Reg I$ D$ ALU Reg D$ Reg I$ D$ Reg ALU Reg D$ Reg D$ ALU Reg I$

CS1104-P2-7Pipelining28 Structural Hazard #2: Register (2)  Fact: Register access is VERY fast: takes less than half the time of ALU stage.  Solution: introduce convention  Always Write to Registers during first half of each clock cycle.  Always Read from Registers during second half of each clock cycle.  Result: can perform Read and Write during same clock cycle.

CS1104-P2-7Pipelining29 Control Hazard: Branching  Suppose we put branch decision-making hardware in ALU stage  then two more instructions after the branch will always be fetched, whether or not the branch is taken  Desired functionality of a branch  if we do not take the branch, don’t waste any time and continue executing normally  if we take the branch, don’t execute any instructions after the branch, just go to the desired label

CS1104-P2-7Pipelining30 Control Hazard: Branching (2)  Initial Solution: Stall until decision is made  Insert “no-op” instructions: those that accomplish nothing, just take time.  Drawback: branches take 3 clock cycles each (assuming comparator is put in ALU stage).

CS1104-P2-7Pipelining31 Control Hazard: Branching (3)  Optimization #1:  Move comparator up to stage 2.  As soon as instruction is decoded (opcode identified as a branch), immediately make a decision and set the value of the PC (if necessary).  Benefit: since branch is complete in stage 2, only one unnecessary instruction is fetched, so only one no-op is needed.  Side note: This means that branches are idle in stages 3, 4 and 5.

CS1104-P2-7Pipelining32 Control Hazard: Branching (4)  Insert a single no-op (bubble)  Impact: 2 clock cycles per branch instruction  slow Time I n s t r. o r d e r Add Beq Load ALU I$ Reg D$Reg ALU I$ Reg D$Reg ALU Reg D$Reg I$ bubble

CS1104-P2-7Pipelining33 Control Hazard: Branching (5)  Optimization #2:  Old definition: if we take the branch, none of the instructions after the branch get executed by accident.  New definition: whether or not we take the branch, the single instruction immediately following the branch gets executed (called the branch-delay slot).

CS1104-P2-7Pipelining34 Control Hazard: Branching (6)  Branch-Delay Slot  Worst-Case Scenario: Always put a no-op in the branch-delay slot.  Better Case: Find an instruction preceding the branch which can be placed in the branch-delay slot without affecting flow of the program  re-ordering instructions is a common method of speeding up programs  compiler must be very smart in order to find instructions to do this  usually can find such an instruction at least 50% of the time

CS1104-P2-7Pipelining35 Non-delayed vs. Delayed Branch Non-delayed branchDelayed branch add $1,$2,$3 sub $4, $5,$6 beq $1, $4, Exit or $8, $9,$10 xor $10, $1,$11 add $1,$2,$3 sub $4, $5,$6 beq $1, $4, Exit or $8, $9,$10 xor $10, $1,$11 Exit:

CS1104-P2-7Pipelining36 Things To Remember  Optimal Pipeline  Each stage is executing part of an instruction in each clock cycle.  One instruction finishes during each clock cycle.  On average, execute far more quickly.  What makes this work?  Similarities between instructions allow us to use same stages for all instructions (generally).  Each stage takes about the same amount of time as all others: little wasted time.

CS1104-P2-7Pipelining37 Things To Remember (2)  Pipelining a Big Idea: widely used concept  What makes it less than perfect?  Structural hazards: suppose we had only one cache?  Need more HW resources  Control hazards: need to worry about branch instructions?  Delayed branch  Data hazards: an instruction depends on a previous instruction?

38 End of file