Skip to content

Commit 4cc6e5e

Browse files
dlei6gsys_zuul
authored andcommitted
Vary private memory stack size based on SIMD width:
SIMD8: 8k per lane SIMD16: 4k per lane SIMD32: 2k per lane Change-Id: I7d4034437b1bb4ce2a6776d55817d29c0f274886
1 parent c0efd8e commit 4cc6e5e

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

IGC/Compiler/CISACodeGen/CShader.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ CVariable* CShader::CreateSP()
248248
return m_SP;
249249
}
250250

251+
/// get max private mem size, varying by simd width
252+
uint32_t CShader::GetMaxPrivateMem()
253+
{
254+
uint32_t MaxPrivateSize = 0;
255+
switch (m_dispatchSize) {
256+
default:
257+
MaxPrivateSize = 8 * 1024;
258+
break;
259+
case SIMDMode::SIMD16:
260+
MaxPrivateSize = 4 * 1024;
261+
break;
262+
case SIMDMode::SIMD32:
263+
MaxPrivateSize = 2 * 1024;
264+
break;
265+
}
266+
return MaxPrivateSize;
267+
}
268+
251269
/// initial stack-pointer at the beginning of the kernel
252270
void CShader::InitKernelStack(CVariable*& stackBase, CVariable*& stackAllocSize)
253271
{
@@ -281,7 +299,7 @@ void CShader::InitKernelStack(CVariable*& stackBase, CVariable*& stackAllocSize)
281299
// Maximun private size in byte, per-workitem
282300
// When there's stack call, we don't know the actual stack size being used,
283301
// so set a conservative max stack size.
284-
const uint32_t MaxPrivateSize = 1024;
302+
uint32_t MaxPrivateSize = GetMaxPrivateMem();
285303
if (IGC_IS_FLAG_ENABLED(EnableRuntimeFuncAttributePatching))
286304
{
287305
// Experimental: Patch private memory size
@@ -311,6 +329,12 @@ void CShader::InitKernelStack(CVariable*& stackBase, CVariable*& stackAllocSize)
311329

312330
// Set the total alloca size for the entry function
313331
encoder.SetFunctionAllocaStackSize(entry, totalAllocaSize);
332+
333+
if ((uint32_t)funcMDItr->second.privateMemoryPerWI > MaxPrivateSize)
334+
{
335+
GetContext()->EmitError("Private memory allocation exceeds max allowed size");
336+
IGC_ASSERT(0);
337+
}
314338
}
315339
}
316340

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9938,6 +9938,12 @@ void EmitPass::emitStackFuncEntry(Function* F)
99389938

99399939
// Set the per-function private mem size
99409940
m_encoder->SetFunctionAllocaStackSize(F, totalAllocaSize);
9941+
9942+
if ((uint32_t)funcMDItr->second.privateMemoryPerWI > m_currShader->GetMaxPrivateMem())
9943+
{
9944+
m_currShader->GetContext()->EmitError("Private memory allocation exceeds max allowed size");
9945+
IGC_ASSERT(0);
9946+
}
99419947
}
99429948
}
99439949
}

IGC/Compiler/CISACodeGen/ShaderCodeGen.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ namespace IGC
197197
void SaveSP();
198198
/// restore the stack-pointer when exiting a stack-call function
199199
void RestoreSP();
200+
/// Get the max private mem size based on simd width
201+
uint32_t GetMaxPrivateMem();
200202

201203
void AllocateInput(CVariable* var, uint offset, uint instance = 0);
202204
void AllocateOutput(CVariable* var, uint offset, uint instance = 0);

0 commit comments

Comments
 (0)