Skip to content

Commit 7d89fb3

Browse files
Rishipal Singh Bhatiapaigeale
authored andcommitted
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
1 parent ac157e7 commit 7d89fb3

File tree

7 files changed

+34
-82
lines changed

7 files changed

+34
-82
lines changed

IGC/Compiler/CISACodeGen/CShader.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,19 @@ void CShader::InitEncoder(SIMDMode simdSize, bool canAbortOnSpill, ShaderDispatc
118118
void CShader::PreAnalysisPass()
119119
{
120120
ExtractGlobalVariables();
121-
122-
FunctionInfoMetaDataHandle funcInfoMD = m_pMdUtils->getFunctionsInfoItem(entry);
123-
if (funcInfoMD->isPrivateMemoryPerWIHasValue()) {
124-
if (GetContext()->getModuleMetaData()->compOpt.UseScratchSpacePrivateMemory) {
125-
m_ScratchSpaceSize = funcInfoMD->getPrivateMemoryPerWI() * numLanes(m_dispatchSize);
126-
// Round up to GENX_GRF_REG_SIZ-byte aligned.
127-
m_ScratchSpaceSize =
128-
((GENX_GRF_REG_SIZ + m_ScratchSpaceSize - 1) / GENX_GRF_REG_SIZ) * GENX_GRF_REG_SIZ;
121+
122+
auto funcMDItr = m_ModuleMetadata->FuncMD.find(entry);
123+
if (funcMDItr != m_ModuleMetadata->FuncMD.end())
124+
{
125+
if (funcMDItr->second.privateMemoryPerWI != 0)
126+
{
127+
if (GetContext()->getModuleMetaData()->compOpt.UseScratchSpacePrivateMemory)
128+
{
129+
m_ScratchSpaceSize = funcMDItr->second.privateMemoryPerWI * numLanes(m_dispatchSize);
130+
// Round up to GENX_GRF_REG_SIZ-byte aligned.
131+
m_ScratchSpaceSize =
132+
((GENX_GRF_REG_SIZ + m_ScratchSpaceSize - 1) / GENX_GRF_REG_SIZ) * GENX_GRF_REG_SIZ;
133+
}
129134
}
130135
}
131136

@@ -273,17 +278,21 @@ void CShader::InitKernelStack(bool ptr64bits)
273278
CVariable* pTemp = GetNewVariable(1, ISA_TYPE_UD, EALIGN_DWORD, true, 1);
274279
encoder.Mul(pTemp, pHWTID, pSize);
275280
encoder.Push();
276-
FunctionInfoMetaDataHandle funcInfoMD = m_pMdUtils->getFunctionsInfoItem(entry);
277281
// reserve space for alloca
278-
if (funcInfoMD->isPrivateMemoryPerWIHasValue()) {
279-
if (funcInfoMD->getPrivateMemoryPerWI()) {
280-
unsigned totalAllocaSize = funcInfoMD->getPrivateMemoryPerWI() * numLanes(m_dispatchSize);
282+
283+
auto funcMDItr = m_ModuleMetadata->FuncMD.find(entry);
284+
if (funcMDItr != m_ModuleMetadata->FuncMD.end())
285+
{
286+
if (funcMDItr->second.privateMemoryPerWI != 0)
287+
{
288+
unsigned totalAllocaSize = funcMDItr->second.privateMemoryPerWI * numLanes(m_dispatchSize);
281289
encoder.Add(pTemp, pTemp, ImmToVariable(totalAllocaSize, ISA_TYPE_UD));
282290
encoder.Push();
283291
}
284292
}
293+
285294
// modify private-memory size to a large setting
286-
funcInfoMD->setPrivateMemoryPerWI(8192);
295+
m_ModuleMetadata->FuncMD[entry].privateMemoryPerWI = 8192;
287296
CVariable* pBase = GetSymbol(kerArg);
288297
encoder.Add(m_SP, pBase, pTemp);
289298
encoder.Push();

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8761,14 +8761,14 @@ void EmitPass::emitStackFuncEntry(Function *F, bool ptr64bits)
87618761
// save SP before allocation
87628762
m_currShader->SaveSP();
87638763

8764-
FunctionInfoMetaDataHandle funcInfoMD = m_currShader->GetMetaDataUtils()->getFunctionsInfoItem(F);
87658764
// reserve space for all the alloca in the function subgroup
8766-
if (funcInfoMD->isPrivateMemoryPerWIHasValue())
8765+
auto funcMDItr = m_currShader->m_ModuleMetadata->FuncMD.find(F);
8766+
if (funcMDItr != m_currShader->m_ModuleMetadata->FuncMD.end())
87678767
{
8768-
if (funcInfoMD->getPrivateMemoryPerWI())
8768+
if (funcMDItr->second.privateMemoryPerWI != 0)
87698769
{
87708770
CVariable *pSP = m_currShader->GetSP();
8771-
unsigned totalAllocaSize = funcInfoMD->getPrivateMemoryPerWI() * numLanes(m_currShader->m_dispatchSize);
8771+
unsigned totalAllocaSize = funcMDItr->second.privateMemoryPerWI * numLanes(m_currShader->m_dispatchSize);
87728772
m_encoder->Add(pSP, pSP, m_currShader->ImmToVariable(totalAllocaSize, ISA_TYPE_UD));
87738773
m_encoder->Push();
87748774
}

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,11 +1393,10 @@ void COpenCLKernel::AllocatePayload()
13931393
// Set the amount of the private memory used by the kernel
13941394
// Set only if the private memory metadata actually exists and we don't use
13951395
// scratch space for private memory.
1396-
FunctionInfoMetaDataHandle funcInfoMD = m_pMdUtils->getFunctionsInfoItem(entry);
13971396
bool noScratchSpacePrivMem = !m_Context->getModuleMetaData()->compOpt.UseScratchSpacePrivateMemory;
1398-
if (noScratchSpacePrivMem && funcInfoMD->isPrivateMemoryPerWIHasValue())
1397+
if (noScratchSpacePrivMem && m_Context->getModuleMetaData()->privateMemoryPerWI)
13991398
{
1400-
m_perWIPrivateMemSize = funcInfoMD->getPrivateMemoryPerWI();
1399+
m_perWIPrivateMemSize = m_Context->getModuleMetaData()->privateMemoryPerWI;
14011400
}
14021401

14031402
m_ConstantBufferLength = 0;

IGC/Compiler/MetaDataApi/MetaDataApi.cpp

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const llvm::MDNode* pNode, bool hasId
22452245
m_GlobalOffsetPresent(getGlobalOffsetPresentNode(pNode)),
22462246
m_LocalOffsets(getLocalOffsetsNode(pNode), true),
22472247
m_ResourceAlloc(ResourceAllocMetaData::get(getResourceAllocNode(pNode), true)),
2248-
m_PrivateMemoryPerWI(getPrivateMemoryPerWINode(pNode)),
22492248
m_OpenCLVectorTypeHint(VectorTypeHintMetaData::get(getOpenCLVectorTypeHintNode(pNode), true)),
22502249
m_OpenCLArgAddressSpaces(getOpenCLArgAddressSpacesNode(pNode), true),
22512250
m_BufferLocationIndex(getBufferLocationIndexNode(pNode), true),
@@ -2271,7 +2270,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(): m_Type("function_type"),
22712270
m_GlobalOffsetPresent("global_offset_present"),
22722271
m_LocalOffsets("local_offsets"),
22732272
m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")),
2274-
m_PrivateMemoryPerWI("private_memory_per_wi"),
22752273
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")),
22762274
m_OpenCLArgAddressSpaces("opencl_kernel_arg_addr_space"),
22772275
m_BufferLocationIndex("buffer_location_index"),
@@ -2299,7 +2297,6 @@ FunctionInfoMetaData::FunctionInfoMetaData(const char* name):
22992297
m_GlobalOffsetPresent("global_offset_present"),
23002298
m_LocalOffsets("local_offsets"),
23012299
m_ResourceAlloc(ResourceAllocMetaDataHandle::ObjectType::get("resource_alloc")),
2302-
m_PrivateMemoryPerWI("private_memory_per_wi"),
23032300
m_OpenCLVectorTypeHint(VectorTypeHintMetaDataHandle::ObjectType::get("opencl_vec_type_hint")),
23042301
m_OpenCLArgAddressSpaces("opencl_kernel_arg_addr_space"),
23052302
m_BufferLocationIndex("buffer_location_index"),
@@ -2372,14 +2369,7 @@ bool FunctionInfoMetaData::hasValue() const
23722369
{
23732370
return true;
23742371
}
2375-
2376-
2377-
if (m_PrivateMemoryPerWI.hasValue())
2378-
{
2379-
return true;
2380-
}
2381-
2382-
2372+
23832373
if (m_OpenCLVectorTypeHint->hasValue())
23842374
{
23852375
return true;
@@ -2478,11 +2468,7 @@ bool FunctionInfoMetaData::dirty() const
24782468
if( m_ResourceAlloc.dirty() )
24792469
{
24802470
return true;
2481-
}
2482-
if( m_PrivateMemoryPerWI.dirty() )
2483-
{
2484-
return true;
2485-
}
2471+
}
24862472
if( m_OpenCLVectorTypeHint.dirty() )
24872473
{
24882474
return true;
@@ -2536,7 +2522,6 @@ void FunctionInfoMetaData::discardChanges()
25362522
m_GlobalOffsetPresent.discardChanges();
25372523
m_LocalOffsets.discardChanges();
25382524
m_ResourceAlloc.discardChanges();
2539-
m_PrivateMemoryPerWI.discardChanges();
25402525
m_OpenCLVectorTypeHint.discardChanges();
25412526
m_OpenCLArgAddressSpaces.discardChanges();
25422527
m_BufferLocationIndex.discardChanges();
@@ -2607,11 +2592,6 @@ llvm::Metadata* FunctionInfoMetaData::generateNode(llvm::LLVMContext& context) c
26072592
args.push_back(m_ResourceAlloc.generateNode(context));
26082593
}
26092594

2610-
if (isPrivateMemoryPerWIHasValue())
2611-
{
2612-
args.push_back(m_PrivateMemoryPerWI.generateNode(context));
2613-
}
2614-
26152595
if (m_OpenCLVectorTypeHint->hasValue())
26162596
{
26172597
args.push_back(m_OpenCLVectorTypeHint.generateNode(context));
@@ -2695,7 +2675,6 @@ void FunctionInfoMetaData::save(llvm::LLVMContext& context, llvm::MDNode* pNode)
26952675
m_GlobalOffsetPresent.save(context, llvm::cast<llvm::MDNode>(getGlobalOffsetPresentNode(pNode)));
26962676
m_LocalOffsets.save(context, llvm::cast<llvm::MDNode>(getLocalOffsetsNode(pNode)));
26972677
m_ResourceAlloc.save(context, llvm::cast<llvm::MDNode>(getResourceAllocNode(pNode)));
2698-
m_PrivateMemoryPerWI.save(context, llvm::cast<llvm::MDNode>(getPrivateMemoryPerWINode(pNode)));
26992678
m_OpenCLVectorTypeHint.save(context, llvm::cast<llvm::MDNode>(getOpenCLVectorTypeHintNode(pNode)));
27002679
m_OpenCLArgAddressSpaces.save(context, llvm::cast<llvm::MDNode>(getOpenCLArgAddressSpacesNode(pNode)));
27012680
m_BufferLocationIndex.save(context, llvm::cast<llvm::MDNode>(getBufferLocationIndexNode(pNode)));
@@ -2906,24 +2885,6 @@ llvm::MDNode* FunctionInfoMetaData::getResourceAllocNode( const llvm::MDNode* pP
29062885
return NULL;
29072886
}
29082887

2909-
llvm::Metadata* FunctionInfoMetaData::getPrivateMemoryPerWINode( const llvm::MDNode* pParentNode) const
2910-
{
2911-
if( !pParentNode )
2912-
{
2913-
return NULL;
2914-
}
2915-
2916-
unsigned int offset = _Mybase::getStartIndex();
2917-
for(NodeIterator i = NodeIterator(pParentNode, 0+offset), e = NodeIterator(pParentNode); i != e; ++i )
2918-
{
2919-
if( isNamedNode(i.get(), "private_memory_per_wi") )
2920-
{
2921-
return i.get();
2922-
}
2923-
}
2924-
return NULL;
2925-
}
2926-
29272888
llvm::MDNode* FunctionInfoMetaData::getOpenCLVectorTypeHintNode( const llvm::MDNode* pParentNode) const
29282889
{
29292890
if( !pParentNode )

IGC/Compiler/MetaDataApi/MetaDataApi.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,23 +2236,7 @@ class FunctionInfoMetaData:public IMetaDataObject
22362236
{
22372237
return m_ResourceAlloc;
22382238
}
2239-
2240-
2241-
/// PrivateMemoryPerWI related methods
2242-
PrivateMemoryPerWIType getPrivateMemoryPerWI() const
2243-
{
2244-
return m_PrivateMemoryPerWI.get();
2245-
}
2246-
void setPrivateMemoryPerWI( const PrivateMemoryPerWIType& val)
2247-
{
2248-
m_PrivateMemoryPerWI.set(val);
2249-
}
2250-
bool isPrivateMemoryPerWIHasValue() const
2251-
{
2252-
return m_PrivateMemoryPerWI.hasValue();
2253-
}
2254-
2255-
2239+
22562240
/// OpenCLVectorTypeHint related methods
22572241

22582242
VectorTypeHintMetaDataHandle getOpenCLVectorTypeHint()
@@ -2843,7 +2827,6 @@ class FunctionInfoMetaData:public IMetaDataObject
28432827
llvm::Metadata* getLocalSizeNode( const llvm::MDNode* pParentNode) const;
28442828
llvm::MDNode* getLocalOffsetsNode( const llvm::MDNode* pParentNode) const;
28452829
llvm::MDNode* getResourceAllocNode( const llvm::MDNode* pParentNode) const;
2846-
llvm::Metadata* getPrivateMemoryPerWINode( const llvm::MDNode* pParentNode) const;
28472830
llvm::MDNode* getOpenCLVectorTypeHintNode( const llvm::MDNode* pParentNode) const;
28482831
llvm::MDNode* getOpenCLArgAddressSpacesNode( const llvm::MDNode* pParentNode) const;
28492832
llvm::MDNode* getBufferLocationIndexNode( const llvm::MDNode* pParentNode) const;
@@ -2867,7 +2850,6 @@ class FunctionInfoMetaData:public IMetaDataObject
28672850
NamedMetaDataValue<int32_t> m_GlobalOffsetPresent;
28682851
MetaDataList<LocalOffsetMetaDataHandle> m_LocalOffsets;
28692852
ResourceAllocMetaDataHandle m_ResourceAlloc;
2870-
NamedMetaDataValue<int32_t> m_PrivateMemoryPerWI;
28712853
VectorTypeHintMetaDataHandle m_OpenCLVectorTypeHint;
28722854
MetaDataList<int32_t> m_OpenCLArgAddressSpaces;
28732855
MetaDataList<int32_t> m_BufferLocationIndex;

IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,12 @@ bool PrivateMemoryResolution::resolveAllocaInstuctions(bool stackCall)
686686
// It is possible that there is no alloca instruction in the caller but there
687687
// is alloca in the callee. Save the total private memory to the metadata.
688688
unsigned int totalPrivateMemPerWI = m_ModAllocaInfo->getTotalPrivateMemPerWI(m_currFunction);
689-
m_pMdUtils->getFunctionsInfoItem(m_currFunction)->setPrivateMemoryPerWI(totalPrivateMemPerWI);
690689

691690
// This change is only till the FuncMD is ported to new MD framework
692691
ModuleMetaData *modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();
693692
assert(modMD && "Invalid metadata utils wrapper");
694-
modMD->privateMemoryPerWI = totalPrivateMemPerWI;
693+
modMD->FuncMD[m_currFunction].privateMemoryPerWI = totalPrivateMemPerWI;
694+
modMD->privateMemoryPerWI = totalPrivateMemPerWI;//redundant ?
695695

696696
SmallVector<AllocaInst *, 8> &allocaInsts = m_ModAllocaInfo->getAllocaInsts(m_currFunction);
697697
if (allocaInsts.empty())

IGC/common/MDFrameWork.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ namespace IGC
5959
int localSize = 0;
6060
bool localIDPresent = false;
6161
bool groupIDPresent = false;
62+
int privateMemoryPerWI = 0;
6263
};
6364

6465
// isCloned member is added to mark whether a function is clone

0 commit comments

Comments
 (0)