0% found this document useful (0 votes)
277 views3 pages

Assignment 1

This document describes an assignment to analyze the effects of different branch predictors in a gem5 simulator. The assignment has four parts: 1) Add branch prediction support to the TimingSimpleCPU model, 2) Add metrics to the stats output, 3) Implement a Gshare predictor, and 4) Compare the performance of different predictors on a benchmark.

Uploaded by

Rupak Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
277 views3 pages

Assignment 1

This document describes an assignment to analyze the effects of different branch predictors in a gem5 simulator. The assignment has four parts: 1) Add branch prediction support to the TimingSimpleCPU model, 2) Add metrics to the stats output, 3) Implement a Gshare predictor, and 4) Compare the performance of different predictors on a benchmark.

Uploaded by

Rupak Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

High Performance Computer Architecture (CS60003)

Assignment 1
Indian Institute of Technology Kharagpur

In this assignment, you are required to use the gem5 simulator to study and analyze the effects of varying
Branch Predictors on a given processor model using a benchmark program. A tutorial session has already
been provided on how to install and setup gem5. The detailed slides are available on Moodle. For more
information on gem5, please visit http://learning.gem5.org/book/
The aim of this assignment is to make you familiar with the effects of Branch Predictors on the per-
formance of a system. There are a number of Branch Predictors available in gem5, which can be found in
“$gem5/src/cpu/pred”. The assignment is composed of four different modules.

1. Adding Branch Prediction Support to TimingSimple CPU: gem5 uses a number of CPU
models, like AtomicSimple, TimingSimple, InOrder, etc. The TimingSimpleCPU is the version of
SimpleCPU that uses timing memory accesses. By default, TimingSimpleCPU does not have branch
predictor support. You need to add the support of the three branch predictors, such as, 2bit local,
Bi mode and Tournament Predictors (separately) to TimingSimpleCPU. Run a HelloWorld program,
as shown in the tutorial (in class). This should generate ‘configs.ini’ file in “m5out” folder in the $gem5
directory. If your run was successful, you should be able to check the BranchPredictor being used in
the config.ini file. A snapshot of a sample ‘config.ini’ file is shown below.

Deliverable: Three ‘configs.ini’ files. One for each branch predictor.

2. Adding extra Resulting Parameters in the stats file: For every successful run, a ‘stats.txt’
file is generated in m5out folder which shows different statistics like final ticks, cache hits,
cache misses, etc. In this part, you are required to add two more parameters to the ‘stats.txt’
file. Note that the stats file is automatically generated and the event names and its corresponding
values are generated by different source files in gem5. Run a HelloWorld program, similar to the
previous part, with any of the three above-mentioned BranchPredictor support. The two parameters
that you need to add are -

(a) BTBMissPct = (1 - (BTBHits/BTBLookups)) ×100


where: BTBHits -> total number of BTB Hits
BTBLookups -> total number of BTB references
(b) BranchMispredPercent = (numBranchMispred ÷ numBranches) ×100
where: numBranchMispred -> total number of mispredicted Branches
numBranches -> total number of branches fetched

Below is a snapshot of a sample ‘stats.txt’ file with the modification:


Assignment 1 CS60003

This will require you to modify in the following source files -


$gem5/src/cpu/simple/exec context.hh
$gem5/src/cpu/pred/bpred unit.hh
$gem5/src/cpu/pred/bpred unit.cc
$gem5/src/cpu/simple/base.cc
Note that everytime you modify something in the source files, you have to build gem5 (using scons
build/X86/gem5.opt -j5).
Deliverable: The above four files and ‘stats.txt’ from md5out folder

3. Implement a Gshare Predictor: In this part, you are required to implement Gshare branch pre-
dictor. There are several branch predictors implemented in gem5, including 2-bit local predictor,
bi-modal predictor, and tournament predictor. However, gem5 does not expose any branch prediction
configuration in the command-line interface. src/cpu/o3/O3CPU.py is the file where the particular
branch prediction is selected, whereas src/cpu/pred/BranchPredictor.py specifies the configuration
of each predictor. All the branch prediction implementation can be found in src/cpu/pred as well.
The branch predictor in gem5 inherit the base class, BPredUnit, from src/cpu/pred/bpred unit.hh.
The different behaviors of predictors are distinguished in the 5 virtual functions - lookup, update,
uncondBranch, btbUpdate, and squash. To implement a new branch predictor, you only have
to fill up these 5 function with your own design. Here are the descriptions and notes of each virtual
function.

• lookup: This function returns whether a branch with a given PC is predicted as taken or not
taken. The counter data of branch history (Like the counter to store the global history and the
counter for local history for the specific PC) are also backup in this stage, and can be used to
restore those counter if necessary.
• update: Update those counter value of history in any mean for branch prediction by a given
outcome of a branch instruction. Note that the function argument, squashed, is to indicate
whether this is a misprediction or not.
• uncondBranch: This function is called when the target branch instruction is an unconditional
branch. Typically, a branch predictor will do nothing but update global history with taken, as a
unconditional branch is always taken.

2
Assignment 1 CS60003

• btbUpdate: This function is called only if there is a miss in Branch Target Buffer (BTB).
It means the branch prediction does not know where to jump even though the predictor can
accurately predict the branch outcome. In this case, you will predict a branch as not taken so
that the target branch address is not required. Thus, this function is typically to correct what
you did in the lookup function into a result that you predict a branch as non-taken.
• squash: If there is a branch misprediction, everything changed (counters, registers, cache, mem-
ory, etc) due to the outstanding instructions after this branch need to be reverted back into the
state before the branch instruction was issued. This includes those victim branch instructions
following the branch misprediction. This function is primarily called to erase what the outstand-
ing branches did to those history counters by restoring them with the backup value you stored
in update function.

The following table contains the parameters you need to set for the three branch predictors. Run
using the se.py script provided in gem5. You only enable the following flags and leave all others as
the default --cpu-type=DerivO3CPU --caches --l2cache --bpred= TournamentBP(), LocalBP()
and GshareBP().

2-bit local Tournament Gshare


Local History table - 1024 * 11 bits
Local predictor size - 2048 * 2 bits 16384 entries * 2 bit
16384 entries
One 12-bit Global history register one 16-bit Global history
* 2 bits
Global predictor size - 4096 * 2 bits register
Choice predictor size - 4096 * 2 bits

Deliverables: Submit only the modified files.

4. Running the benchmarks for comparison: In this part, you are required to compare between
the performance of three branch predictors - 2bit local, Tournament, Gshare (that you just im-
plemented) using a benchmark program. The benchmark program named blocked matmul.c has
been provided in Moodle. Run the program using se.py script with the following cache parameters:
--l1d size=128kB --l1i size=128kB --l2 size=1MB --l1d assoc=2 --l1i assoc=2 --l2 assoc=4
--cacheline size=64.
Deliverables: A report (in a pdf format) about the observed effects of the Branch Predictors with
respect to the benchmark program.

N.B. All the submissions will be screened through Moss (https://theory.stanford.edu/~aiken/


moss/). If considerable similarities are found between multiple submissions, they will be heavily
penalised.

You might also like