Skip to content

Commit 9aba418

Browse files
jfuentesigcbot
authored andcommitted
[Autobackout][FuncReg]Revert of change: bec1a34
Update GRF selection heuristic
1 parent f0dc49a commit 9aba418

File tree

3 files changed

+25
-57
lines changed

3 files changed

+25
-57
lines changed

visa/G4_Kernel.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,11 @@ void G4_Kernel::calculateSimdSize() {
620620
// Updates kernel's related structures to large GRF
621621
//
622622
bool G4_Kernel::updateKernelToLargerGRF() {
623-
if (numRegTotal == grfMode.getMaxGRF())
623+
if (numRegTotal == grfMode.getVRTMaxGRF())
624624
return false;
625625

626626
// Scale number of GRFs, Acc, SWSB tokens.
627-
setKernelParameters(grfMode.moveToLargerGRF());
627+
setKernelParameters(grfMode.getVRTLargerGRF());
628628
fg.builder->rebuildPhyRegPool(getNumRegTotal());
629629
return true;
630630
}
@@ -633,11 +633,11 @@ bool G4_Kernel::updateKernelToLargerGRF() {
633633
// Updates kernel's related structures to smaller GRF
634634
//
635635
bool G4_Kernel::updateKernelToSmallerGRF() {
636-
if (numRegTotal == grfMode.getMinGRF())
636+
if (numRegTotal == grfMode.getVRTMinGRF())
637637
return false;
638638

639639
// Scale number of GRFs, Acc, SWSB tokens.
640-
setKernelParameters(grfMode.moveToSmallerGRF());
640+
setKernelParameters(grfMode.getVRTSmallerGRF());
641641
fg.builder->rebuildPhyRegPool(getNumRegTotal());
642642
return true;
643643
}
@@ -653,7 +653,7 @@ void G4_Kernel::updateKernelByRegPressure(unsigned regPressure) {
653653
largestInputReg = std::max(largestInputReg, maxRegPayloadDispatch);
654654
}
655655

656-
unsigned newGRF = grfMode.setModeByRegPressure(regPressure, largestInputReg);
656+
unsigned newGRF = grfMode.findModeByRegPressure(regPressure, largestInputReg);
657657

658658
if (newGRF == numRegTotal)
659659
return;
@@ -2084,27 +2084,25 @@ GRFMode::GRFMode(const TARGET_PLATFORM platform, Options *op) : options(op) {
20842084
currentMode = defaultMode;
20852085
}
20862086

2087-
unsigned GRFMode::setModeByRegPressure(unsigned maxRP, unsigned largestInputReg) {
2088-
unsigned size = configs.size(), i = 0;
2087+
unsigned GRFMode::findModeByRegPressure(unsigned maxRP, unsigned largestInputReg) {
2088+
unsigned size = configs.size();
2089+
unsigned i = 0, newGRF = 0;
20892090
// find appropiate GRF based on reg pressure
20902091
for (; i < size; i++) {
20912092
if (configs[i].VRTEnable && maxRP <= configs[i].numGRF &&
20922093
// Check that we've at least 8 GRFs over and above
20932094
// those blocked for kernel input. This helps cases
20942095
// where an 8 GRF variable shows up in entry BB.
20952096
(largestInputReg + 8) <= configs[i].numGRF) {
2096-
currentMode = i;
2097+
newGRF = configs[i].numGRF;
20972098
break;
20982099
}
20992100
}
2100-
return configs[currentMode].numGRF;
2101-
}
21022101

2103-
// Check if next larger GRF has the same number of threads per EU
2104-
bool GRFMode::hasLargerGRFSameThreads() const {
2105-
unsigned largerGrfIdx = currentMode + 1;
2106-
if (largerGrfIdx == configs.size() || !configs[largerGrfIdx].VRTEnable)
2107-
return false;
2102+
// if not found, pressure is too high
2103+
// set largest grf mode
2104+
if (i == size)
2105+
newGRF = getVRTMaxGRF();
21082106

2109-
return configs[currentMode].numThreads == configs[largerGrfIdx].numThreads;
2107+
return newGRF;
21102108
}

visa/G4_Kernel.hpp

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ class GRFMode {
148148
return iter != configs.end();
149149
}
150150

151-
unsigned setModeByRegPressure(unsigned maxRP, unsigned largestInputReg);
152-
bool hasLargerGRFSameThreads() const;
151+
unsigned findModeByRegPressure(unsigned maxRP, unsigned largestInputReg);
153152

154153
unsigned getNumGRF() const { return configs[currentMode].numGRF; }
155154
unsigned getDefaultGRF() const { return configs[defaultMode].numGRF; }
@@ -171,20 +170,19 @@ class GRFMode {
171170
unsigned getNumAcc() const { return configs[currentMode].numAcc; }
172171

173172
// ----- helper functions for autoGRFSelection (VRT) ----- //
174-
unsigned getMinGRF() const {
173+
unsigned getVRTMinGRF() const {
175174
auto found = std::find_if(configs.begin(), configs.end(),
176175
[](const Config &c) { return c.VRTEnable; });
177176
return found->numGRF;
178177
}
179178

180-
unsigned getMaxGRF() const {
179+
unsigned getVRTMaxGRF() const {
181180
auto found = std::find_if(configs.rbegin(), configs.rend(),
182181
[](const Config &c) { return c.VRTEnable; });
183182
return found->numGRF;
184183
}
185184

186-
// Get the next larger GRF available
187-
unsigned getLargerGRF() const {
185+
unsigned getVRTLargerGRF() const {
188186
// find the first larger mode that's available for VRT
189187
for (auto i = currentMode + 1; i < configs.size(); ++i) {
190188
if (configs[i].VRTEnable)
@@ -193,37 +191,14 @@ class GRFMode {
193191
return configs[currentMode].numGRF;
194192
}
195193

196-
// Get the next smaller GRF available
197-
unsigned getSmallerGRF() const {
194+
unsigned getVRTSmallerGRF() const {
198195
for (auto i = static_cast<int>(currentMode) - 1; i >= 0 ; --i) {
199196
if (configs[i].VRTEnable)
200197
return configs[i].numGRF;
201198
}
202199
return configs[currentMode].numGRF;
203200
}
204201

205-
// Move GRF mode to the larger GRF available and return the number
206-
unsigned moveToLargerGRF() {
207-
for (auto i = currentMode + 1; i < configs.size(); ++i) {
208-
if (configs[i].VRTEnable) {
209-
currentMode = i;
210-
break;
211-
}
212-
}
213-
return configs[currentMode].numGRF;
214-
}
215-
216-
// Move GRF mode to the smaller GRF available and return the number
217-
unsigned moveToSmallerGRF() {
218-
for (auto i = currentMode - 1; i >= 0; --i) {
219-
if (configs[i].VRTEnable) {
220-
currentMode = i;
221-
break;
222-
}
223-
}
224-
return configs[currentMode].numGRF;
225-
}
226-
227202
private:
228203
// Parameters associated to a GRF mode
229204
struct Config {

visa/LocalScheduler/G4_Sched.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -715,24 +715,19 @@ bool preRA_Scheduler::runWithGRFSelection(unsigned &KernelPressure) {
715715
unsigned BBRP = rp.getPressure(bb);
716716

717717
unsigned UpperBoundGRF = 0;
718-
if (GRFdecreased && KernelPressure < kernel.grfMode.getMaxGRF())
719-
UpperBoundGRF = kernel.grfMode.getLargerGRF();
718+
if (GRFdecreased && KernelPressure < kernel.grfMode.getVRTMaxGRF())
719+
UpperBoundGRF = kernel.grfMode.getVRTLargerGRF();
720720
Changed |= S.scheduleBlockForLatency(BBRP, Changed, UpperBoundGRF);
721721
}
722722

723723
if (Changed) {
724724
rp.recompute();
725725
KernelPressure = rp.getMaxRP();
726726
}
727-
728-
unsigned ExtraRegs = 0;
729-
if (kernel.grfMode.hasLargerGRFSameThreads()) {
730-
// In RA extra registers might be needed to satisfy some restrictions,
731-
// e.g. alignment, SIMD size, etc. So in order to avoid spill in GRF
732-
// modes smaller than default, extra registers are added to reg pressure.
733-
ExtraRegs =
734-
(unsigned)(kernel.getNumRegTotal() * EXTRA_REGISTERS_FOR_RA / 100.0f);
735-
}
727+
// In RA extra registers might be needed to satisfy
728+
// some restrictions, e.g. alignment, SIMD size, etc.
729+
// So extra registers are provided.
730+
unsigned ExtraRegs = (unsigned)(kernel.getNumRegTotal() * EXTRA_REGISTERS_FOR_RA / 100.0f);
736731
kernel.updateKernelByRegPressure(KernelPressure + ExtraRegs);
737732

738733
return Changed;

0 commit comments

Comments
 (0)