From 27557fb5037f1ba46cbc352e75ab74b742424309 Mon Sep 17 00:00:00 2001 From: "Garbowski, Mateusz" Date: Wed, 20 Sep 2023 10:04:02 +0000 Subject: [PATCH] Document StackOverflowDetection flag in a warning Inform the user about StackOverflowDetection flag that can be used to debug VLA related memory issues. --- .../PrivateMemory/PrivateMemoryResolution.cpp | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp b/IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp index 1c3edc6eab81..ffbd01204451 100644 --- a/IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp +++ b/IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp @@ -77,6 +77,7 @@ namespace IGC { unsigned int operandIndex; }; + void expandPrivateMemoryForVla(uint32_t &maxPrivateMem); static bool testTransposedMemory(const Type* pTmpType, const Type* const pTypeOfAccessedObject, uint64_t tmpAllocaSize, const uint64_t bufferSizeLimit); /// @brief The module level alloca information @@ -121,6 +122,21 @@ void PrivateMemoryResolution::getAnalysisUsage(llvm::AnalysisUsage& AU) const AU.addRequired(); } +void PrivateMemoryResolution::expandPrivateMemoryForVla(uint32_t &maxPrivateMem) +{ + // Add another 4KB if there are VLAs + maxPrivateMem += 4096; + std::string maxPrivateMemValue = std::to_string(maxPrivateMem); + std::string fullWarningMessage = "VLA has been detected, the private memory size is set to " + maxPrivateMemValue + "B. " + "You can change the size by setting flag ForcePerThreadPrivateMemorySize to a value from [1024:20480]. " + "Greater values can affect performance, and lower ones may lead to incorrect results of your program.\n" + "To make sure your program runs correctly you can set flag StackOverflowDetection to 1. " + "This flag will print \"Stack overflow detected!\" if insufficient memory value has lead to stack overflow. " + "It should be used for debugging only as it affects performance."; + + getAnalysis().getCodeGenContext()->EmitWarning(fullWarningMessage.c_str()); +} + bool PrivateMemoryResolution::runOnModule(llvm::Module& M) { // Get the analysis @@ -193,13 +209,8 @@ bool PrivateMemoryResolution::runOnModule(llvm::Module& M) if (!FGA && hasVLA) { uint32_t maxPrivateMem = funcMD->second.privateMemoryPerWI; - // Add another 4KB if there are VLAs - maxPrivateMem += 4096; - std::string maxPrivateMemValue = std::to_string(maxPrivateMem); - std::string fullWarningMessage = "VLA has been detected, the private memory size is set to " + maxPrivateMemValue + "B. You can change the size by setting flag ForcePerThreadPrivateMemorySize to a value from [1024:20480]. Greater values can affect performance, and lower ones may lead to incorrect results of your program"; + expandPrivateMemoryForVla(maxPrivateMem); - // Now, you can pass the concatenated warning message (const char*) to the EmitWarning function - getAnalysis().getCodeGenContext()->EmitWarning(fullWarningMessage.c_str()); maxPrivateMem = std::max(maxPrivateMem, Ctx.getPrivateMemoryMinimalSizePerThread()); maxPrivateMem = std::max(maxPrivateMem, (uint32_t)(IGC_GET_FLAG_VALUE(ForcePerThreadPrivateMemorySize))); modMD.PrivateMemoryPerFG[m_currFunction] = maxPrivateMem; @@ -316,13 +327,7 @@ bool PrivateMemoryResolution::runOnModule(llvm::Module& M) } if (FG->hasVariableLengthAlloca()) { - // Add another 4KB if there are VLAs - maxPrivateMem += 4096; - std::string maxPrivateMemValue = std::to_string(maxPrivateMem); - std::string fullWarningMessage = "VLA has been detected, the private memory size is set to " + maxPrivateMemValue + "B. You can change the size by setting flag ForcePerThreadPrivateMemorySize to a value from [1024:20480]. Greater values can affect performance, and lower ones may lead to incorrect results of your program"; - - // Now, you can pass the concatenated warning message (const char*) to the EmitWarning function - getAnalysis().getCodeGenContext()->EmitWarning(fullWarningMessage.c_str()); + expandPrivateMemoryForVla(maxPrivateMem); } maxPrivateMem = std::max(maxPrivateMem, Ctx.getPrivateMemoryMinimalSizePerThread()); maxPrivateMem = std::max(maxPrivateMem, (uint32_t)(IGC_GET_FLAG_VALUE(ForcePerThreadPrivateMemorySize)));