Skip to content

Commit bd047bb

Browse files
committed
bpu: analyse perceptron
Change-Id: I63e3e2935247d9528e487a811bea72fc0413c5cc
1 parent f9563f4 commit bd047bb

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

configs/example/kmhv3.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ def setKmhV3Params(args, system):
109109
cpu.branchPred.ras.enabled = True
110110

111111
# prediction
112-
cpu.branchPred.mgsc.enablePerceptionPred = True
113-
cpu.branchPred.mgsc.percepTableEntryNum = 128
112+
cpu.branchPred.mgsc.enablePerceptronPred = True
113+
cpu.branchPred.mgsc.percepTableEntryNum = 256
114114
cpu.branchPred.mgsc.percepTableWidth = 9
115115
cpu.branchPred.mgsc.gbhrLen = 4096
116116
cpu.branchPred.mgsc.percepThres = 7960
117117

118-
cpu.branchPred.mgsc.enableBwTable = True
119-
cpu.branchPred.mgsc.enableLTable = True
120-
cpu.branchPred.mgsc.enableITable = True
121-
cpu.branchPred.mgsc.enablePTable = True
118+
cpu.branchPred.mgsc.enableBwTable = False
119+
cpu.branchPred.mgsc.enableLTable = False
120+
cpu.branchPred.mgsc.enableITable = False
121+
cpu.branchPred.mgsc.enablePTable = False
122122
cpu.branchPred.mgsc.enableBiasTable = True
123123

124124
# l1 cache per core

src/cpu/pred/BranchPredictor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,9 +1127,9 @@ class BTBMGSC(TimedBaseBTBPredictor):
11271127
biasTableIdxWidth = Param.Unsigned(11, "Log number of bias entries")
11281128

11291129
percepTableEntryNum = Param.Unsigned(512, "Num of entries in perception preditor weight table")
1130-
gbhrLen = Param.Unsigned(64, "Length of gbhr in perception predictor")
1131-
percepTableWidth = Param.Unsigned(8, "Width of weight in perception predictor table")
1132-
percepThres = Param.Unsigned(137, "Threshold of perception predictor")
1130+
gbhrLen = Param.Unsigned(128, "Length of gbhr in perception predictor")
1131+
percepTableWidth = Param.Unsigned(9, "Width of weight in perception predictor table")
1132+
percepThres = Param.Unsigned(262, "Threshold of perception predictor")
11331133

11341134
thresholdTablelogSize = Param.Unsigned(6,
11351135
"Log size of update threshold counters tables")
@@ -1160,7 +1160,7 @@ class BTBMGSC(TimedBaseBTBPredictor):
11601160
enablePTable = Param.Bool(False, "Enable P (path) table")
11611161
enableBiasTable = Param.Bool(True, "Enable Bias table")
11621162
enablePCThreshold = Param.Bool(False, "Enable PC-indexed threshold table")
1163-
enablePerceptionPred = Param.Bool(False, "Enable perception predictor")
1163+
enablePerceptronPred = Param.Bool(True, "Enable perception predictor")
11641164

11651165
numDelay = 2
11661166

src/cpu/pred/btb/btb_mgsc.cc

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ BTBMGSC::initStorage()
109109
pWeightTable.resize(weightTableSize);
110110
biasWeightTable.resize(weightTableSize);
111111

112-
//perception weightTable init
112+
//perceptron weightTable init
113113
auto allocWeightTable = [&](std::vector<std::vector<int16_t>> &table,unsigned numEntries) -> uint64_t {
114114
assert(isPowerOf2(numEntries));
115115
// if (!isPowerOf2(numEntries)) {
@@ -172,7 +172,7 @@ BTBMGSC::BTBMGSC()
172172
enablePTable(true),
173173
enableBiasTable(true),
174174
enablePCThreshold(false),
175-
enablePerceptionPred(false),
175+
enablePerceptronPred(false),
176176
mgscStats()
177177
{
178178
// Test-only small config: keep tables tiny and deterministic for fast unit tests.
@@ -224,7 +224,7 @@ BTBMGSC::BTBMGSC(const Params &p)
224224
enablePTable(p.enablePTable),
225225
enableBiasTable(p.enableBiasTable),
226226
enablePCThreshold(p.enablePCThreshold),
227-
enablePerceptionPred(p.enablePerceptionPred),
227+
enablePerceptronPred(p.enablePerceptronPred),
228228
mgscStats(this)
229229
{
230230
DPRINTF(MGSC, "BTBMGSC constructor\n");
@@ -445,18 +445,20 @@ BTBMGSC::generateSinglePrediction(const BTBEntry &btb_entry, const Addr &startPC
445445
int total_sum = bw_scaled_percsum + l_scaled_percsum + i_scaled_percsum + g_scaled_percsum + p_scaled_percsum +
446446
bias_scaled_percsum;
447447

448-
//genertate perception prediction
449-
int percep_sum = enablePerceptionPred ? calculatePercepSum(btb_entry.pc) : 0;
448+
//genertate perceptron prediction
449+
int percep_sum =calculatePercepSum(btb_entry.pc);
450450
int percep_index = getPercepIndex(btb_entry.pc,gbhr);
451451
// Find thresholds
452452
// pc-indexed threshold table (only if enabled)
453453
int p_update_thres = enablePCThreshold ? findThreshold(pUpdateThreshold, btb_entry.pc) : 0;
454454

455455
int total_thres = (updateThreshold / 8) + p_update_thres;
456456
int percep_thres = percepThres;
457+
total_thres = enablePerceptronPred ? percep_thres : total_thres;
458+
total_sum = enablePerceptronPred ? percep_sum : total_sum;
457459

458460
bool use_sc_pred = forceUseSC; // Force use SC if configured
459-
bool use_percep_pred = false;
461+
bool use_percep_pred = enablePerceptronPred;
460462
bool percep_taken = percep_sum>=0;
461463
if (!use_sc_pred) {
462464
if (tage_info.tage_pred_conf_high) {
@@ -479,13 +481,13 @@ BTBMGSC::generateSinglePrediction(const BTBEntry &btb_entry, const Addr &startPC
479481
}
480482
}
481483
}
482-
if (abs(percep_sum) > percep_thres){
483-
use_percep_pred = true;
484-
}
484+
// if (abs(percep_sum) > percep_thres){
485+
// use_percep_pred = true;
486+
// }
485487

486488
// Final prediction, total_sum >= 0 means taken if use_sc_pred
487-
bool taken = use_sc_pred ? (use_percep_pred? percep_sum>=0 : total_sum >= 0) : tage_info.tage_pred_taken;
488-
489+
// bool taken = use_sc_pred ? (use_percep_pred? percep_sum>=0 : total_sum >= 0) : tage_info.tage_pred_taken;
490+
bool taken = use_sc_pred ? total_sum >= 0 : tage_info.tage_pred_taken;
489491
// DPRINTF(MGSC, "global tag_index: %d, global_percsum: %d, total_sum: %d\n", gIndex[0], g_percsum, total_sum);
490492
// DPRINTF(MGSC, "local tag_index: %d, local_percsum: %d, total_sum: %d\n", lIndex[0], l_percsum, total_sum);
491493
// DPRINTF(MGSC, "path tag_index: %d, path_percsum: %d, total_sum: %d\n", pIndex[0], p_percsum, total_sum);
@@ -671,7 +673,7 @@ BTBMGSC::updateWeightTable(std::vector<int16_t> &weightTable, Addr tableIndex, A
671673
}
672674

673675
/**
674-
* Update perception weight table */
676+
* Update perceptron weight table */
675677
void
676678
BTBMGSC::updatePercepTable(std::vector<std::vector<int16_t>> &weightTable, int percep_sum,bool percep_taken,
677679
Addr pc,bool actual_taken,std::vector<bool> pred_gbhr)
@@ -959,7 +961,7 @@ BTBMGSC::updateSinglePredictor(const BTBEntry &entry, bool actual_taken, const M
959961
updateWeightTable(biasWeightTable, weightTableIdx, entry.pc, pred.bias_weight_scale_diff,
960962
(pred.bias_percsum >= 0) == actual_taken);
961963

962-
//Update perception table
964+
//Update perceptron table
963965
auto pred_gbhr = pred.pred_gbhr;
964966
updatePercepTable(percepWeightTable,percep_sum,percep_taken,entry.pc,actual_taken,meta_gbhr);
965967

@@ -1552,12 +1554,12 @@ BTBMGSC::MgscStats::MgscStats(statistics::Group *parent)
15521554
ADD_STAT(predMiss, statistics::units::Count::get(), "number of sc prediction miss"),
15531555
ADD_STAT(scPredCorrect, statistics::units::Count::get(), "number of sc prediction correct"),
15541556
ADD_STAT(scPredWrong, statistics::units::Count::get(), "number of sc prediction wrong"),
1555-
ADD_STAT(percepPredCorrect, statistics::units::Count::get(), "number of perception prediction correct") ,
1556-
ADD_STAT(percepPredWrong, statistics::units::Count::get(), "number of perception prediction wrong") ,
1557-
ADD_STAT(usePercepPred, statistics::units::Count::get(), "number of mgsc use perception prediction") ,
1558-
ADD_STAT(percepHighConf,statistics::units::Count::get(), "number of perception sum above threshold"),
1557+
ADD_STAT(percepPredCorrect, statistics::units::Count::get(), "number of perceptron prediction correct") ,
1558+
ADD_STAT(percepPredWrong, statistics::units::Count::get(), "number of perceptron prediction wrong") ,
1559+
ADD_STAT(usePercepPred, statistics::units::Count::get(), "number of mgsc use perceptron prediction") ,
1560+
ADD_STAT(percepHighConf,statistics::units::Count::get(), "number of perceptron sum above threshold"),
15591561
ADD_STAT(percepHighConfCorrect,statistics::units::Count::get(),
1560-
"number of correct perception prediction above threshold"),
1562+
"number of correct perceptron prediction above threshold"),
15611563
ADD_STAT(scPredMissTaken, statistics::units::Count::get(), "number of sc prediction miss taken"),
15621564
ADD_STAT(scPredMissNotTaken, statistics::units::Count::get(), "number of sc prediction miss not taken"),
15631565
ADD_STAT(scPredCorrectTageWrong, statistics::units::Count::get(),

src/cpu/pred/btb/btb_mgsc.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class BTBMGSC : public TimedBaseBTBPredictor
381381
bool enablePTable;
382382
bool enableBiasTable;
383383
bool enablePCThreshold;
384-
bool enablePerceptionPred;
384+
bool enablePerceptronPred;
385385

386386
// Folded history for index calculation
387387
std::vector<GlobalBwFoldedHist> indexBwFoldedHist;
@@ -582,7 +582,7 @@ class BTBMGSC : public TimedBaseBTBPredictor
582582
static bool &enablePTable(BTBMGSC &mgsc) { return mgsc.enablePTable; }
583583
static bool &enableBiasTable(BTBMGSC &mgsc) { return mgsc.enableBiasTable; }
584584
static bool &enablePCThreshold(BTBMGSC &mgsc) { return mgsc.enablePCThreshold; }
585-
static bool &enablePerceptionPred(BTBMGSC &mgsc) {return mgsc.enablePerceptionPred;}
585+
static bool &enablePerceptronPred(BTBMGSC &mgsc) {return mgsc.enablePerceptronPred;}
586586

587587
static auto &bwTable(BTBMGSC &mgsc) { return mgsc.bwTable; }
588588
static auto &lTable(BTBMGSC &mgsc) { return mgsc.lTable; }

0 commit comments

Comments
 (0)