Skip to content

Commit 6a8c073

Browse files
dlei6gpszymich
authored andcommitted
Abort when Scratch Space size exceeds HW limit on last retry attempt only
When Scratch Space size exceeds HW limit, we also need to check if the current compilation is the final retry attempt. On retry, we may end up reducing spills and consequently SS usage such that the HW limit is not hit. Only abort compilation if the final try still has SS exceeding the HW limit. (cherry picked from commit a8c625e)
1 parent 8acfa43 commit 6a8c073

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6178,8 +6178,7 @@ namespace IGC
61786178
context->SetSIMDInfo(SIMD_SKIP_SPILL, m_program->m_dispatchSize, m_program->m_ShaderDispatchMode);
61796179
// Set spill size despite VISA terminates with VISA_SPILL error code.
61806180
// This member is checked later for OOB scratch.
6181-
m_program->ProgramOutput()->m_scratchSpaceUsedBySpills =
6182-
jitInfo->stats.spillMemUsed;
6181+
m_program->ProgramOutput()->m_scratchSpaceUsedBySpills = jitInfo->stats.spillMemUsed;
61836182
return;
61846183
}
61856184

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,7 +3455,7 @@ namespace IGC
34553455

34563456
static bool exceedMaxScratchUse(CShader* shader, OpenCLProgramContext* ctx)
34573457
{
3458-
return getScratchUse(shader, ctx) >
3458+
return shader && getScratchUse(shader, ctx) >
34593459
shader->ProgramOutput()->m_scratchSpaceSizeLimit;
34603460
}
34613461

@@ -3592,33 +3592,29 @@ namespace IGC
35923592
}
35933593
}
35943594

3595-
static void verifyOOBScratch(OpenCLProgramContext *ctx,
3595+
static bool verifyHasOOBScratch(OpenCLProgramContext *ctx,
35963596
COpenCLKernel *simd8Shader,
35973597
COpenCLKernel *simd16Shader,
35983598
COpenCLKernel *simd32Shader) {
35993599
auto verify = [ctx](CShader *shader) {
36003600
if (exceedMaxScratchUse(shader, ctx)) {
3601-
std::string errorMsg =
3602-
"total scratch space exceeds HW "
3603-
"supported limit for kernel " +
3604-
shader->entry->getName().str() + ": " +
3605-
std::to_string(getScratchUse(shader, ctx)) + " bytes (max permitted PTSS " +
3606-
std::to_string(shader->ProgramOutput()->m_scratchSpaceSizeLimit) +
3607-
" bytes)";
3608-
3609-
ctx->EmitError(errorMsg.c_str(), nullptr);
3601+
return true;
36103602
}
3603+
return false;
36113604
};
36123605

36133606
// Need to check if simd* shader is not nullptr and its vISA compile status,
36143607
// since it may be created without going through full vISA compilation and
36153608
// the spill size record may be invalid
3609+
bool result = false;
36163610
if (simd8Shader && !COpenCLKernel::IsVisaCompileStatusFailureForShader(simd8Shader))
3617-
verify(simd8Shader);
3611+
result |= verify(simd8Shader);
36183612
else if (simd16Shader && !COpenCLKernel::IsVisaCompileStatusFailureForShader(simd16Shader))
3619-
verify(simd16Shader);
3613+
result |= verify(simd16Shader);
36203614
else if (simd32Shader && !COpenCLKernel::IsVisaCompileStatusFailureForShader(simd32Shader))
3621-
verify(simd32Shader);
3615+
result |= verify(simd32Shader);
3616+
3617+
return result;
36223618
}
36233619

36243620
static void CodeGen(OpenCLProgramContext* ctx, CShaderProgram::KernelShaderMap& shaders)
@@ -3835,9 +3831,36 @@ namespace IGC
38353831
GatherDataForDriver(ctx, simd16Shader, std::move(pKernel), pFunc, pMdUtils, SIMDMode::SIMD16);
38363832
else if (COpenCLKernel::IsValidShader(simd8Shader))
38373833
GatherDataForDriver(ctx, simd8Shader, std::move(pKernel), pFunc, pMdUtils, SIMDMode::SIMD8);
3838-
else
3839-
// Verify if compilation failed due to OOB scratch
3840-
verifyOOBScratch(ctx, simd8Shader, simd16Shader, simd32Shader);
3834+
else if (verifyHasOOBScratch(ctx, simd8Shader, simd16Shader, simd32Shader))
3835+
{
3836+
// Get the simd* shader with the OOB access.
3837+
COpenCLKernel* shader =
3838+
exceedMaxScratchUse(simd32Shader, ctx) ? simd32Shader :
3839+
exceedMaxScratchUse(simd16Shader, ctx) ? simd16Shader :
3840+
exceedMaxScratchUse(simd8Shader, ctx) ? simd8Shader :
3841+
nullptr;
3842+
3843+
IGC_ASSERT(shader);
3844+
3845+
if (!ctx->m_retryManager.IsLastTry())
3846+
{
3847+
// If this is not the last try, force retry on this kernel to potentially avoid
3848+
// OOB access on the next try by reducing spill size and thus SS usage.
3849+
ctx->m_retryManager.kernelSet.insert(shader->entry->getName().str());
3850+
}
3851+
else
3852+
{
3853+
std::string errorMsg =
3854+
"total scratch space exceeds HW "
3855+
"supported limit for kernel " +
3856+
shader->entry->getName().str() + ": " +
3857+
std::to_string(getScratchUse(shader, ctx)) + " bytes (max permitted PTSS " +
3858+
std::to_string(shader->ProgramOutput()->m_scratchSpaceSizeLimit) +
3859+
" bytes)";
3860+
3861+
ctx->EmitError(errorMsg.c_str(), nullptr);
3862+
}
3863+
}
38413864
}
38423865
}
38433866

visa/RegAlloc.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3120,7 +3120,6 @@ int regAlloc(IR_Builder &builder, PhyRegPool &regPool, G4_Kernel &kernel) {
31203120
builder.criticalMsgStream()
31213121
<< "Total scratch size used by shader exceeds platform capability: "
31223122
<< totalScratchUsed << "\n";
3123-
vISA_ASSERT(false, "spill size exceeds platform capability");
31243123
return VISA_SPILL;
31253124
}
31263125
}

0 commit comments

Comments
 (0)