Skip to content

Commit 2326f2d

Browse files
michalkr52igcbot
authored andcommitted
Refactor enableZEBinary() conditions in OCL
Refactor OCL code paths depending on the enableZEBinary() as if zebin format was always supported and used. The OpenCLPrintfResolution/basic.ll test was targeting older platforms using the patch token format, so it had to be adjusted for differences in pointer sizes. Specifically, pointers to printf string literals are 64-bit instead of 32-bit. Some dead code will be left-over after merging, it will be removed in a later PR.
1 parent 4d3ca7b commit 2326f2d

File tree

10 files changed

+124
-264
lines changed

10 files changed

+124
-264
lines changed

IGC/AdaptorOCL/dllInterfaceCompute.cpp

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -897,15 +897,6 @@ bool ProcessElfInput(
897897
{
898898
if (hasVISALinking)
899899
{
900-
if (!Context.enableZEBinary()) {
901-
SetErrorMessage(
902-
"vISA linking can be used only with ZeBinary "
903-
"compiler output format. It seems that it is "
904-
"currently disabled for your platform.",
905-
OutputArgs);
906-
return false;
907-
}
908-
909900
ShaderHash hash = ShaderHashOCL(
910901
reinterpret_cast<const UINT*>(InputArgs.pInput),
911902
InputArgs.InputSize / 4);
@@ -1629,42 +1620,28 @@ bool TranslateBuildSPMD(
16291620
oclContext.metrics.FinalizeStats();
16301621
oclContext.metrics.OutputMetrics();
16311622

1632-
if (!oclContext.enableZEBinary())
1623+
llvm::SmallVector<char, 64> buf;
1624+
llvm::raw_svector_ostream llvm_os(buf);
1625+
const bool excludeIRFromZEBinary = IGC_IS_FLAG_ENABLED(ExcludeIRFromZEBinary) || oclContext.getModuleMetaData()->compOpt.ExcludeIRFromZEBinary;
1626+
const char* spv_data = nullptr;
1627+
uint32_t spv_size = 0;
1628+
if (inputDataFormatTemp == TB_DATA_FORMAT_SPIR_V && !excludeIRFromZEBinary)
16331629
{
1634-
Util::BinaryStream programBinary;
1635-
// Patch token based binary format
1636-
oclContext.m_programOutput.CreateKernelBinaries();
1637-
oclContext.m_programOutput.GetProgramBinary(programBinary, pointerSizeInBytes);
1638-
binarySize = static_cast<int>(programBinary.Size());
1639-
binaryOutput = new char[binarySize];
1640-
memcpy_s(binaryOutput, binarySize, programBinary.GetLinearPointer(), binarySize);
1630+
spv_data = pInputArgs->pInput;
1631+
spv_size = pInputArgs->InputSize;
16411632
}
1642-
else
1643-
{
1644-
// ze binary format
1645-
llvm::SmallVector<char, 64> buf;
1646-
llvm::raw_svector_ostream llvm_os(buf);
1647-
const bool excludeIRFromZEBinary = IGC_IS_FLAG_ENABLED(ExcludeIRFromZEBinary) || oclContext.getModuleMetaData()->compOpt.ExcludeIRFromZEBinary;
1648-
const char* spv_data = nullptr;
1649-
uint32_t spv_size = 0;
1650-
if (inputDataFormatTemp == TB_DATA_FORMAT_SPIR_V && !excludeIRFromZEBinary)
1651-
{
1652-
spv_data = pInputArgs->pInput;
1653-
spv_size = pInputArgs->InputSize;
1654-
}
16551633

1656-
// IGC metrics
1657-
size_t metricDataSize = oclContext.metrics.getMetricDataSize();
1658-
auto metricData = reinterpret_cast<const char*>(oclContext.metrics.getMetricData());
1634+
// IGC metrics
1635+
size_t metricDataSize = oclContext.metrics.getMetricDataSize();
1636+
auto metricData = reinterpret_cast<const char*>(oclContext.metrics.getMetricData());
16591637

1660-
oclContext.m_programOutput.GetZEBinary(llvm_os, pointerSizeInBytes,
1661-
spv_data, spv_size, metricData, metricDataSize, pInputArgs->pOptions, pInputArgs->OptionsSize);
1638+
oclContext.m_programOutput.GetZEBinary(llvm_os, pointerSizeInBytes,
1639+
spv_data, spv_size, metricData, metricDataSize, pInputArgs->pOptions, pInputArgs->OptionsSize);
16621640

1663-
// FIXME: try to avoid memory copy here
1664-
binarySize = buf.size();
1665-
binaryOutput = new char[binarySize];
1666-
memcpy_s(binaryOutput, binarySize, buf.data(), buf.size());
1667-
}
1641+
// FIXME: try to avoid memory copy here
1642+
binarySize = buf.size();
1643+
binaryOutput = new char[binarySize];
1644+
memcpy_s(binaryOutput, binarySize, buf.data(), buf.size());
16681645

16691646
if (IGC_IS_FLAG_ENABLED(ShaderDumpEnable))
16701647
dumpOCLProgramBinary(oclContext, binaryOutput, binarySize);

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ namespace IGC
132132

133133
bool OpenCLProgramContext::forceGlobalMemoryAllocation() const
134134
{
135-
return m_InternalOptions.ForceGlobalMemoryAllocation ||
136-
(m_hasGlobalInPrivateAddressSpace && enableZEBinary());
135+
return m_InternalOptions.ForceGlobalMemoryAllocation || m_hasGlobalInPrivateAddressSpace;
137136
}
138137

139138
bool OpenCLProgramContext::allocatePrivateAsGlobalBuffer() const
@@ -527,8 +526,6 @@ namespace IGC
527526

528527
void COpenCLKernel::CreateZEInlineSamplerAnnotations()
529528
{
530-
IGC_ASSERT(m_Context->enableZEBinary());
531-
532529
auto getZESamplerAddrMode = [](int addrMode)
533530
{
534531
switch (addrMode) {
@@ -2586,18 +2583,16 @@ namespace IGC
25862583

25872584
const uint offsetInPayload = offset - constantBufferStart - offsetCorrection;
25882585

2589-
// Create annotations for the kernel argument
2590-
// If an arg is unused, don't generate patch token for it.
2591-
CreateAnnotations(&arg, offsetInPayload);
2592-
2593-
if (m_Context->enableZEBinary()) {
2594-
// FIXME: once we transit to zebin completely, we don't need to do
2595-
// CreateAnnotations above. Only CreateZEPayloadArguments is required
2596-
bool Res = CreateZEPayloadArguments(&arg, offsetInPayload, ptrArgsAttrMap);
2597-
IGC_ASSERT_MESSAGE(Res, "ZEBin: unsupported KernelArg Type");
2598-
(void) Res;
2586+
if (arg.getArgType() == KernelArg::ArgType::IMPLICIT_LOCAL_IDS) {
2587+
m_kernelInfo.m_threadPayload.HasLocalIDx = true;
2588+
m_kernelInfo.m_threadPayload.HasLocalIDy = true;
2589+
m_kernelInfo.m_threadPayload.HasLocalIDz = true;
25992590
}
26002591

2592+
bool Res = CreateZEPayloadArguments(&arg, offsetInPayload, ptrArgsAttrMap);
2593+
IGC_ASSERT_MESSAGE(Res, "ZEBin: unsupported KernelArg Type");
2594+
(void) Res;
2595+
26012596
if (arg.needsAllocation())
26022597
{
26032598
for (int i = 0; i < numAllocInstances; ++i)
@@ -2649,21 +2644,10 @@ namespace IGC
26492644

26502645
m_State.m_ConstantBufferLength = iSTD::Align(m_State.m_ConstantBufferLength, getGRFSize());
26512646

2652-
// FIXME: skip this function when EnableZEBinary
2653-
CreateInlineSamplerAnnotations();
2654-
if (m_Context->enableZEBinary())
2655-
{
2656-
CreateZEInlineSamplerAnnotations();
2657-
// Currently we don't support inline vme sampler in zebin.
2658-
// assertion tests if we force to EnableZEBinary but encounter inline vme sampler.
2659-
IGC_ASSERT_MESSAGE(!m_kernelInfo.m_HasInlineVmeSamplers, "ZEBin: Inline vme sampler unsupported");
2660-
}
2661-
2662-
// Handle kernel reflection for patch-token format
2663-
if (!m_Context->enableZEBinary()) {
2664-
CreateKernelArgInfo();
2665-
CreateKernelAttributeInfo();
2666-
}
2647+
CreateZEInlineSamplerAnnotations();
2648+
// Currently we don't support inline vme sampler in zebin.
2649+
// Assertion tests if we encounter inline vme sampler.
2650+
IGC_ASSERT_MESSAGE(!m_kernelInfo.m_HasInlineVmeSamplers, "ZEBin: Inline vme sampler unsupported");
26672651

26682652
// Create annotations for printf string.
26692653
CreatePrintfStringAnnotations();
@@ -2939,10 +2923,8 @@ namespace IGC
29392923
m_kernelInfo.m_executionEnvironment.HasLscStoresWithNonDefaultL1CacheControls = m_State.GetHasLscStoresWithNonDefaultL1CacheControls();
29402924
}
29412925

2942-
if (m_Context->enableZEBinary()) {
2943-
FillZEKernelArgInfo();
2944-
FillZEUserAttributes(funcInfoMD);
2945-
}
2926+
FillZEKernelArgInfo();
2927+
FillZEUserAttributes(funcInfoMD);
29462928
}
29472929

29482930
void COpenCLKernel::RecomputeBTLayout()
@@ -3073,20 +3055,17 @@ namespace IGC
30733055

30743056
ctx->m_programInfo.m_initConstantAnnotation = std::move(initConstant);
30753057

3076-
if (ctx->enableZEBinary())
3077-
{
3078-
// String literals
3079-
auto& ipsbStringMDHandle = modMD->inlineBuffers[InlineProgramScopeBufferType::ConstantStrings];
3080-
std::unique_ptr<iOpenCL::InitConstantAnnotation> initStringConstant(new iOpenCL::InitConstantAnnotation());
3081-
initStringConstant->Alignment = ipsbStringMDHandle.alignment;
3082-
initStringConstant->AllocSize = ipsbStringMDHandle.allocSize;
3058+
// String literals
3059+
auto& ipsbStringMDHandle = modMD->inlineBuffers[InlineProgramScopeBufferType::ConstantStrings];
3060+
std::unique_ptr<iOpenCL::InitConstantAnnotation> initStringConstant(new iOpenCL::InitConstantAnnotation());
3061+
initStringConstant->Alignment = ipsbStringMDHandle.alignment;
3062+
initStringConstant->AllocSize = ipsbStringMDHandle.allocSize;
30833063

3084-
bufferSize = (ipsbStringMDHandle.Buffer).size();
3085-
initStringConstant->InlineData.resize(bufferSize);
3086-
memcpy_s(initStringConstant->InlineData.data(), bufferSize, ipsbStringMDHandle.Buffer.data(), bufferSize);
3064+
bufferSize = (ipsbStringMDHandle.Buffer).size();
3065+
initStringConstant->InlineData.resize(bufferSize);
3066+
memcpy_s(initStringConstant->InlineData.data(), bufferSize, ipsbStringMDHandle.Buffer.data(), bufferSize);
30873067

3088-
ctx->m_programInfo.m_initConstantStringAnnotation = std::move(initStringConstant);
3089-
}
3068+
ctx->m_programInfo.m_initConstantStringAnnotation = std::move(initStringConstant);
30903069
}
30913070

30923071
if (modMD->inlineBuffers[InlineProgramScopeBufferType::Globals].allocSize)
@@ -3510,10 +3489,6 @@ namespace IGC
35103489
if (ctx->m_retryManager.IsFirstTry())
35113490
{
35123491
CollectProgramInfo(ctx);
3513-
if (!ctx->enableZEBinary())
3514-
{
3515-
ctx->m_programOutput.CreateProgramScopePatchStream(ctx->m_programInfo);
3516-
}
35173492
}
35183493

35193494
MetaDataUtils* pMdUtils = ctx->getMetaDataUtils();

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.hpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ namespace IGC
3131
uint32_t m_numUAVs = 0;
3232

3333
private:
34-
bool m_enableZEBinary;
35-
3634
// To minimize negative performance implications caused by a dynamic generic address
3735
// space resolution, private memory can be allocated in the same address space as
3836
// global memory. It gives a possibility to treat private memory operations as global
@@ -76,17 +74,9 @@ namespace IGC
7674
}
7775
}
7876

79-
80-
if (m_InternalOptions.DisableZEBinary) {
81-
// Allow to disable ZEBin via internal options
82-
m_enableZEBinary = false;
83-
} else {
84-
// Enable ZEBin for all supported platforms
85-
m_enableZEBinary = platform.supportsZEBin();
86-
}
8777
}
8878

89-
bool enableZEBinary() const override { return m_enableZEBinary; }
79+
bool enableZEBinary() const override { return true; }
9080
bool isSPIRV() const;
9181
void setAsSPIRV();
9282
float getProfilingTimerResolution();

IGC/Compiler/CISACodeGen/OpenCLOptions.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,6 @@ void InternalOptions::parseOptions(const char* internalOpts)
202202
}
203203
}
204204

205-
if (internalOptions.hasArg(OPT_disable_zebin_common))
206-
{
207-
DisableZEBinary = true;
208-
}
209-
210205
if (internalOptions.hasArg(OPT_exclude_ir_from_zebin_common))
211206
{
212207
ExcludeIRFromZEBinary = true;

IGC/Compiler/CISACodeGen/OpenCLOptions.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ class InternalOptions
114114
uint32_t IntelScratchSpacePrivateMemoryMinimalSizePerThread = 0;
115115

116116
bool EnableDivergentBarrierHandling = false;
117-
bool DisableZEBinary = false;
118117
bool EnableBufferBoundsChecking = false;
119118

120119
// Compile only up to vISA stage.

IGC/Compiler/Optimizer/OpenCLPasses/OpenCLPrintf/OpenCLPrintfResolution.cpp

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -235,39 +235,7 @@ Value* OpenCLPrintfResolution::processPrintfString(Value* arg, Function& F)
235235
return ConstantInt::get(m_int32Type, -1);
236236
}
237237

238-
if (m_CGContext->enableZEBinary())
239-
{
240-
return arg;
241-
}
242-
243-
ConstantDataArray* formatStringConst = dyn_cast<ConstantDataArray>(formatString->getInitializer());
244-
std::string escaped_string = getEscapedString(formatStringConst);
245-
246-
// preventing MD enries duplication
247-
if (m_MapStringStringIndex.find(escaped_string) != m_MapStringStringIndex.end()) {
248-
return ConstantInt::get(m_int32Type, m_MapStringStringIndex[escaped_string]);
249-
}
250-
251-
252-
// Add new metadata node and put the printf string into it.
253-
// The first element of metadata node is the string index,
254-
// the second element is the string itself.
255-
NamedMDNode* namedMDNode = m_module->getOrInsertNamedMetadata(getPrintfStringsMDNodeName(F));
256-
SmallVector<Metadata*, 2> args;
257-
Metadata* stringIndexVal = ConstantAsMetadata::get(
258-
ConstantInt::get(m_int32Type, m_stringIndex));
259-
260-
MDString* final_string = MDString::get(*m_context, escaped_string);
261-
262-
args.push_back(stringIndexVal);
263-
args.push_back(final_string);
264-
265-
MDNode* itemMDNode = MDNode::get(*m_context, args);
266-
namedMDNode->addOperand(itemMDNode);
267-
268-
m_MapStringStringIndex[escaped_string] = m_stringIndex;
269-
270-
return ConstantInt::get(m_int32Type, m_stringIndex++);
238+
return arg;
271239
}
272240
else if (CastInst* castInst = dyn_cast<CastInst>(arg))
273241
{
@@ -600,7 +568,7 @@ void OpenCLPrintfResolution::expandPrintfCall(CallInst& printfCall, Function& F)
600568
writeOffsetPtr = generateCastToPtr(argDesc, writeOffset, bblockTrue);
601569
writeOffsetPtr->setDebugLoc(m_DL);
602570

603-
if (dataType == SHADER_PRINTF_STRING_LITERAL && m_CGContext->enableZEBinary())
571+
if (dataType == SHADER_PRINTF_STRING_LITERAL)
604572
{
605573
printfArg = CastInst::Create(Instruction::CastOps::PtrToInt,
606574
argDesc->value,
@@ -836,13 +804,8 @@ unsigned int OpenCLPrintfResolution::getArgTypeSize(IGC::SHADER_PRINTF_TYPE argT
836804
return vecSize * 8;
837805

838806
case IGC::SHADER_PRINTF_STRING_LITERAL: {
839-
if (m_CGContext->enableZEBinary()) {
840-
// The size of the format string address
841-
return 8;
842-
} else {
843-
// The size of the format string index
844-
return 4;
845-
}
807+
// The size of the format string address
808+
return 8;
846809
}
847810

848811
default:
@@ -968,10 +931,7 @@ Instruction* OpenCLPrintfResolution::generateCastToPtr(SPrintfArgDescriptor* arg
968931
}
969932

970933
case IGC::SHADER_PRINTF_STRING_LITERAL: {
971-
if (m_CGContext->enableZEBinary())
972-
castedType = Type::getInt64PtrTy(*m_context, ADDRESS_SPACE_GLOBAL);
973-
else
974-
castedType = Type::getInt32PtrTy(*m_context, ADDRESS_SPACE_GLOBAL);
934+
castedType = Type::getInt64PtrTy(*m_context, ADDRESS_SPACE_GLOBAL);
975935
break;
976936
}
977937
case IGC::SHADER_PRINTF_POINTER:

0 commit comments

Comments
 (0)