Skip to content

Commit 884fd4a

Browse files
DianaChenigcbot
authored andcommitted
IGC: Support relocation on cross_thread_data_size
In kernel's per-thread-load-payload, create a relocation for cross_thread_size (per_thread_payload_offset) in case of cross_thread_size is changed after compilation (e.g. gtpin inserted argument). The relocation can be resolved to the new cross_thread_size. - Add R_SYM_ADDR_16 relocation to support relocating mad's 16b imm source - Add relocation for cross_thread_size with symbol name "__INTEL_PER_THREAD_OFF" to indicate the usage of this relocation - Update ZEBinary spec
1 parent 563aeab commit 884fd4a

File tree

10 files changed

+52
-29
lines changed

10 files changed

+52
-29
lines changed

IGC/AdaptorOCL/OCL/sp/zebin_builder.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ void ZEBinaryBuilder::addRuntimeSymbols(const IGC::SOpenCLProgramInfo& annotatio
413413
if (annotations.m_hasCrossThreadOffsetRelocations)
414414
mBuilder.addSymbol(vISA::CROSS_THREAD_OFF_R0_RELOCATION_NAME, /*addr*/0, /*size*/0,
415415
llvm::ELF::STB_GLOBAL, llvm::ELF::STT_NOTYPE, /*sectionId*/-1);
416+
if (annotations.m_hasPerThreadOffsetRelocations)
417+
mBuilder.addSymbol(vISA::PER_THREAD_OFF_RELOCATION_NAME, /*addr*/0, /*size*/0,
418+
llvm::ELF::STB_GLOBAL, llvm::ELF::STT_NOTYPE, /*sectionId*/-1);
416419
}
417420

418421
void ZEBinaryBuilder::addProgramSymbols(const IGC::SOpenCLProgramInfo& annotations)
@@ -860,12 +863,12 @@ void ZEBinaryBuilder::addElfSections(void* elfBin, size_t elfSize)
860863
}
861864

862865
unsigned int relocType = relocEntry.r_info & 0xF;
863-
zebin::R_TYPE_ZEBIN zebinType = R_ZE_NONE;
866+
zebin::R_TYPE_ZEBIN zebinType = R_NONE;
864867

865868
if (relocType == ELF::R_X86_64_64)
866-
zebinType = R_ZE_SYM_ADDR;
869+
zebinType = R_SYM_ADDR;
867870
else if (relocType == ELF::R_X86_64_32)
868-
zebinType = R_ZE_SYM_ADDR_32;
871+
zebinType = R_SYM_ADDR_32;
869872
else
870873
IGC_ASSERT_MESSAGE(false, "Unsupported ELF relocation type");
871874

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6785,7 +6785,11 @@ namespace IGC
67856785
IGC_ASSERT(context->type == ShaderType::OPENCL_SHADER);
67866786
auto cl_context = static_cast<OpenCLProgramContext*>(context);
67876787
cl_context->m_programInfo.m_hasCrossThreadOffsetRelocations = true;
6788-
break;
6788+
}
6789+
else if (reloc.r_symbol == vISA::PER_THREAD_OFF_RELOCATION_NAME) {
6790+
IGC_ASSERT(context->type == ShaderType::OPENCL_SHADER);
6791+
auto cl_context = static_cast<OpenCLProgramContext*>(context);
6792+
cl_context->m_programInfo.m_hasPerThreadOffsetRelocations = true;
67896793
}
67906794
}
67916795
}

IGC/Compiler/CodeGenPublic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ namespace IGC
678678
LegacySymbolTable m_legacySymbolTable;
679679
ZEBinGlobalHostAccessTable m_zebinGlobalHostAccessTable;
680680
bool m_hasCrossThreadOffsetRelocations = false;
681+
bool m_hasPerThreadOffsetRelocations = false;
681682
};
682683

683684
class CBTILayout

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
@@ -241,7 +241,7 @@ struct zeInfoContainer
241241
KernelsMiscInfoTy kernels_misc_info;
242242
};
243243
struct PreDefinedAttrGetter{
244-
static zeinfo_str_t getVersionNumber() { return "1.43"; }
244+
static zeinfo_str_t getVersionNumber() { return "1.44"; }
245245

246246
enum class ArgThreadSchedulingMode {
247247
age_based,

IGC/ZEBinWriter/zebin/spec/elf.md

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

IGC/ZEBinWriter/zebin/spec/version.md

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

99
# ZEBIN Version
10-
Version 1.43
10+
Version 1.44
1111

1212
## Versioning
1313
Format: \<_Major number_\>.\<_Minor number_\>
1414
- Major number: Increase when non-backward-compatible features are added. For example, rename attributes or remove attributes.
1515
- Minor number: Increase when backward-compatible features are added. For example, add new attributes.
1616

1717
## Change Note
18+
- **Version 1.44**: Add relocation type "R_SYM_ADDR_16" and update supported relocation types.
1819
- **Version 1.43**: Internal changes.
1920
- **Version 1.42**: Enable is_ptr attribute in indirect payload arguments.
2021
- **Version 1.41**: Add intel_reqd_thread_group_dispatch_size to user_attributes.

visa/FlowGraph.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4580,6 +4580,15 @@ uint32_t RelocationEntry::getTargetOffset(const IR_Builder &builder) const {
45804580
vASSERT(opndPos == 1);
45814581
// Src1.imm[31:0] mapped to Instruction [127:96]
45824582
return 12;
4583+
case G4_mad:
4584+
vASSERT(relocType == R_SYM_ADDR_16);
4585+
// Src0.imm[15:0] mapped to Instruction [79:64]
4586+
// Src2.imm[15:0] mapped to Instruction [127:112]
4587+
if (opndPos == 1)
4588+
return 8;
4589+
else if (opndPos == 3)
4590+
return 14;
4591+
break;
45834592
case G4_send:
45844593
case G4_sendc:
45854594
case G4_sends:
@@ -4612,6 +4621,8 @@ const char *RelocationEntry::getTypeString(RelocationType relocType) {
46124621
return "R_GLOBAL_IMM_32";
46134622
case RelocationType::R_SEND:
46144623
return "R_SEND";
4624+
case RelocationType::R_SYM_ADDR_16:
4625+
return "R_SYM_ADDR_16";
46154626
default:
46164627
vISA_ASSERT_UNREACHABLE("unhandled relocation type");
46174628
return "??";

visa/PrologEpilog.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -887,24 +887,17 @@ class PayloadLoader
887887
// inserted argument), the relocation need to be resolved to the new
888888
// cross_thread_size.
889889
G4_Operand *addSrc1 =
890-
builder.createRelocImm(GenRelocType::R_PER_THREAD_PAYLOAD_OFFSET_32,
891-
kernel.getName(), perThreadOffsetMem, Type_UD);
890+
builder.createRelocImm(GenRelocType::R_SYM_ADDR_32,
891+
PER_THREAD_OFF_RELOCATION_NAME, perThreadOffsetMem, Type_UD);
892892
auto addDst = builder.createDst(rtmp->getRegVar(), 0, 2, 1, Type_UD);
893893
// instruction has relocation must not be compacted
894894
auto addInst =
895895
builder.createBinOp(G4_add, g4::SIMD1, addDst, addSrc0, addSrc1,
896896
InstOpt_WriteEnable | InstOpt_NoCompact, false);
897+
RelocationEntry::createRelocation(builder.kernel, *addInst, 1,
898+
PER_THREAD_OFF_RELOCATION_NAME,
899+
GenRelocType::R_SYM_ADDR_32);
897900

898-
// FIXME: before RT supports the R_PER_THREAD_PAYLOAD_OFFSET_32 relocation,
899-
// we create relocation only when GTPin option is given to avoid the test
900-
// failure. We can remove this option check once RT supports it.
901-
if (kernel.getOption(vISA_GetFreeGRFInfo)) {
902-
// Relocation with the target symbol set to kernel symbol. Note that
903-
// currently only ZEBinary will produce kernel symbols
904-
RelocationEntry::createRelocation(
905-
kernel, *addInst, 1, kernel.getName(),
906-
GenRelocType::R_PER_THREAD_PAYLOAD_OFFSET_32);
907-
}
908901
instBuffer.push_back(addInst);
909902

910903
if (kernel.getOption(vISA_emitCrossThreadOffR0Reloc)) {

visa/include/RelocationInfo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace vISA {
2424
static const uint32_t MAX_SYMBOL_NAME_LENGTH = 1024;
2525
constexpr const char *CROSS_THREAD_OFF_R0_RELOCATION_NAME =
2626
"__INTEL_PATCH_CROSS_THREAD_OFFSET_OFF_R0";
27+
constexpr const char *PER_THREAD_OFF_RELOCATION_NAME =
28+
"__INTEL_PER_THREAD_OFF";
2729

2830
/// GenSymType - Specify the symbol's type
2931
enum GenSymType {
@@ -53,9 +55,10 @@ enum GenRelocType {
5355
R_SYM_ADDR = 1, // 64-bit type address
5456
R_SYM_ADDR_32 = 2, // 32-bit address or lower 32-bit of a 64-bit address.
5557
R_SYM_ADDR_32_HI = 3, // higher 32 bits of 64-bit address
56-
R_PER_THREAD_PAYLOAD_OFFSET_32 = 4, // 32-bit offset of per-thread data
58+
R_PER_THREAD_PAYLOAD_OFFSET_32 = 4, // *** Deprecated. Do Not Use. ***
5759
R_GLOBAL_IMM_32 = 5, // 32-bit global immediate
58-
R_SEND = 6 // send instruction offset, used for BTI patching
60+
R_SEND = 6, // send instruction offset, used for BTI patching
61+
R_SYM_ADDR_16 = 7 // 16-bit address or immediate
5962
};
6063

6164
/// GenRelocEntry - An relocation table entry

0 commit comments

Comments
 (0)