Commit c17389dd authored by Jacky Lin's avatar Jacky Lin
Browse files

add readme

parent 20204032
......@@ -13,7 +13,7 @@ Fall 2021 Semester
## Project description
This RISC-V project aims to implement all branch predictors we learned from class and evaluate them on the benchmark programs. We have implemented 6 types of branch predictors, including static, global, local, Gshare, Pshare, and tournament.
This RISC-V project aims to implement all branch predictors we learned from class and evaluate them on the benchmark programs. We have implemented 6 types of branch predictors each as a class in [branch_predict](branch_predict.py), including static, global, local, Gshare, Pshare, and tournament.
The branch predictors are tested on the [hello](riscv_isa/programs/hello), [return](riscv_isa/programs/return), and 7 benchmark programs in [riscv_isa/programs/benchmarks](riscv_isa/programs/benchmarks). The index bits of PC, size of correlation register, and size of saturation counters are all set to 2 in our experiments. The initial value of the saturation counter is 00.
......@@ -39,7 +39,9 @@ To further investigate the influence of predictor size on the prediction accurac
## Usage
We generated the branch result file from the `onestage_elf_project2.py` and dumped all the files (`pkl` format ) into a folder called `all_pkl_files/`. After that, run `main.py` for each branch predictor specified below:
We generated the branch result file from the `onestage_elf_project2.py` and dumped all the files (`pkl` format ) into a folder called `all_pkl_files/`.
After that, run `main.py` . User can select which branch predictor to use as specified below (default is Static):
| Branch Predictor | Option |
| :--------------: | :----: |
......@@ -49,3 +51,40 @@ We generated the branch result file from the `onestage_elf_project2.py` and dump
| GShare | `g` |
| PShare | `x` |
| Tournament | `t` |
```bash
python main.py [-h] [-s] [-b] [-p] [-g] [-x] [-t] [path [path ...]]
```
Where `path` is the input file name or directory.
Note that if multiple predictor is specified, it uses the first one.
Docs
```
usage: main.py [-h] [-s] [-b] [-p] [-g] [-x] [-t] [path [path ...]]
The following arguments can help debug and test the program
positional arguments:
path input filepath
optional arguments:
-h, --help show this help message and exit
-s if use static predictor mode
-b if use BHT predictor mode
-p if use PHT predictor mode
-g if use GShare predictor mode
-x if use PShare predictor mode
-t if use Tournament predictor mode
```
## Develop Mode
To use our branch predictor in your own project, you can import need predictor class in [branch_predict.py](branch_predict.py) and instantiate. All the predictor classes have 3 methods: `__init__`, `predict`, `update`. To use our class, you need to use the `Instruction` class as input to `predict()` method. After that input whether the branch is taken or not as a `int` into `update()` method. For example,
```python
bht = BHT()
bht.predict(instr)
bht.update(is_taken)
```
No preview for this file type
from branch_predict import *
import pickle
import numpy as np
#import numpy as np
import os
def read_branch(fname, opt=None):
......@@ -34,11 +34,7 @@ def sel_pred(opt = None):
elif opt == "b" or opt == "bht":
return BHT()
elif opt == "p" or opt == "pht":
<<<<<<< HEAD
return PHT(pht_bit=4)
=======
return PHT(8)
>>>>>>> 98471ba60277a31655b4fc7d28a768ee32f99fbd
return PHT()
elif opt == "g" or opt == "gshare":
return GShare()
elif opt == "x" or opt == "pshare":
......
No preview for this file type
import argparse
from branch_reader import read_branch
if __name__ == "__main__":
default_in_fname = "riscv_isa/programs/hello"
parser = argparse.ArgumentParser(description = 'The following arguments can help debug and test the program')
#parser.add_argument('-t', action = "store_true", default = False, help = "if use test mode")
parser.add_argument('path', nargs = '+', type=str, default = "riscv_isa/programs/hello", help = "input filepath")
parser.add_argument('-s', action = "store_true", required = False, default = False, help = "if use static predictor mode")
parser.add_argument('-b', action = "store_true", required = False, default = False, help = "if use BHT predictor mode")
parser.add_argument('-p', action = "store_true", required = False, default = False, help = "if use PHT predictor mode")
parser.add_argument('-g', action = "store_true", required = False, default = False, help = "if use GShare predictor mode")
parser.add_argument('-x', action = "store_true", required = False, default = False, help = "if use PShare predictor mode")
parser.add_argument('-t', action = "store_true", required = False, default = False, help = "if use Tournament predictor mode")
parser.add_argument('path', nargs = '*', type=str, default = default_in_fname, help = "input filepath")
args = parser.parse_args()
path = args.path
for testfile in path:
read_branch(testfile, opt='p')
select_modes = [args.s, args.b, args.p, args.g, args.x, args.t, True]
modes = ['s', 'b', 'p', 'g', 'x', 't', None]
if path == default_in_fname:
read_branch(path, opt=modes[select_modes.index(True)])
else:
for testfile in path:
read_branch(testfile, opt=modes[select_modes.index(True)])
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment