Skip to content

Commit 242dc4a

Browse files
DianaChenigcbot
authored andcommitted
ZEBinary printf support
- create symbols for string literals those defined in .data.const.string - Spec update: add new payload_argument type "printf_buffer" for implicit argument printf buffer
1 parent c329596 commit 242dc4a

File tree

6 files changed

+42
-15
lines changed

6 files changed

+42
-15
lines changed

IGC/AdaptorOCL/OCL/sp/zebin_builder.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ void ZEBinaryBuilder::addGlobalConstants(const IGC::SOpenCLProgramInfo& annotati
137137
return;
138138

139139
// create a data section for global constant variables
140-
// Two constant data sections: general constants and string literals
141-
IGC_ASSERT(annotations.m_initConstantAnnotation.size() >= 1);
140+
// There could be two constant data sections: general constants and string literals
142141

143142
// General constants
144143
// create a data section for global constant variables
@@ -177,9 +176,12 @@ void ZEBinaryBuilder::addGlobalConstants(const IGC::SOpenCLProgramInfo& annotati
177176
}
178177
}
179178

180-
if (annotations.m_initConstantAnnotation.size() != 2)
179+
if (annotations.m_initConstantAnnotation.size() < 2)
181180
return;
182181

182+
// At most two const global buffers: general and string literals
183+
IGC_ASSERT(annotations.m_initConstantAnnotation.size() == 2);
184+
183185
// String literals
184186
auto& caString = annotations.m_initConstantAnnotation[1];
185187
if (caString->InlineData.size() > 0)
@@ -392,6 +394,12 @@ void ZEBinaryBuilder::addSymbols(
392394
getSymbolElfBinding(sym), getSymbolElfType(sym),
393395
(sym.s_type == vISA::GenSymType::S_UNDEF) ? -1 : mGlobalConstSectID);
394396

397+
// add symbols defined in global string constant section
398+
for (auto sym : symbols.globalStringConst)
399+
mBuilder.addSymbol(sym.s_name, sym.s_offset, sym.s_size,
400+
getSymbolElfBinding(sym), getSymbolElfType(sym),
401+
(sym.s_type == vISA::GenSymType::S_UNDEF) ? -1 : mConstStringSectID);
402+
395403
// add symbols defined in global section
396404
for (auto sym : symbols.global)
397405
mBuilder.addSymbol(sym.s_name, sym.s_offset, sym.s_size,

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4865,12 +4865,20 @@ namespace IGC
48654865
sEntry.s_size = int_cast<uint32_t>(pModule->getDataLayout().getTypeAllocSize(pGlobal->getType()->getPointerElementType()));
48664866
sEntry.s_offset = static_cast<uint32_t>(global.second);
48674867
// symbols for ZEBinary
4868-
if (sEntry.s_type == vISA::GenSymType::S_GLOBAL_VAR)
4868+
if (sEntry.s_type == vISA::GenSymType::S_GLOBAL_VAR) {
48694869
symbols.global.emplace_back((vISA::GenSymType)sEntry.s_type,
48704870
sEntry.s_offset, sEntry.s_size, name.str());
4871-
else
4872-
symbols.globalConst.emplace_back((vISA::GenSymType)sEntry.s_type,
4873-
sEntry.s_offset, sEntry.s_size, name.str());
4871+
} else {
4872+
// Global constants and string literals
4873+
Constant * initializer = pGlobal->getInitializer();
4874+
ConstantDataSequential * cds = dyn_cast<ConstantDataSequential>(initializer);
4875+
if (cds && (cds->isCString() || cds->isString()))
4876+
symbols.globalStringConst.emplace_back((vISA::GenSymType)sEntry.s_type,
4877+
sEntry.s_offset, sEntry.s_size, name.str());
4878+
else
4879+
symbols.globalConst.emplace_back((vISA::GenSymType)sEntry.s_type,
4880+
sEntry.s_offset, sEntry.s_size, name.str());
4881+
}
48744882
}
48754883
symbolTable.push_back(sEntry);
48764884
}

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ namespace IGC
490490
{
491491
switch (kernelArg->getArgType()) {
492492

493-
// Implicit args
494493
case KernelArg::ArgType::IMPLICIT_PAYLOAD_HEADER:{
495494
// PayloadHeader contains global work offset x,y,z and local size x,y,z
496495
// global work offset, size is int32x3
@@ -701,6 +700,12 @@ namespace IGC
701700
}
702701
break;
703702

703+
case KernelArg::ArgType::IMPLICIT_PRINTF_BUFFER:
704+
zebin::ZEInfoBuilder::addPayloadArgumentImplicit(m_kernelInfo.m_zePayloadArgs,
705+
zebin::PreDefinedAttrGetter::ArgType::printf_buffer,
706+
payloadPosition, kernelArg->getAllocateSize());
707+
break;
708+
704709
// We don't need these in ZEBinary, can safely skip them
705710
case KernelArg::ArgType::IMPLICIT_R0:
706711
case KernelArg::ArgType::R1:

IGC/Compiler/CodeGenPublic.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ namespace IGC
9595
typedef std::vector<vISA::ZERelocEntry> RelocListTy;
9696
typedef std::vector<vISA::ZEFuncAttribEntry> FuncAttrListTy;
9797
struct SymbolLists {
98-
SymbolListTy function; // function symbols
99-
SymbolListTy global; // global symbols
100-
SymbolListTy globalConst; // global constant symbols
101-
SymbolListTy sampler; // sampler symbols
102-
SymbolListTy local; // local symbols
98+
SymbolListTy function; // function symbols
99+
SymbolListTy global; // global symbols
100+
SymbolListTy globalConst; // global constant symbols
101+
SymbolListTy globalStringConst; // global string constant symbols
102+
SymbolListTy sampler; // sampler symbols
103+
SymbolListTy local; // local symbols
103104
};
104105

105106
public:

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct zeInfoContainer
122122
KernelsTy kernels;
123123
};
124124
struct PreDefinedAttrGetter{
125-
static zeinfo_str_t getVersionNumber() { return "1.2"; }
125+
static zeinfo_str_t getVersionNumber() { return "1.3"; }
126126

127127
enum class ArgType {
128128
packed_local_ids,
@@ -134,6 +134,7 @@ struct PreDefinedAttrGetter{
134134
global_id_offset,
135135
private_base_stateless,
136136
buffer_offset,
137+
printf_buffer,
137138
arg_byvalue,
138139
arg_bypointer
139140
};
@@ -185,6 +186,8 @@ struct PreDefinedAttrGetter{
185186
return "private_base_stateless";
186187
case ArgType::buffer_offset:
187188
return "buffer_offset";
189+
case ArgType::printf_buffer:
190+
return "printf_buffer";
188191
case ArgType::arg_byvalue:
189192
return "arg_byvalue";
190193
case ArgType::arg_bypointer:

IGC/ZEBinWriter/zebin/spec/zeinfo.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ IN THE SOFTWARE.
2323
============================= end_copyright_notice ==========================-->
2424

2525
# ZE Info
26-
Version 1.2
26+
Version 1.3
2727

2828
## Grammar
2929

@@ -157,6 +157,7 @@ Supported <argument_type> of payload_arguments or per_thread_payload_arguments.
157157
| global_id_offset | int32x3 | |
158158
| private_base_stateless | int64 | The base address of private buffer specified at per_thread_memory_buffers |
159159
| buffer_offset | | The extra offset for buffer reference to satisfy the alignment requirement of stateful memory access. |
160+
| printf_buffer | | The address of printf_buffer which holds the prtinf strings information. |
160161
| arg_byvalue | | Explicit kernel argument |
161162
| arg_bypointer | | Explicit kernel argument |
162163
<!--- <argument_type> ArgType -->
@@ -269,6 +270,7 @@ Format: \<_Major number_\>.\<_Minor number_\>
269270
- Minor number: Increase when backward-compatible features are added. For example, add new attributes.
270271

271272
## Change Note
273+
- **Version 1.3**: Add printf_buffer to argument_type.
272274
- **Version 1.2**: Add buffer_offset to argument_type.
273275
- **Version 1.1**: Add experimental_properties to kernel.
274276
- **Version 1.0**: Add version number. Add slot to per_thread_memory_buffers. Rename shared_local_memory to slm in memory_addressing_mode.

0 commit comments

Comments
 (0)