-
Notifications
You must be signed in to change notification settings - Fork 23
Perceptron predictor #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Perceptron predictor #374
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
52f6f96
Adding PerceptronPredictor class and rebasing
ABenC377 fec45b7
Updating default config options to include Branch Predictor Type
ABenC377 b0afe42
Shuffling order of declarations in PerceptronPRedictor.hh
ABenC377 68387e0
Shuffling order of declarations in PerceptronPRedictor.hh
ABenC377 bc95bce
debugging -- squash this commit
ABenC377 8f54745
Sorting out tests
ABenC377 0aa88a1
tidying
ABenC377 c1a3cd2
Adding to documentation
ABenC377 ede562d
Adding to documentation
ABenC377 8a042c3
Adding comments, adding if to config
ABenC377 13e79e2
Adjusting tests in view of config changes
ABenC377 4351315
clang format and finessing
ABenC377 229862c
Making passed perceptron vector a const in getDotProduct() helper fuc…
ABenC377 cb6dedc
Reformatting ConfigTest.cc strings
ABenC377 c8e83b2
Consolidating if logic in BP-related ModelConfig.cc
ABenC377 2e6e041
passing perceptron by reference in getDotProduct()
ABenC377 1b194a7
doc changes
ABenC377 5413b63
doc changes
ABenC377 5f2b5b8
Changes docs
ABenC377 526f509
Changes docs
ABenC377 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #pragma once | ||
|
|
||
| #include <deque> | ||
| #include <map> | ||
| #include <vector> | ||
|
|
||
| #include "simeng/BranchPredictor.hh" | ||
| #include "simeng/config/SimInfo.hh" | ||
|
|
||
| namespace simeng { | ||
|
|
||
| /** A Perceptron branch predictor implementing the branch predictor described in | ||
| * Jimenez and Lin ("Dynamic branch prediction with perceptrons", IEEE High- | ||
| * Performance Computer Architecture Symposium Proceedings (2001), 197-206 -- | ||
| * https://www.cs.utexas.edu/~lin/papers/hpca01.pdf). | ||
| * The following predictors have been included: | ||
| * | ||
| * - Static predictor based on pre-allocated branch type. | ||
| * | ||
| * - A Branch Target Buffer (BTB) with a local and global indexing scheme and a | ||
| * perceptron. | ||
| * | ||
| * - A Return Address Stack (RAS) is also in use. | ||
| */ | ||
|
|
||
| class PerceptronPredictor : public BranchPredictor { | ||
| public: | ||
| /** Initialise predictor models. */ | ||
| PerceptronPredictor(ryml::ConstNodeRef config = config::SimInfo::getConfig()); | ||
| ~PerceptronPredictor(); | ||
|
|
||
| /** Generate a branch prediction for the supplied instruction address, a | ||
| * branch type, and a known branch offset; defaults to 0 meaning offset is not | ||
| * known. Returns a branch direction and branch target address. */ | ||
| BranchPrediction predict(uint64_t address, BranchType type, | ||
| int64_t knownOffset = 0) override; | ||
|
|
||
| /** Updates appropriate predictor model objects based on the address and | ||
| * outcome of the branch instruction. */ | ||
| void update(uint64_t address, bool taken, uint64_t targetAddress, | ||
| BranchType type) override; | ||
|
|
||
| /** Provides RAS rewinding behaviour. */ | ||
| void flush(uint64_t address) override; | ||
|
|
||
| private: | ||
| /** Returns the dot product of a perceptron and a history vector. Used to | ||
| * determine a direction prediction */ | ||
| int64_t getDotProduct(const std::vector<int8_t>& perceptron, | ||
| uint64_t history); | ||
|
|
||
| /** The length in bits of the BTB index; BTB will have 2^bits entries. */ | ||
| uint64_t btbBits_; | ||
|
|
||
| /** A 2^bits length vector of pairs containing a perceptron with | ||
| * globalHistoryLength_ + 1 inputs, and a branch target. | ||
| * The perceptrons are used to provide a branch direction prediction by | ||
| * taking a dot product with the global history, as described | ||
| * in Jiminez and Lin */ | ||
|
dANW34V3R marked this conversation as resolved.
|
||
| std::vector<std::pair<std::vector<int8_t>, uint64_t>> btb_; | ||
|
|
||
|
dANW34V3R marked this conversation as resolved.
|
||
| /** The previous hashed index for an address. */ | ||
| std::map<uint64_t, uint64_t> btbHistory_; | ||
|
|
||
| /** An n-bit history of previous branch directions where n is equal to | ||
| * globalHistoryLength_. */ | ||
| uint64_t globalHistory_ = 0; | ||
|
|
||
| /** The number of previous branch directions recorded globally. */ | ||
| uint64_t globalHistoryLength_; | ||
|
|
||
| /** The magnitude of the dot product of the perceptron and the global history, | ||
| * below which the perceptron's weight must be updated */ | ||
| uint64_t trainingThreshold_; | ||
|
|
||
| /** A return address stack. */ | ||
| std::deque<uint64_t> ras_; | ||
|
|
||
| /** RAS history with instruction address as the keys. A non-zero value | ||
| * represents the target prediction for a return instruction and a 0 entry for | ||
| * a branch-and-link instruction. */ | ||
| std::map<uint64_t, uint64_t> rasHistory_; | ||
|
|
||
| /** The size of the RAS. */ | ||
| uint64_t rasSize_; | ||
| }; | ||
|
|
||
| } // namespace simeng | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.