Skip to content

Commit

Permalink
Change the spill compression threshold to 32k
Browse files Browse the repository at this point in the history
Change the spill compression threshold to 32k
  • Loading branch information
bcheng0127 authored and igcbot committed Oct 11, 2023
1 parent 843a4d2 commit 130538c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
46 changes: 30 additions & 16 deletions visa/GraphColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ using namespace vISA;

#define GRAPH_COLOR_MEM_SIZE 16 * 1024
#define SCRATCH_MSG_LIMIT (128 * 1024)
#define SCRATCH_COMPRESS_THRESHOLD (32 * 1024)

const RAVarInfo GlobalRA::defaultValues;
const char GlobalRA::StackCallStr[] = "StackCall";
Expand Down Expand Up @@ -9580,22 +9581,31 @@ GlobalRA::abortOnSpill(unsigned int GRFSpillFillCount,
return std::make_pair(false, GRFSpillFillCount);
}

bool GlobalRA::spillSpaceCompression(bool enableSpillSpaceCompression,
GraphColor &coloring, bool hasStackCall,
unsigned GlobalRA::computeSpillSize(std::list<LSLiveRange *> &spilledLRs) {
unsigned spillSize = 0;
for (auto lr : spilledLRs) {
spillSize += lr->getTopDcl()->getByteSize();
}
return spillSize;
}

unsigned GlobalRA::computeSpillSize(const LIVERANGE_LIST &spilledLRs) {
unsigned spillSize = 0;
for (auto lr : spilledLRs) {
spillSize += lr->getDcl()->getByteSize();
}
return spillSize;
}

bool GlobalRA::spillSpaceCompression(int spillSize,
const int globalScratchOffset) {
if (getIterNo() == 0 && enableSpillSpaceCompression &&
kernel.getInt32KernelAttr(Attributes::ATTR_Target) == VISA_3D &&
!hasStackCall) {
unsigned spillSize = 0;
const LIVERANGE_LIST &spilledLRs = coloring.getSpilledLiveRanges();
for (auto lr : spilledLRs) {
spillSize += lr->getDcl()->getByteSize();
}
if ((int)(spillSize * 1.5) < (SCRATCH_MSG_LIMIT - globalScratchOffset)) {
return false;
}
// factor 1.2 is used to count in the space used for the following
// iterations. Generally, the most spill will happen in first iteration.
if ((spillSize * 1.2) <
((int)SCRATCH_COMPRESS_THRESHOLD - globalScratchOffset)) {
return false;
}
return enableSpillSpaceCompression;
return true;
}

void GlobalRA::verifyNoInfCostSpill(GraphColor& coloring, bool reserveSpillReg)
Expand Down Expand Up @@ -9667,8 +9677,12 @@ GlobalRA::insertSpillCode(bool enableSpillSpaceCompression,
bool reserveSpillReg, unsigned int spillRegSize,
unsigned int indrSpillRegSize,
bool useScratchMsgForSpill) {
enableSpillSpaceCompression = spillSpaceCompression(
enableSpillSpaceCompression, coloring, hasStackCall, globalScratchOffset);
if (getIterNo() == 0 && enableSpillSpaceCompression &&
kernel.getInt32KernelAttr(Attributes::ATTR_Target) == VISA_3D &&
!hasStackCall) {
enableSpillSpaceCompression = spillSpaceCompression(
computeSpillSize(coloring.getSpilledLiveRanges()), globalScratchOffset);
}

startTimer(TimerID::SPILL);
SpillManagerGRF spillGRF(*this, nextSpillOffset, &liveAnalysis,
Expand Down
8 changes: 5 additions & 3 deletions visa/GraphColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,11 @@ class GlobalRA {
return iter != bbLocalRAMap.end() ? iter->second : nullptr;
}

unsigned computeSpillSize(const LIVERANGE_LIST &spilledLRs);
unsigned computeSpillSize(std::list<LSLiveRange *> &spilledLRs);
bool spillSpaceCompression(int spillSize,
const int globalScratchOffset);

public:
// Store new variables created when inserting scalar imm
// spill/fill code. Such variables are not infinite spill
Expand Down Expand Up @@ -1789,9 +1794,6 @@ class GlobalRA {
// pair of abort, updated GRFSpillFillCount
std::pair<bool, unsigned int> abortOnSpill(unsigned int GRFSpillFillCount,
GraphColor &coloring);
bool spillSpaceCompression(bool enableSpillSpaceCompression,
GraphColor &coloring, bool hasStackCall,
const int globalScratchOffset);
void verifyNoInfCostSpill(GraphColor &coloring, bool reserveSpillReg);
void setupA0Dot2OnSpill(bool hasStackCall, unsigned int nextSpillOffset,
int globalScratchOffset);
Expand Down
11 changes: 3 additions & 8 deletions visa/LinearScanRA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,14 +914,9 @@ int LinearScanRA::linearScanRA() {
if (spillLRs.size()) {
if (iterator == 0 && enableSpillSpaceCompression &&
kernel.getInt32KernelAttr(Attributes::ATTR_Target) == VISA_3D &&
!(kernel.fg.getHasStackCalls() || kernel.fg.getIsStackCallFunc())) {
unsigned int spillSize = 0;
for (auto lr : spillLRs) {
spillSize += lr->getTopDcl()->getByteSize();
}
if ((spillSize * 1.5) < (SCRATCH_MSG_LIMIT - nextSpillOffset)) {
enableSpillSpaceCompression = false;
}
!hasStackCall) {
enableSpillSpaceCompression = gra.spillSpaceCompression(
gra.computeSpillSize(spillLRs), nextSpillOffset);
}

SpillManagerGRF spillGRF(gra, nextSpillOffset, &l, &spillLRs,
Expand Down

0 comments on commit 130538c

Please sign in to comment.