Skip to content

Commit f891ebf

Browse files
PawelJurekigcbot
authored andcommitted
Add CROSS_THREAD_OFF_R0_RELOCATION runtime symbol in ZeBinary builder if it is used in the program
CROSS_THREAD_OFF_R0_RELOCATION symbol was added in ZeBinaryBuilder only if EnableGlobalStateBuffer registry flag was set. This relocation in the kernel is set when vISA_emitCrossThreadOffR0Reloc option is set. VC backend adds this option without checking for EnableGlobalStateBuffer registry setting for subtargets that have thread payload in memory. This change makez ZeBinary builder add the runtime symbol if the relocation is detected in the program.
1 parent 2e19957 commit f891ebf

File tree

9 files changed

+35
-8
lines changed

9 files changed

+35
-8
lines changed

IGC/AdaptorOCL/OCL/sp/zebin_builder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void ZEBinaryBuilder::addProgramScopeInfo(const IGC::SOpenCLProgramInfo& program
160160
{
161161
addGlobalConstants(programInfo);
162162
addGlobals(programInfo);
163-
addRuntimeSymbols();
163+
addRuntimeSymbols(programInfo);
164164
addProgramSymbols(programInfo);
165165
addProgramRelocations(programInfo);
166166
addGlobalHostAccessInfo(programInfo);
@@ -375,10 +375,10 @@ void ZEBinaryBuilder::addSymbol(const vISA::ZESymEntry& sym, uint8_t binding,
375375
getSymbolElfType(sym), targetSect);
376376
}
377377

378-
void ZEBinaryBuilder::addRuntimeSymbols()
378+
void ZEBinaryBuilder::addRuntimeSymbols(const IGC::SOpenCLProgramInfo& annotations)
379379
{
380-
if (IGC_IS_FLAG_ENABLED(EnableGlobalStateBuffer))
381-
mBuilder.addSymbol("__INTEL_PATCH_CROSS_THREAD_OFFSET_OFF_R0", /*addr*/0, /*size*/0,
380+
if (annotations.m_hasCrossThreadOffsetRelocations)
381+
mBuilder.addSymbol(vISA::CROSS_THREAD_OFF_R0_RELOCATION_NAME, /*addr*/0, /*size*/0,
382382
llvm::ELF::STB_GLOBAL, llvm::ELF::STT_NOTYPE, /*sectionId*/-1);
383383
}
384384

IGC/AdaptorOCL/OCL/sp/zebin_builder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ZEBinaryBuilder : DisallowCopy
106106
void addMiscInfoSection(std::string sectName, const uint8_t* data, uint32_t size);
107107

108108
/// add runtime symbols
109-
void addRuntimeSymbols();
109+
void addRuntimeSymbols(const IGC::SOpenCLProgramInfo& annotations);
110110

111111
/// add note section for IGC metrics
112112
void addMetrics(const uint8_t* data, uint32_t size);

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6424,6 +6424,16 @@ namespace IGC
64246424
if (ZEBinEnabled)
64256425
{
64266426
CreateRelocationTable(pMainKernel, pOutput->m_relocs);
6427+
for (const auto& reloc : pOutput->m_relocs)
6428+
{
6429+
if (reloc.r_symbol == vISA::CROSS_THREAD_OFF_R0_RELOCATION_NAME)
6430+
{
6431+
IGC_ASSERT(context->type == ShaderType::OPENCL_SHADER);
6432+
auto cl_context = static_cast<OpenCLProgramContext*>(context);
6433+
cl_context->m_programInfo.m_hasCrossThreadOffsetRelocations = true;
6434+
break;
6435+
}
6436+
}
64276437
}
64286438
else
64296439
{

IGC/Compiler/CodeGenPublic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ namespace IGC
894894
ZEBinProgramSymbolTable m_zebinSymbolTable;
895895
LegacySymbolTable m_legacySymbolTable;
896896
ZEBinGlobalHostAccessTable m_zebinGlobalHostAccessTable;
897+
bool m_hasCrossThreadOffsetRelocations = false;
897898
};
898899

899900
class CBTILayout

IGC/VectorCompiler/igcdeps/include/vc/igcdeps/cmc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class CGen8CMProgram : public iOpenCL::CGen8OpenCLProgramBase {
129129
void GetZEBinary(llvm::raw_pwrite_stream &programBinary,
130130
unsigned pointerSizeInBytes) override;
131131
bool HasErrors() const { return !m_ErrorLog.empty(); };
132+
bool HasCrossThreadOffsetRelocations();
132133
llvm::Error GetError() const;
133134

134135
// CM kernel list.

IGC/VectorCompiler/igcdeps/src/PatchTokens.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,14 @@ void CGen8CMProgram::GetZEBinary(llvm::raw_pwrite_stream &programBinary,
219219
}
220220
zebuilder.getBinaryObject(programBinary);
221221
}
222+
223+
bool CGen8CMProgram::HasCrossThreadOffsetRelocations() {
224+
for (const auto &kernel : m_kernels) {
225+
for (const auto &reloc : kernel->getProgramOutput().m_relocs) {
226+
if (reloc.r_symbol == vISA::CROSS_THREAD_OFF_R0_RELOCATION_NAME) {
227+
return true;
228+
}
229+
}
230+
}
231+
return false;
232+
}

IGC/VectorCompiler/igcdeps/src/cmc.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,8 @@ getDataAnnotation(const GenXOCLRuntimeInfo::DataInfo &Data) {
831831

832832
static void
833833
fillOCLProgramInfo(IGC::SOpenCLProgramInfo &ProgramInfo,
834-
const GenXOCLRuntimeInfo::ModuleInfoT &ModuleInfo) {
834+
const GenXOCLRuntimeInfo::ModuleInfoT &ModuleInfo,
835+
bool HasCrossThreadOffsetRelocations) {
835836
auto ConstantAnnotation = getDataAnnotation<iOpenCL::InitConstantAnnotation>(
836837
ModuleInfo.Constant.Data);
837838
if (ConstantAnnotation)
@@ -866,16 +867,18 @@ fillOCLProgramInfo(IGC::SOpenCLProgramInfo &ProgramInfo,
866867
IGC_ASSERT_MESSAGE(
867868
ModuleInfo.ConstString.Relocations.empty(),
868869
"relocations inside constant string section are not supported");
870+
ProgramInfo.m_hasCrossThreadOffsetRelocations = HasCrossThreadOffsetRelocations;
869871
};
870872

871873
void vc::createBinary(
872874
vc::CGen8CMProgram &CMProgram,
873875
const GenXOCLRuntimeInfo::CompiledModuleT &CompiledModule) {
874-
fillOCLProgramInfo(*CMProgram.m_programInfo, CompiledModule.ModuleInfo);
875876
for (const GenXOCLRuntimeInfo::CompiledKernel &CompKernel :
876877
CompiledModule.Kernels) {
877878
auto K = std::make_unique<CMKernel>(CMProgram.getPlatform());
878879
fillKernelInfo(CompKernel, *K);
879880
CMProgram.m_kernels.push_back(std::move(K));
880881
}
882+
fillOCLProgramInfo(*CMProgram.m_programInfo, CompiledModule.ModuleInfo,
883+
CMProgram.HasCrossThreadOffsetRelocations());
881884
}

visa/Optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9027,7 +9027,7 @@ bool Optimizer::foldPseudoAndOr(G4_BB* bb, INST_LIST_ITER& ii)
90279027
auto addInst = builder.createBinOp(G4_add, g4::SIMD1, dst, src0, src1,
90289028
InstOpt_WriteEnable | InstOpt_NoCompact, false);
90299029
RelocationEntry::createRelocation(builder.kernel, *addInst,
9030-
1, "__INTEL_PATCH_CROSS_THREAD_OFFSET_OFF_R0", GenRelocType::R_SYM_ADDR_32);
9030+
1, CROSS_THREAD_OFF_R0_RELOCATION_NAME, GenRelocType::R_SYM_ADDR_32);
90319031
instBuffer.push_back(addInst);
90329032
};
90339033

visa/include/RelocationInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SPDX-License-Identifier: MIT
2121
namespace vISA {
2222

2323
static const uint32_t MAX_SYMBOL_NAME_LENGTH = 1024;
24+
constexpr const char* CROSS_THREAD_OFF_R0_RELOCATION_NAME = "__INTEL_PATCH_CROSS_THREAD_OFFSET_OFF_R0";
2425

2526
/// GenSymType - Specify the symbol's type
2627
enum GenSymType {

0 commit comments

Comments
 (0)