Samira Khan University of Virginia Mar 6, 2019

Slides:



Advertisements
Similar presentations
Dynamic History-Length Fitting: A third level of adaptivity for branch prediction Toni Juan Sanji Sanjeevan Juan J. Navarro Department of Computer Architecture.
Advertisements

Hardware-based Devirtualization (VPC Prediction) Hyesoon Kim, Jose A. Joao, Onur Mutlu ++, Chang Joo Lee, Yale N. Patt, Robert Cohn* ++ *
Pipeline Computer Organization II 1 Hazards Situations that prevent starting the next instruction in the next cycle Structural hazards – A required resource.
Dynamic Branch Prediction
Pipeline Hazards Pipeline hazards These are situations that inhibit that the next instruction can be processed in the next stage of the pipeline. This.
CPE 731 Advanced Computer Architecture ILP: Part II – Branch Prediction Dr. Gheith Abandah Adapted from the slides of Prof. David Patterson, University.
Computer Architecture 2011 – Branch Prediction 1 Computer Architecture Advanced Branch Prediction Lihu Rappoport and Adi Yoaz.
Neural Methods for Dynamic Branch Prediction Daniel A. Jiménez Calvin Lin Dept. of Computer Science Rutgers University Univ. of Texas Austin Presented.
1 COMP 206: Computer Architecture and Implementation Montek Singh Wed., Oct. 8, 2003 Topic: Instruction-Level Parallelism (Dynamic Branch Prediction)
1 COMP 206: Computer Architecture and Implementation Montek Singh Mon., Oct. 7, 2002 Topic: Instruction-Level Parallelism (Dynamic Branch Prediction)
1 Lecture 7: Out-of-Order Processors Today: out-of-order pipeline, memory disambiguation, basic branch prediction (Sections 3.4, 3.5, 3.7)
EECE476: Computer Architecture Lecture 20: Branch Prediction Chapter extra The University of British ColumbiaEECE 476© 2005 Guy Lemieux.
EECC551 - Shaaban #1 lec # 5 Fall Reduction of Control Hazards (Branch) Stalls with Dynamic Branch Prediction So far we have dealt with.
EENG449b/Savvides Lec /17/04 February 17, 2004 Prof. Andreas Savvides Spring EENG 449bG/CPSC 439bG.
Branch Target Buffers BPB: Tag + Prediction
EECC551 - Shaaban #1 lec # 5 Winter Reduction of Control Hazards (Branch) Stalls with Dynamic Branch Prediction So far we have dealt with.
Computer Architecture Instruction Level Parallelism Dr. Esam Al-Qaralleh.
Branch Prediction Dimitris Karteris Rafael Pasvantidιs.
Dynamic Branch Prediction
EENG449b/Savvides Lec /25/05 March 24, 2005 Prof. Andreas Savvides Spring g449b EENG 449bG/CPSC 439bG.
CIS 429/529 Winter 2007 Branch Prediction.1 Branch Prediction, Multiple Issue.
Neural Methods for Dynamic Branch Prediction Daniel A. Jiménez Department of Computer Science Rutgers University.
Evaluation of Dynamic Branch Prediction Schemes in a MIPS Pipeline Debajit Bhattacharya Ali JavadiAbhari ELE 475 Final Project 9 th May, 2012.
1 Dynamic Branch Prediction. 2 Why do we want to predict branches? MIPS based pipeline – 1 instruction issued per cycle, branch hazard of 1 cycle. –Delayed.
CSCI 6461: Computer Architecture Branch Prediction Instructor: M. Lancaster Corresponding to Hennessey and Patterson Fifth Edition Section 3.3 and Part.
André Seznec Caps Team IRISA/INRIA 1 A 256 Kbits L-TAGE branch predictor André Seznec IRISA/INRIA/HIPEAC.
CS 6290 Branch Prediction. Control Dependencies Branches are very frequent –Approx. 20% of all instructions Can not wait until we know where it goes –Long.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 13: Branch prediction (Chapter 4/6)
Branch Prediction Perspectives Using Machine Learning Veerle Desmet Ghent University.
Samira Khan University of Virginia April 12, 2016
Dynamic Branch Prediction
Computer Architecture Lecture 11: Branch Prediction Prof. Onur Mutlu Carnegie Mellon University Spring 2013, 2/11/2013.
CSL718 : Pipelined Processors
Computer Architecture Lecture 10: Branch Prediction II
Computer Architecture: Branch Prediction (II) and Predicated Execution
CS203 – Advanced Computer Architecture
Computer Structure Advanced Branch Prediction
Dynamic Branch Prediction
Computer Architecture Advanced Branch Prediction
CS5100 Advanced Computer Architecture Advanced Branch Prediction
COSC3330 Computer Architecture Lecture 15. Branch Prediction
Samira Khan University of Virginia Nov 13, 2017
Samira Khan University of Virginia Dec 4, 2017
CMSC 611: Advanced Computer Architecture
15-740/ Computer Architecture Lecture 25: Control Flow II
Module 3: Branch Prediction
So far we have dealt with control hazards in instruction pipelines by:
Branch statistics Branches occur every 4-6 instructions (16-25%) in integer programs; somewhat less frequently in scientific ones Unconditional branches.
15-740/ Computer Architecture Lecture 24: Control Flow
Lecture: Branch Prediction
18-740/640 Computer Architecture Lecture 5: Advanced Branch Prediction
Dynamic Branch Prediction
Advanced Computer Architecture
So far we have dealt with control hazards in instruction pipelines by:
Lecture 10: Branch Prediction and Instruction Delivery
Samira Khan University of Virginia Nov 5, 2018
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
Pipelining: dynamic branch prediction Prof. Eric Rotenberg
Adapted from the slides of Prof
Dynamic Hardware Prediction
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
So far we have dealt with control hazards in instruction pipelines by:
Computer Architecture Lecture 9: Branch Prediction
18-447: Computer Architecture Lecture 11: Control Flow Handling
Lecture 7: Branch Prediction, Dynamic ILP
Design of Digital Circuits Lecture 18: Branch Prediction
Presentation transcript:

Samira Khan University of Virginia Mar 6, 2019 ADVANCED COMPUTER ARCHITECTURE CS 4330/6501 Branch Prediction Samira Khan University of Virginia Mar 6, 2019 The content and concept of this course are adapted from CMU ECE 740

AGENDA Logistics Review from the last class Branch Prediction

LOGISTICS Mar 18: Second Student Paper Presentation Two papers Presenters do not need to submit reviews Beyond the Memory Wall: A Case for Memory-centric HPC System for Deep Learning, MICRO 2018 EIE: Efficient Inference Engine on Compressed Deep Neural Network, ISCA 2016

Presentation Guidelines 30 mins for presentation and 5 mins for Q&A Start with authors’ slide and then modify them to make yours Format is similar to reviews Spend significant time on the background and problem Key idea Mechanism Results. Pros, cons, what did you like, future work Send the slides at least one week before the presentation Practice at least 3 times before the class If necessary, first write down and then practice

Presentation Guidelines Background and problem statement (10 mins) Key idea/mechanism (8-10 mins) Results (2-3 mins) Pros/cons/discussion (5-7 mins) Q&A (5 mins)

BRANCH PREDICTION Idea: Predict the next fetch address (to be used in the next cycle) Requires three things to be predicted at fetch stage: Whether the fetched instruction is a branch (Conditional) branch direction Branch target address (if taken) Observation: Target address remains the same for a conditional direct branch across dynamic instances Idea: Store the target address from previous instance and access it with the PC Called Branch Target Buffer (BTB) or Branch Target Address Cache

THE LAST TIME PREDICTOR Problem: A last-time predictor changes its prediction from TNT or NTT too quickly even though the branch may be mostly taken or mostly not taken Solution Idea: Add hysteresis to the predictor so that prediction does not change on a single different outcome Use two bits to track the history of predictions for a branch instead of a single bit Can have 2 states for T or NT instead of 1 state for each Smith, “A Study of Branch Prediction Strategies,” ISCA 1981.

TWO-BIT COUNTER BASED PREDICTION Each branch associated with a two-bit counter One more bit provides hysteresis A strong prediction does not change with one single different outcome Accuracy for a loop with N iterations = (N-1)/N for (i=0; i<N; i++) { … } Prediction: TTTT …. T TTTT ... T TTTT ... T Actual: TTTT .... N TTTT ... N TTTT ... N TNTNTNTNTNTNTNTNTNTN  50% accuracy (assuming init to weakly taken) + Better prediction accuracy -- More hardware cost (but counter can be part of a BTB entry)

STATE MACHINE FOR 2-BIT SATURATING COUNTER Counter using saturating arithmetic There is a symbol for maximum and minimum values “weakly taken” actually taken actually !taken pred taken 11 pred taken 10 “strongly taken” actually taken actually taken “strongly !taken” pred !taken 01 pred !taken 00 “weakly !taken” actually taken

IS THIS ENOUGH? ~85-90% accuracy for many programs with 2-bit counter based prediction (also called bimodal prediction) Is this good enough? How big is the branch problem?

REVIEW: RETHINKING THE BRANCH PROBLEM Control flow instructions (branches) are frequent 15-25% of all instructions Problem: Next fetch address after a control-flow instruction is not determined after N cycles in a pipelined processor N cycles: (minimum) branch resolution latency Stalling on a branch wastes instruction processing bandwidth (i.e. reduces IPC) N x IW instruction slots are wasted (IW: issue width) How do we keep the pipeline full after a branch? Problem: Need to determine the next fetch address when the branch is fetched (to avoid a pipeline bubble)

REVIEW: IMPORTANCE OF THE BRANCH PROBLEM Assume a 5-wide superscalar pipeline with 20-cycle branch resolution latency How long does it take to fetch 500 instructions? Assume no fetch breaks and 1 out of 5 instructions is a branch 100% accuracy 100 cycles (all instructions fetched on the correct path) No wasted work 99% accuracy 100 (correct path) + 20 (wrong path) = 120 cycles 20% extra instructions fetched 98% accuracy 100 (correct path) + 20 * 2 (wrong path) = 140 cycles 40% extra instructions fetched 95% accuracy 100 (correct path) + 20 * 5 (wrong path) = 200 cycles 100% extra instructions fetched

CAN WE DO BETTER? Last-time and 2BC predictors exploit “last-time” predictability Realization 1: A branch’s outcome can be correlated with other branches’ outcomes Global branch correlation Realization 2: A branch’s outcome can be correlated with past outcomes of the same branch (other than the outcome of the branch “last-time” it was executed) Local branch correlation

GLOBAL BRANCH CORRELATION (I) Recently executed branch outcomes in the execution path is correlated with the outcome of the next branch If first branch not taken, second also not taken If first branch taken, second definitely not taken

GLOBAL BRANCH CORRELATION (II) If Y and Z both taken, then X also taken If Y or Z not taken, then X also not taken

GLOBAL BRANCH CORRELATION (III) Eqntott, SPEC 1992 if (aa==2) ;; B1 aa=0; if (bb==2) ;; B2 bb=0; if (aa!=bb) { ;; B3 …. } If B1 is taken (i.e. aa=0@B3) and B2 is taken (i.e. bb=0@B2) then B3 is certainly NOT taken

CAPTURING GLOBAL BRANCH CORRELATION Idea: Associate branch outcomes with “global T/NT history” of all branches Make a prediction based on the outcome of the branch the last time the same global branch history was encountered Implementation: Keep track of the “global T/NT history” of all branches in a register  Global History Register (GHR) Use GHR to index into a table of that recorded the outcome that was seen for that GHR value in the recent past  Pattern History Table (table of 2-bit counters) Global history/branch predictor Uses two levels of history (GHR + history at that GHR)

TWO LEVEL GLOBAL BRANCH PREDICTION First level: Global branch history register (N bits) The direction of last N branches Second level: Table of saturating counters for each history entry The direction the branch took the last time the same history was seen Pattern History Table (PHT) 00 …. 00 1 1 ….. 1 0 00 …. 01 2 3 previous one 00 …. 10 GHR (global history register) index 1 11 …. 11 Yeh and Patt, “Two-Level Adaptive Training Branch Prediction,” MICRO 1991.

HOW DOES THE GLOBAL PREDICTOR WORK? McFarling, “Combining Branch Predictors,” DEC WRL TR 1993. This branch tests i Last 4 branches test j History: TTTN Predict taken for i Next history: TTNT (shift in last outcome) Start with j=3, last iteration that is not taken…

ONE-LEVEL BRANCH PREDICTOR Direction predictor (2-bit counters) taken? PC + inst size Next Fetch Address Program Counter hit? Address of the current instruction target address Cache of Target Addresses (BTB: Branch Target Buffer)

TWO-LEVEL GLOBAL HISTORY PREDICTOR Direction predictor (2-bit counters) Which direction earlier branches went taken? Global branch history PC + inst size Next Fetch Address Program Counter hit? Address of the current instruction target address Cache of Target Addresses (BTB: Branch Target Buffer)

TWO-LEVEL GSHARE PREDICTOR Direction predictor (2-bit counters) Which direction earlier branches went taken? Global branch history PC + inst size Next Fetch Address XOR Program Counter hit? Address of the current instruction target address Cache of Target Addresses (BTB: Branch Target Buffer)

CAN WE DO BETTER? Last-time and 2BC predictors exploit “last-time” predictability Realization 1: A branch’s outcome can be correlated with other branches’ outcomes Global branch correlation Realization 2: A branch’s outcome can be correlated with past outcomes of the same branch (other than the outcome of the branch “last-time” it was executed) Local branch correlation

LOCAL BRANCH CORRELATION McFarling, “Combining Branch Predictors,” DEC WRL TR 1993.

MORE MOTIVATION FOR LOCAL HISTORY To predict a loop branch “perfectly”, we want to identify the last iteration of the loop By having a separate PHT entry for each local history, we can distinguish different iterations of a loop Works for “short” loops

CAPTURING LOCAL BRANCH CORRELATION Idea: Have a per-branch history register Associate the predicted outcome of a branch with “T/NT history” of the same branch Make a prediction is based on the outcome of the branch the last time the same local branch history was encountered Called the local history/branch predictor Uses two levels of history (Per-branch history register + history at that history register value)

TWO LEVEL LOCAL BRANCH PREDICTION First level: A set of local history registers (N bits each) Select the history register based on the PC of the branch Second level: Table of saturating counters for each history entry The direction the branch took the last time the same history was seen Pattern History Table (PHT) 00 …. 00 1 1 ….. 1 0 00 …. 01 2 3 00 …. 10 index 1 Local history registers 11 …. 11 Yeh and Patt, “Two-Level Adaptive Training Branch Prediction,” MICRO 1991.

TWO-LEVEL LOCAL HISTORY PREDICTOR Which directions earlier instances of *this branch* went Direction predictor (2-bit counters) taken? PC + inst size Next Fetch Address Program Counter hit? Address of the current instruction target address Cache of Target Addresses (BTB: Branch Target Buffer)

CAN WE DO EVEN BETTER? Predictability of branches varies Some branches are more predictable using local history Some using global For others, a simple two-bit counter is enough Yet for others, a bit is enough Observation: There is heterogeneity in predictability behavior of branches No one-size fits all branch prediction algorithm for all branches Idea: Exploit that heterogeneity by designing heterogeneous branch predictors

HYBRID BRANCH PREDICTORS Idea: Use more than one type of predictor (i.e., multiple algorithms) and select the “best” prediction E.g., hybrid of 2-bit counters and global predictor Advantages: + Better accuracy: different predictors are better for different branches + Reduced warmup time (faster-warmup predictor used until the slower-warmup predictor warms up) Disadvantages: -- Need “meta-predictor” or “selector” -- Longer access latency McFarling, “Combining Branch Predictors,” DEC WRL Tech Report, 1993.

ALPHA 21264 TOURNAMENT PREDICTOR Minimum branch penalty: 7 cycles Typical branch penalty: 11+ cycles 48K bits of target addresses stored in I-cache Predictor tables are reset on a context switch Kessler, “The Alpha 21264 Microprocessor,” IEEE Micro 1999.

BRANCH PREDICTION ACCURACY (EXAMPLE) Bimodal: table of 2bc indexed by branch address

ARE WE DONE W/ BRANCH PREDICTION? Hybrid branch predictors work well E.g., 90-97% prediction accuracy on average Some “difficult” workloads still suffer, though! E.g., gcc Max IPC with tournament prediction: 9 Max IPC with perfect prediction: 35

ARE WE DONE W/ BRANCH PREDICTION? Chappell et al., “Simultaneous Subordinate Microthreading (SSMT),” ISCA 1999.

SOME OTHER BRANCH PREDICTOR TYPES Loop branch detector and predictor Loop iteration count detector/predictor Works well for loops, where iteration count is predictable Used in Intel Pentium M Perceptron branch predictor Learns the direction correlations between individual branches Assigns weights to correlations Jimenez and Lin, “Dynamic Branch Prediction with Perceptrons,” HPCA 2001. Hybrid history length based predictor Uses different tables with different history lengths Seznec, “Analysis of the O-Geometric History Length branch predictor,” ISCA 2005.

Intel Pentium M Predictors Gochman et al., “The Intel Pentium M Processor: Microarchitecture and Performance,” Intel Technology Journal, May 2003.

Perceptron Branch Predictor (I) Idea: Use a perceptron to learn the correlations between branch history register bits and branch outcome A perceptron learns a target Boolean function of N inputs Jimenez and Lin, “Dynamic Branch Prediction with Perceptrons,” HPCA 2001. Rosenblatt, “Principles of Neurodynamics: Perceptrons and the Theory of Brain Mechanisms,” 1962 Each branch associated with a perceptron A perceptron contains a set of weights wi Each weight corresponds to a bit in the GHR How much the bit is correlated with the direction of the branch  Positive correlation: large + weight  Negative correlation: large - weight Prediction:  Express GHR bits as 1 (T) and -1 (NT)  Take dot product of GHR and weights  If output > 0, predict taken

Samira Khan University of Virginia Mar 6, 2019 ADVANCED COMPUTER ARCHITECTURE CS 4330/6501 Branch Prediction Samira Khan University of Virginia Mar 6, 2019 The content and concept of this course are adapted from CMU ECE 740