Commit 7d89fb39 authored by Rishipal Singh Bhatia's avatar Rishipal Singh Bhatia Committed by Alex

Moving the variable PrivateMemoryPerWI to the new metadata

framework.. Already an existing metadata variable present in
module metadata seems. redundant. We need this info in the
function metadata, hence placing it. there in the new framework.
The module level variable can be cleaned up later.

Change-Id: I822710a37b1cd86608107d05aeb8a49bbb61a3a1
parent ac157e7f
......@@ -118,14 +118,19 @@ void CShader::InitEncoder(SIMDMode simdSize, bool canAbortOnSpill, ShaderDispatc
void CShader::PreAnalysisPass()
{
ExtractGlobalVariables();
FunctionInfoMetaDataHandle funcInfoMD = m_pMdUtils->getFunctionsInfoItem(entry);
if (funcInfoMD->isPrivateMemoryPerWIHasValue()) {
if (GetContext()->getModuleMetaData()->compOpt.UseScratchSpacePrivateMemory) {
m_ScratchSpaceSize = funcInfoMD->getPrivateMemoryPerWI() * numLanes(m_dispatchSize);
// Round up to GENX_GRF_REG_SIZ-byte aligned.
m_ScratchSpaceSize =
((GENX_GRF_REG_SIZ + m_ScratchSpaceSize - 1) / GENX_GRF_REG_SIZ) * GENX_GRF_REG_SIZ;
auto funcMDItr = m_ModuleMetadata->FuncMD.find(entry);
if (funcMDItr != m_ModuleMetadata->FuncMD.end())
{
if (funcMDItr->second.privateMemoryPerWI != 0)
{
if (GetContext()->getModuleMetaData()->compOpt.UseScratchSpacePrivateMemory)
{
m_ScratchSpaceSize = funcMDItr->second.privateMemoryPerWI * numLanes(m_dispatchSize);
// Round up to GENX_GRF_REG_SIZ-byte aligned.
m_ScratchSpaceSize =
((GENX_GRF_REG_SIZ + m_ScratchSpaceSize - 1) / GENX_GRF_REG_SIZ) * GENX_GRF_REG_SIZ;
}
}
}
......@@ -273,17 +278,21 @@ void CShader::InitKernelStack(bool ptr64bits)
CVariable* pTemp = GetNewVariable(1, ISA_TYPE_UD, EALIGN_DWORD, true, 1);
encoder.Mul(pTemp, pHWTID, pSize);
encoder.Push();
FunctionInfoMetaDataHandle funcInfoMD = m_pMdUtils->getFunctionsInfoItem(entry);
// reserve space for alloca
if (funcInfoMD->isPrivateMemoryPerWIHasValue()) {
if (funcInfoMD->getPrivateMemoryPerWI()) {
unsigned totalAllocaSize = funcInfoMD->getPrivateMemoryPerWI() * numLanes(m_dispatchSize);
auto funcMDItr = m_ModuleMetadata->FuncMD.find(entry);
if (funcMDItr != m_ModuleMetadata->FuncMD.end())
{
if (funcMDItr->second.privateMemoryPerWI != 0)
{
unsigned totalAllocaSize = funcMDItr->second.privateMemoryPerWI * numLanes(m_dispatchSize);
encoder.Add(pTemp, pTemp, ImmToVariable(totalAllocaSize, ISA_TYPE_UD));
encoder.Push();
}
}
// modify private-memory size to a large setting
funcInfoMD->setPrivateMemoryPerWI(8192);
m_ModuleMetadata->FuncMD[entry].privateMemoryPerWI = 8192;
CVariable* pBase = GetSymbol(kerArg);
encoder.Add(m_SP, pBase, pTemp);
encoder.Push();
......
......@@ -8761,14 +8761,14 @@ void EmitPass::emitStackFuncEntry(Function *F, bool ptr64bits)
// save SP before allocation
m_currShader->SaveSP();
FunctionInfoMetaDataHandle funcInfoMD = m_currShader->GetMetaDataUtils()->getFunctionsInfoItem(F);
// reserve space for all the alloca in the function subgroup
if (funcInfoMD->isPrivateMemoryPerWIHasValue())
auto funcMDItr = m_currShader->m_ModuleMetadata->FuncMD.find(F);
if (funcMDItr != m_currShader->m_ModuleMetadata->FuncMD.end())
{
if (funcInfoMD->getPrivateMemoryPerWI())
if (funcMDItr->second.privateMemoryPerWI != 0)
{
CVariable *pSP = m_currShader->GetSP();
unsigned totalAllocaSize = funcInfoMD->getPrivateMemoryPerWI() * numLanes(m_currShader->m_dispatchSize);
unsigned totalAllocaSize = funcMDItr->second.privateMemoryPerWI * numLanes(m_currShader->m_dispatchSize);
m_encoder->Add(pSP, pSP, m_currShader->ImmToVariable(totalAllocaSize, ISA_TYPE_UD));
m_encoder->Push();
}
......
......@@ -1393,11 +1393,10 @@ void COpenCLKernel::AllocatePayload()
// Set the amount of the private memory used by the kernel
// Set only if the private memory metadata actually exists and we don't use
// scratch space for private memory.
FunctionInfoMetaDataHandle funcInfoMD = m_pMdUtils->getFunctionsInfoItem(entry);
bool noScratchSpacePrivMem = !m_Context->getModuleMetaData()->compOpt.UseScratchSpacePrivateMemory;
if (noScratchSpacePrivMem && funcInfoMD->isPrivateMemoryPerWIHasValue())
if (noScratchSpacePrivMem && m_Context->getModuleMetaData()->privateMemoryPerWI)
{
m_perWIPrivateMemSize = funcInfoMD->getPrivateMemoryPerWI();
m_perWIPrivateMemSize = m_Context->getModuleMetaData()->privateMemoryPerWI;
}
m_ConstantBufferLength = 0;
......
......@@ -2245,7 +2245,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const llvm::MDNode* pNode, bool hasId
m_GlobalOffsetPresent(getGlobalOffsetPresentNode(pNode)),
m_LocalOffsets(getLocalOffsetsNode(pNode), true),
m_ResourceAlloc(ResourceAllocMetaData::get(getResourceAllocNode(pNode), true)),
m_PrivateMemoryPerWI(getPrivateMemoryPerWINode(pNode)),
m_OpenCLVectorTypeHint(VectorTypeHintMetaData::get(getOpenCLVectorTypeHintNode(pNode), true)),
m_OpenCLArgAddressSpaces(getOpenCLArgAddressSpacesNode(pNode), true),
m_BufferLocationIndex(getBufferLocationIndexNode(pNode), true),
......@@ -2271,7 +2270,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(): m_Type("function_type"),
m_GlobalOffsetPresent("global_offset_present"),
m_LocalOffsets("local_offsets"),
m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")),
m_PrivateMemoryPerWI("private_memory_per_wi"),
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")),
m_OpenCLArgAddressSpaces("opencl_kernel_arg_addr_space"),
m_BufferLocationIndex("buffer_location_index"),
......@@ -2299,7 +2297,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const char* name):
m_GlobalOffsetPresent("global_offset_present"),
m_LocalOffsets("local_offsets"),
m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")),
m_PrivateMemoryPerWI("private_memory_per_wi"),
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")),
m_OpenCLArgAddressSpaces("opencl_kernel_arg_addr_space"),
m_BufferLocationIndex("buffer_location_index"),
......@@ -2372,14 +2369,7 @@ bool FunctionInfoMetaData::hasValue() const
{
return true;
}
if (m_PrivateMemoryPerWI.hasValue())
{
return true;
}
if (m_OpenCLVectorTypeHint->hasValue())
{
return true;
......@@ -2478,11 +2468,7 @@ bool FunctionInfoMetaData::dirty() const
if( m_ResourceAlloc.dirty() )
{
return true;
}
if( m_PrivateMemoryPerWI.dirty() )
{
return true;
}
}
if( m_OpenCLVectorTypeHint.dirty() )
{
return true;
......@@ -2536,7 +2522,6 @@ void FunctionInfoMetaData::discardChanges()
m_GlobalOffsetPresent.discardChanges();
m_LocalOffsets.discardChanges();
m_ResourceAlloc.discardChanges();
m_PrivateMemoryPerWI.discardChanges();
m_OpenCLVectorTypeHint.discardChanges();
m_OpenCLArgAddressSpaces.discardChanges();
m_BufferLocationIndex.discardChanges();
......@@ -2607,11 +2592,6 @@ llvm::Metadata* FunctionInfoMetaData::generateNode(llvm::LLVMContext& context) c
args.push_back(m_ResourceAlloc.generateNode(context));
}
if (isPrivateMemoryPerWIHasValue())
{
args.push_back(m_PrivateMemoryPerWI.generateNode(context));
}
if (m_OpenCLVectorTypeHint->hasValue())
{
args.push_back(m_OpenCLVectorTypeHint.generateNode(context));
......@@ -2695,7 +2675,6 @@ void FunctionInfoMetaData::save(llvm::LLVMContext& context, llvm::MDNode* pNode)
m_GlobalOffsetPresent.save(context, llvm::cast<llvm::MDNode>(getGlobalOffsetPresentNode(pNode)));
m_LocalOffsets.save(context, llvm::cast<llvm::MDNode>(getLocalOffsetsNode(pNode)));
m_ResourceAlloc.save(context, llvm::cast<llvm::MDNode>(getResourceAllocNode(pNode)));
m_PrivateMemoryPerWI.save(context, llvm::cast<llvm::MDNode>(getPrivateMemoryPerWINode(pNode)));
m_OpenCLVectorTypeHint.save(context, llvm::cast<llvm::MDNode>(getOpenCLVectorTypeHintNode(pNode)));
m_OpenCLArgAddressSpaces.save(context, llvm::cast<llvm::MDNode>(getOpenCLArgAddressSpacesNode(pNode)));
m_BufferLocationIndex.save(context, llvm::cast<llvm::MDNode>(getBufferLocationIndexNode(pNode)));
......@@ -2906,24 +2885,6 @@ llvm::MDNode* FunctionInfoMetaData::getResourceAllocNode( const llvm::MDNode* pP
return NULL;
}
llvm::Metadata* FunctionInfoMetaData::getPrivateMemoryPerWINode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
{
return NULL;
}
unsigned int offset = _Mybase::getStartIndex();
for(NodeIterator i = NodeIterator(pParentNode, 0+offset), e = NodeIterator(pParentNode); i != e; ++i )
{
if( isNamedNode(i.get(), "private_memory_per_wi") )
{
return i.get();
}
}
return NULL;
}
llvm::MDNode* FunctionInfoMetaData::getOpenCLVectorTypeHintNode( const llvm::MDNode* pParentNode) const
{
if( !pParentNode )
......
......@@ -2236,23 +2236,7 @@ public:
{
return m_ResourceAlloc;
}
/// PrivateMemoryPerWI related methods
PrivateMemoryPerWIType getPrivateMemoryPerWI() const
{
return m_PrivateMemoryPerWI.get();
}
void setPrivateMemoryPerWI( const PrivateMemoryPerWIType& val)
{
m_PrivateMemoryPerWI.set(val);
}
bool isPrivateMemoryPerWIHasValue() const
{
return m_PrivateMemoryPerWI.hasValue();
}
/// OpenCLVectorTypeHint related methods
VectorTypeHintMetaDataHandle getOpenCLVectorTypeHint()
......@@ -2843,7 +2827,6 @@ private:
llvm::Metadata* getLocalSizeNode( const llvm::MDNode* pParentNode) const;
llvm::MDNode* getLocalOffsetsNode( const llvm::MDNode* pParentNode) const;
llvm::MDNode* getResourceAllocNode( const llvm::MDNode* pParentNode) const;
llvm::Metadata* getPrivateMemoryPerWINode( const llvm::MDNode* pParentNode) const;
llvm::MDNode* getOpenCLVectorTypeHintNode( const llvm::MDNode* pParentNode) const;
llvm::MDNode* getOpenCLArgAddressSpacesNode( const llvm::MDNode* pParentNode) const;
llvm::MDNode* getBufferLocationIndexNode( const llvm::MDNode* pParentNode) const;
......@@ -2867,7 +2850,6 @@ private:
NamedMetaDataValue<int32_t> m_GlobalOffsetPresent;
MetaDataList<LocalOffsetMetaDataHandle> m_LocalOffsets;
ResourceAllocMetaDataHandle m_ResourceAlloc;
NamedMetaDataValue<int32_t> m_PrivateMemoryPerWI;
VectorTypeHintMetaDataHandle m_OpenCLVectorTypeHint;
MetaDataList<int32_t> m_OpenCLArgAddressSpaces;
MetaDataList<int32_t> m_BufferLocationIndex;
......
......@@ -686,12 +686,12 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
// It is possible that there is no alloca instruction in the caller but there
// is alloca in the callee. Save the total private memory to the metadata.
unsigned int totalPrivateMemPerWI = m_ModAllocaInfo->getTotalPrivateMemPerWI(m_currFunction);
m_pMdUtils->getFunctionsInfoItem(m_currFunction)->setPrivateMemoryPerWI(totalPrivateMemPerWI);
// This change is only till the FuncMD is ported to new MD framework
ModuleMetaData *modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();
assert(modMD && "Invalid metadata utils wrapper");
modMD->privateMemoryPerWI = totalPrivateMemPerWI;
modMD->FuncMD[m_currFunction].privateMemoryPerWI = totalPrivateMemPerWI;
modMD->privateMemoryPerWI = totalPrivateMemPerWI;//redundant ?
SmallVector<AllocaInst *, 8> &allocaInsts = m_ModAllocaInfo->getAllocaInsts(m_currFunction);
if (allocaInsts.empty())
......
......@@ -59,6 +59,7 @@ namespace IGC
int localSize = 0;
bool localIDPresent = false;
bool groupIDPresent = false;
int privateMemoryPerWI = 0;
};
// isCloned member is added to mark whether a function is clone
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment