Skip to content

Commit 902743b

Browse files
aratajewigcbot
authored andcommitted
Avoid generating useless binding table and surface states
Don't generate binding table and surface states if stateful optimization was not applied. This change handles both compiler outputs: - patch tokens - zebin
1 parent 1702190 commit 902743b

File tree

6 files changed

+62
-35
lines changed

6 files changed

+62
-35
lines changed

IGC/AdaptorOCL/OCL/KernelAnnotations.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct PointerArgumentAnnotation : KernelArgumentAnnotation
7070
DWORD SecondPayloadSizeInBytes;
7171
bool IsEmulationArgument;
7272
bool IsBindlessAccess;
73+
bool HasStatefulAccess;
7374

7475
static bool compare( const PointerArgumentAnnotation* a, const PointerArgumentAnnotation* b )
7576
{

IGC/AdaptorOCL/OCL/sp/sp_g8.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -685,17 +685,20 @@ RETVAL CGen8OpenCLStateProcessor::CreateSurfaceStateHeap(
685685

686686
for (const auto& annotation: annotations.m_pointerArgument)
687687
{
688-
unsigned int bti = annotations.m_argIndexMap.at(annotation->ArgumentNumber);
689-
context.Surface.SurfaceOffset[bti] = (DWORD)membuf.Size();
688+
if (annotation->HasStatefulAccess)
689+
{
690+
unsigned int bti = annotations.m_argIndexMap.at(annotation->ArgumentNumber);
691+
context.Surface.SurfaceOffset[bti] = (DWORD)membuf.Size();
690692

691-
SurfaceStates.insert(
692-
std::make_pair(
693-
bti,
694-
SurfaceState(
695-
SURFACE_BUFFER,
696-
SURFACE_FORMAT_UNKNOWN,
697-
0,
698-
false)));
693+
SurfaceStates.insert(
694+
std::make_pair(
695+
bti,
696+
SurfaceState(
697+
SURFACE_BUFFER,
698+
SURFACE_FORMAT_UNKNOWN,
699+
0,
700+
false)));
701+
}
699702
}
700703

701704
// Images
@@ -1556,11 +1559,10 @@ RETVAL CGen8OpenCLStateProcessor::CreatePatchList(
15561559
dataParameterStreamSize,
15571560
ptrArg->BindingTableIndex + ptrArg->SecondPayloadSizeInBytes
15581561
);
1559-
15601562
}
15611563
else
15621564
{
1563-
patch.SurfaceStateHeapOffset = context.Surface.SurfaceOffset[bti];
1565+
patch.SurfaceStateHeapOffset = ptrArg->HasStatefulAccess ? context.Surface.SurfaceOffset[bti] : UINT32_MAX;
15641566
}
15651567
patch.DataParamOffset = ptrArg->PayloadPosition;
15661568
patch.DataParamSize = ptrArg->PayloadSizeInBytes;

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -640,24 +640,30 @@ namespace IGC
640640
funcMD.m_OpenCLArgTypeQualifiers[arg_idx] == "const")
641641
access_type = zebin::PreDefinedAttrGetter::ArgAccessType::readonly;
642642

643-
// Add BTI argument if being promoted
644-
// FIXME: do not set bti if the number is 0xffffffff (?)
645-
SOpenCLKernelInfo::SResourceInfo resInfo = getResourceInfo(arg_idx);
646-
uint32_t bti_idx = getBTI(resInfo);
647-
if (bti_idx != 0xffffffff) {
648-
// add BTI argument with addr_mode set to stateful
649-
// promoted arg has 0 offset and 0 size
650-
zebin::ZEInfoBuilder::addPayloadArgumentByPointer(m_kernelInfo.m_zePayloadArgs,
651-
0, 0, arg_idx,
652-
zebin::PreDefinedAttrGetter::ArgAddrMode::stateful,
653-
(kernelArg->getArgType() == KernelArg::ArgType::PTR_GLOBAL)?
654-
zebin::PreDefinedAttrGetter::ArgAddrSpace::global :
655-
zebin::PreDefinedAttrGetter::ArgAddrSpace::constant,
656-
access_type
657-
);
658-
// add the corresponding BTI table index
659-
zebin::ZEInfoBuilder::addBindingTableIndex(m_kernelInfo.m_zeBTIArgs,
660-
bti_idx, arg_idx);
643+
ResourceAllocMD& resAllocMD = GetContext()->getModuleMetaData()->FuncMD[entry].resAllocMD;
644+
IGC_ASSERT_MESSAGE(resAllocMD.argAllocMDList.size() > 0, "ArgAllocMDList is empty.");
645+
ArgAllocMD& argAlloc = resAllocMD.argAllocMDList[arg_idx];
646+
647+
if (argAlloc.hasStatefulAccess) {
648+
// Add BTI argument if being promoted
649+
// FIXME: do not set bti if the number is 0xffffffff (?)
650+
SOpenCLKernelInfo::SResourceInfo resInfo = getResourceInfo(arg_idx);
651+
uint32_t bti_idx = getBTI(resInfo);
652+
if (bti_idx != 0xffffffff) {
653+
// add BTI argument with addr_mode set to stateful
654+
// promoted arg has 0 offset and 0 size
655+
zebin::ZEInfoBuilder::addPayloadArgumentByPointer(m_kernelInfo.m_zePayloadArgs,
656+
0, 0, arg_idx,
657+
zebin::PreDefinedAttrGetter::ArgAddrMode::stateful,
658+
(kernelArg->getArgType() == KernelArg::ArgType::PTR_GLOBAL) ?
659+
zebin::PreDefinedAttrGetter::ArgAddrSpace::global :
660+
zebin::PreDefinedAttrGetter::ArgAddrSpace::constant,
661+
access_type
662+
);
663+
// add the corresponding BTI table index
664+
zebin::ZEInfoBuilder::addBindingTableIndex(m_kernelInfo.m_zeBTIArgs,
665+
bti_idx, arg_idx);
666+
}
661667
}
662668
// FIXME: check if all reference are promoted, if it is, we can skip
663669
// creating non-bti payload arg
@@ -676,11 +682,6 @@ namespace IGC
676682
break;
677683
*/
678684

679-
ResourceAllocMD& resAllocMD = GetContext()->getModuleMetaData()->FuncMD[entry].resAllocMD;
680-
IGC_ASSERT_MESSAGE(resAllocMD.argAllocMDList.size() > 0, "ArgAllocMDList is empty.");
681-
682-
ArgAllocMD& argAlloc = resAllocMD.argAllocMDList[arg_idx];
683-
684685
zebin::PreDefinedAttrGetter::ArgAddrMode addr_mode =
685686
zebin::PreDefinedAttrGetter::ArgAddrMode::stateless;
686687
if (argAlloc.type == ResourceTypeEnum::BindlessUAVResourceType)
@@ -1123,6 +1124,7 @@ namespace IGC
11231124

11241125
m_kernelInfo.m_argOffsetMap[argNo] = ptrAnnotation;
11251126

1127+
ptrAnnotation->HasStatefulAccess = argAlloc->hasStatefulAccess;
11261128
ptrAnnotation->AddressSpace = addressSpace;
11271129
ptrAnnotation->ArgumentNumber = argNo;
11281130
ptrAnnotation->BindingTableIndex = getBTI(resInfo);

IGC/Compiler/Optimizer/OpenCLPasses/StatelessToStateful/StatelessToStateful.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,20 @@ bool StatelessToStateful::runOnFunction(llvm::Function& F)
182182
visit(F);
183183

184184
finalizeArgInitialValue(&F);
185+
186+
if (!m_promotedKernelArgs.empty())
187+
{
188+
ModuleMetaData* modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();
189+
FunctionMetaData* funcMD = &modMD->FuncMD[&F];
190+
ResourceAllocMD* resAllocMD = &funcMD->resAllocMD;
191+
IGC_ASSERT_MESSAGE(resAllocMD->argAllocMDList.size() > 0, "ArgAllocMDList is empty.");
192+
for (auto promotedArg : m_promotedKernelArgs)
193+
{
194+
ArgAllocMD* argAlloc = &resAllocMD->argAllocMDList[promotedArg->getAssociatedArgNo()];
195+
argAlloc->hasStatefulAccess = true;
196+
}
197+
}
198+
185199
delete m_pImplicitArgs;
186200
delete m_pKernelArgs;
187201
m_promotedKernelArgs.clear();

IGC/VectorCompiler/igcdeps/src/cmc.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ void CMKernel::createPointerGlobalAnnotation(unsigned index, unsigned offset,
321321
auto ptrAnnotation = std::make_unique<iOpenCL::PointerArgumentAnnotation>();
322322
ptrAnnotation->IsStateless = !isBindless;
323323
ptrAnnotation->IsBindlessAccess = isBindless;
324+
// TODO: Make an analysis whether a particular argument has any stateful access,
325+
// and set the below variable appropriately. For now, make a safe bet and always
326+
// assume that stateful access is present.
327+
ptrAnnotation->HasStatefulAccess = true;
324328
ptrAnnotation->AddressSpace = iOpenCL::KERNEL_ARGUMENT_ADDRESS_SPACE_GLOBAL;
325329
ptrAnnotation->ArgumentNumber = index;
326330
ptrAnnotation->BindingTableIndex = BTI;
@@ -368,6 +372,9 @@ void CMKernel::createPrivateBaseAnnotation(
368372
void CMKernel::createBufferStatefulAnnotation(unsigned argNo,
369373
ArgAccessKind accessKind)
370374
{
375+
// TODO: early return if there is no stateful access to this argument
376+
// if(no_stateful_access) return;
377+
371378
auto constInput = std::make_unique<iOpenCL::ConstantInputAnnotation>();
372379

373380
constInput->ConstantType = iOpenCL::DATA_PARAMETER_BUFFER_STATEFUL;

IGC/common/MDFrameWork.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ namespace IGC
117117
int type = -1;
118118
int extensionType = -1;
119119
int indexType = -1;
120+
int hasStatefulAccess = false;
120121
};
121122

122123
struct InlineSamplersMD

0 commit comments

Comments
 (0)