Skip to content

Commit a8c625e

Browse files
dlei6gigcbot
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.
1 parent f8be115 commit a8c625e

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
@@ -6205,8 +6205,7 @@ namespace IGC
62056205
context->SetSIMDInfo(SIMD_SKIP_SPILL, m_program->m_dispatchSize, m_program->m_ShaderDispatchMode);
62066206
// Set spill size despite VISA terminates with VISA_SPILL error code.
62076207
// This member is checked later for OOB scratch.
6208-
m_program->ProgramOutput()->m_scratchSpaceUsedBySpills =
6209-
jitInfo->stats.spillMemUsed;
6208+
m_program->ProgramOutput()->m_scratchSpaceUsedBySpills = jitInfo->stats.spillMemUsed;
62106209
return;
62116210
}
62126211

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

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

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

@@ -3638,33 +3638,29 @@ namespace IGC
36383638
}
36393639
}
36403640

3641-
static void verifyOOBScratch(OpenCLProgramContext *ctx,
3641+
static bool verifyHasOOBScratch(OpenCLProgramContext *ctx,
36423642
COpenCLKernel *simd8Shader,
36433643
COpenCLKernel *simd16Shader,
36443644
COpenCLKernel *simd32Shader) {
36453645
auto verify = [ctx](CShader *shader) {
36463646
if (exceedMaxScratchUse(shader, ctx)) {
3647-
std::string errorMsg =
3648-
"total scratch space exceeds HW "
3649-
"supported limit for kernel " +
3650-
shader->entry->getName().str() + ": " +
3651-
std::to_string(getScratchUse(shader, ctx)) + " bytes (max permitted PTSS " +
3652-
std::to_string(shader->ProgramOutput()->m_scratchSpaceSizeLimit) +
3653-
" bytes)";
3654-
3655-
ctx->EmitError(errorMsg.c_str(), nullptr);
3647+
return true;
36563648
}
3649+
return false;
36573650
};
36583651

36593652
// Need to check if simd* shader is not nullptr and its vISA compile status,
36603653
// since it may be created without going through full vISA compilation and
36613654
// the spill size record may be invalid
3655+
bool result = false;
36623656
if (simd8Shader && !COpenCLKernel::IsVisaCompileStatusFailureForShader(simd8Shader))
3663-
verify(simd8Shader);
3657+
result |= verify(simd8Shader);
36643658
else if (simd16Shader && !COpenCLKernel::IsVisaCompileStatusFailureForShader(simd16Shader))
3665-
verify(simd16Shader);
3659+
result |= verify(simd16Shader);
36663660
else if (simd32Shader && !COpenCLKernel::IsVisaCompileStatusFailureForShader(simd32Shader))
3667-
verify(simd32Shader);
3661+
result |= verify(simd32Shader);
3662+
3663+
return result;
36683664
}
36693665

36703666
static void CodeGen(OpenCLProgramContext* ctx, CShaderProgram::KernelShaderMap& shaders)
@@ -3881,9 +3877,36 @@ namespace IGC
38813877
GatherDataForDriver(ctx, simd16Shader, std::move(pKernel), pFunc, pMdUtils, SIMDMode::SIMD16);
38823878
else if (COpenCLKernel::IsValidShader(simd8Shader))
38833879
GatherDataForDriver(ctx, simd8Shader, std::move(pKernel), pFunc, pMdUtils, SIMDMode::SIMD8);
3884-
else
3885-
// Verify if compilation failed due to OOB scratch
3886-
verifyOOBScratch(ctx, simd8Shader, simd16Shader, simd32Shader);
3880+
else if (verifyHasOOBScratch(ctx, simd8Shader, simd16Shader, simd32Shader))
3881+
{
3882+
// Get the simd* shader with the OOB access.
3883+
COpenCLKernel* shader =
3884+
exceedMaxScratchUse(simd32Shader, ctx) ? simd32Shader :
3885+
exceedMaxScratchUse(simd16Shader, ctx) ? simd16Shader :
3886+
exceedMaxScratchUse(simd8Shader, ctx) ? simd8Shader :
3887+
nullptr;
3888+
3889+
IGC_ASSERT(shader);
3890+
3891+
if (!ctx->m_retryManager.IsLastTry())
3892+
{
3893+
// If this is not the last try, force retry on this kernel to potentially avoid
3894+
// OOB access on the next try by reducing spill size and thus SS usage.
3895+
ctx->m_retryManager.kernelSet.insert(shader->entry->getName().str());
3896+
}
3897+
else
3898+
{
3899+
std::string errorMsg =
3900+
"total scratch space exceeds HW "
3901+
"supported limit for kernel " +
3902+
shader->entry->getName().str() + ": " +
3903+
std::to_string(getScratchUse(shader, ctx)) + " bytes (max permitted PTSS " +
3904+
std::to_string(shader->ProgramOutput()->m_scratchSpaceSizeLimit) +
3905+
" bytes)";
3906+
3907+
ctx->EmitError(errorMsg.c_str(), nullptr);
3908+
}
3909+
}
38873910
}
38883911
}
38893912

visa/RegAlloc.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3101,7 +3101,6 @@ int regAlloc(IR_Builder &builder, PhyRegPool &regPool, G4_Kernel &kernel) {
31013101
builder.criticalMsgStream()
31023102
<< "Total scratch size used by shader exceeds platform capability: "
31033103
<< totalScratchUsed << "\n";
3104-
vISA_ASSERT(false, "spill size exceeds platform capability");
31053104
return VISA_SPILL;
31063105
}
31073106
}

0 commit comments

Comments
 (0)