Skip to content

Commit e31c8e9

Browse files
igorban-inteligcbot
authored andcommitted
Emit predefined runtime symbol to ZEBinary's symbol table
.
1 parent 77d6042 commit e31c8e9

File tree

13 files changed

+76
-32
lines changed

13 files changed

+76
-32
lines changed

IGC/AdaptorOCL/OCL/sp/zebin_builder.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ void ZEBinaryBuilder::addRuntimeSymbols(const IGC::SOpenCLProgramInfo& annotatio
420420
if (annotations.m_hasCrossThreadOffsetRelocations)
421421
mBuilder.addSymbol(vISA::CROSS_THREAD_OFF_R0_RELOCATION_NAME, /*addr*/0, /*size*/0,
422422
llvm::ELF::STB_GLOBAL, llvm::ELF::STT_NOTYPE, /*sectionId*/-1);
423+
if (annotations.m_hasPerThreadOffsetRelocations)
424+
mBuilder.addSymbol(vISA::PER_THREAD_OFF_RELOCATION_NAME, /*addr*/0, /*size*/0,
425+
llvm::ELF::STB_GLOBAL, llvm::ELF::STT_NOTYPE, /*sectionId*/-1);
423426
}
424427

425428
void ZEBinaryBuilder::addProgramSymbols(const IGC::SOpenCLProgramInfo& annotations)
@@ -883,12 +886,12 @@ void ZEBinaryBuilder::addElfSections(void* elfBin, size_t elfSize)
883886
}
884887

885888
unsigned int relocType = relocEntry.r_info & 0xF;
886-
zebin::R_TYPE_ZEBIN zebinType = R_ZE_NONE;
889+
zebin::R_TYPE_ZEBIN zebinType = R_NONE;
887890

888891
if (relocType == ELF::R_X86_64_64)
889-
zebinType = R_ZE_SYM_ADDR;
892+
zebinType = R_SYM_ADDR;
890893
else if (relocType == ELF::R_X86_64_32)
891-
zebinType = R_ZE_SYM_ADDR_32;
894+
zebinType = R_SYM_ADDR_32;
892895
else
893896
IGC_ASSERT_MESSAGE(false, "Unsupported ELF relocation type");
894897

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6866,7 +6866,11 @@ namespace IGC
68666866
IGC_ASSERT(context->type == ShaderType::OPENCL_SHADER);
68676867
auto cl_context = static_cast<OpenCLProgramContext*>(context);
68686868
cl_context->m_programInfo.m_hasCrossThreadOffsetRelocations = true;
6869-
break;
6869+
}
6870+
else if (reloc.r_symbol == vISA::PER_THREAD_OFF_RELOCATION_NAME) {
6871+
IGC_ASSERT(context->type == ShaderType::OPENCL_SHADER);
6872+
auto cl_context = static_cast<OpenCLProgramContext*>(context);
6873+
cl_context->m_programInfo.m_hasPerThreadOffsetRelocations = true;
68706874
}
68716875
}
68726876
}

IGC/Compiler/CodeGenPublic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ namespace IGC
692692
LegacySymbolTable m_legacySymbolTable;
693693
ZEBinGlobalHostAccessTable m_zebinGlobalHostAccessTable;
694694
bool m_hasCrossThreadOffsetRelocations = false;
695+
bool m_hasPerThreadOffsetRelocations = false;
695696
};
696697

697698
class CBTILayout

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class CGen8CMProgram : public iOpenCL::CGen8OpenCLProgramBase {
147147
unsigned pointerSizeInBytes) override;
148148
bool HasErrors() const { return !m_ErrorLog.empty(); };
149149
bool HasCrossThreadOffsetRelocations();
150+
bool HasPerThreadOffsetRelocations();
150151
llvm::Error GetError() const;
151152

152153
// CM kernel list.

IGC/VectorCompiler/igcdeps/src/PatchTokens.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,14 @@ bool CGen8CMProgram::HasCrossThreadOffsetRelocations() {
236236
}
237237
return false;
238238
}
239+
240+
bool CGen8CMProgram::HasPerThreadOffsetRelocations() {
241+
for (const auto &kernel : m_kernels) {
242+
for (const auto &reloc : kernel->getProgramOutput().m_relocs) {
243+
if (reloc.r_symbol == vISA::PER_THREAD_OFF_RELOCATION_NAME) {
244+
return true;
245+
}
246+
}
247+
}
248+
return false;
249+
}

IGC/VectorCompiler/igcdeps/src/cmc.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,8 @@ getDataAnnotation(const GenXOCLRuntimeInfo::DataInfo &Data) {
997997
static void
998998
fillOCLProgramInfo(IGC::SOpenCLProgramInfo &ProgramInfo,
999999
const GenXOCLRuntimeInfo::ModuleInfoT &ModuleInfo,
1000-
bool HasCrossThreadOffsetRelocations) {
1000+
bool HasCrossThreadOffsetRelocations,
1001+
bool HasPerThreadOffsetRelocations) {
10011002
auto ConstantAnnotation = getDataAnnotation<iOpenCL::InitConstantAnnotation>(
10021003
ModuleInfo.Constant.Data);
10031004
if (ConstantAnnotation)
@@ -1033,6 +1034,7 @@ fillOCLProgramInfo(IGC::SOpenCLProgramInfo &ProgramInfo,
10331034
ModuleInfo.ConstString.Relocations.empty(),
10341035
"relocations inside constant string section are not supported");
10351036
ProgramInfo.m_hasCrossThreadOffsetRelocations = HasCrossThreadOffsetRelocations;
1037+
ProgramInfo.m_hasPerThreadOffsetRelocations = HasPerThreadOffsetRelocations;
10361038
};
10371039

10381040
void vc::createBinary(
@@ -1045,5 +1047,6 @@ void vc::createBinary(
10451047
CMProgram.m_kernels.push_back(std::move(K));
10461048
}
10471049
fillOCLProgramInfo(*CMProgram.m_programInfo, CompiledModule.ModuleInfo,
1048-
CMProgram.HasCrossThreadOffsetRelocations());
1050+
CMProgram.HasCrossThreadOffsetRelocations(),
1051+
CMProgram.HasPerThreadOffsetRelocations());
10491052
}

IGC/ZEBinWriter/zebin/source/ZEELF.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ enum SHT_ZEBIN : uint32_t
4141
// ELF relocation type for ELF32_Rel::ELF32_R_TYPE
4242
enum R_TYPE_ZEBIN
4343
{
44-
R_ZE_NONE = 0,
45-
R_ZE_SYM_ADDR = 1, // 64-bit type address
46-
R_ZE_SYM_ADDR_32 = 2, // lower 32-bit of 64-bit address.
47-
R_ZE_SYM_ADDR_32_HI = 3 // higher 32bits of 64-bit address
44+
R_NONE = 0,
45+
R_SYM_ADDR = 1, // 64-bit type address
46+
R_SYM_ADDR_32 = 2, // 32-bit address or lower 32-bit of a 64-bit address.
47+
R_SYM_ADDR_32_HI = 3, // higher 32 bits of 64-bit address
48+
R_PER_THREAD_PAYLOAD_OFFSET_32 = 4, // *** Deprecated. Do Not Use. ***
49+
R_GLOBAL_IMM_32 = 5, // 32-bit global immediate
50+
R_SEND = 6, // send instruction offset, used for BTI patching
51+
R_SYM_ADDR_16 = 7 // 16-bit address or immediate
4852
};
4953

5054
// ELF note type for INTELGT

IGC/ZEBinWriter/zebin/source/autogen/ZEInfo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ struct zeInfoContainer
290290
KernelsCostInfoTy kernels_cost_info;
291291
};
292292
struct PreDefinedAttrGetter{
293-
static zeinfo_str_t getVersionNumber() { return "1.49"; }
293+
static zeinfo_str_t getVersionNumber() { return "1.48"; }
294294

295295
enum class ArgThreadSchedulingMode {
296296
age_based,

IGC/ZEBinWriter/zebin/spec/elf.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,14 @@ lower than 2.
222222
Relocation type for **ELF32_R_TYPE** or **ELF64_R_TYPE**
223223
~~~
224224
enum GenRelocType {
225-
R_ZE_NONE = 0,
226-
R_ZE_SYM_ADDR = 1, // 64-bit address
227-
R_ZE_SYM_ADDR_32 = 2, // 32-bit address or lower 32-bit of a 64-bit address
228-
R_ZE_SYM_ADDR_32_HI = 3 // higher 32bits of a 64-bit address
229-
R_PER_THREAD_PAYLOAD_OFFSET_32 = 4 // 32-bit field of payload offset of per-thread data
225+
R_NONE = 0,
226+
R_SYM_ADDR = 1, // 64-bit address
227+
R_SYM_ADDR_32 = 2, // 32-bit address or lower 32-bit of a 64-bit address
228+
R_SYM_ADDR_32_HI = 3 // higher 32bits of a 64-bit address
229+
R_PER_THREAD_PAYLOAD_OFFSET_32 = 4, // *** Deprecated ***
230+
R_GLOBAL_IMM_32 = 5, // 32-bit global immediate
231+
R_SEND = 6, // send instruction offset, used for BTI patching
232+
R_SYM_ADDR_16 = 7 // 16-bit address or immediate
230233
};
231234
~~~
232235

IGC/ZEBinWriter/zebin/spec/version.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ SPDX-License-Identifier: MIT
77
============================= end_copyright_notice ==========================-->
88

99
# ZEBIN Version
10-
Version 1.47
10+
Version 1.48
11+
=======
1112

1213
## Versioning
1314
Format: \<_Major number_\>.\<_Minor number_\>
1415
- Major number: Increase when non-backward-compatible features are added. For example, rename attributes or remove attributes.
1516
- Minor number: Increase when backward-compatible features are added. For example, add new attributes.
1617

1718
## Change Note
19+
- **Version 1.48**: Add relocation type "R_SYM_ADDR_16" and update supported relocation types.
1820
- **Version 1.47**: Added kernel cost analysis.
1921
- **Version 1.46**: Change cmake target directory from IGC/zebinlib to IGC/Libraries/zebinlib
2022
- **Version 1.45**: Add .text section into ELF section content.

0 commit comments

Comments
 (0)