Skip to content

Commit 204f6f0

Browse files
petechouigcbot
authored andcommitted
Reland ZEBIN: Add per-function zeinfo with name and execution env.
Provide the barrier count information and other required fields in execution env for each external function in .ze_info section.
1 parent b2cc01d commit 204f6f0

File tree

10 files changed

+112
-13
lines changed

10 files changed

+112
-13
lines changed

IGC/AdaptorOCL/OCL/sp/zebin_builder.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void ZEBinaryBuilder::createKernel(
8585
addPayloadArgsAndBTI(annotations, zeKernel);
8686
addMemoryBuffer(annotations, zeKernel);
8787
addGTPinInfo(annotations);
88+
addFunctionAttrs(annotations);
8889
if (!visaasm.empty())
8990
addKernelVISAAsm(annotations.m_kernelName, visaasm);
9091
if (isProgramDebuggable)
@@ -123,6 +124,29 @@ void ZEBinaryBuilder::addGTPinInfo(const IGC::SOpenCLKernelInfo& annotations)
123124
}
124125
}
125126

127+
void ZEBinaryBuilder::addFunctionAttrs(const IGC::SOpenCLKernelInfo& annotations)
128+
{
129+
// get function attribute list from the current process SKernelProgram
130+
auto funcAttrs = [](int simdSize, const IGC::SKernelProgram& program) {
131+
if (simdSize == 8)
132+
return program.simd8.m_funcAttrs;
133+
else if (simdSize == 16)
134+
return program.simd16.m_funcAttrs;
135+
else if (simdSize == 32)
136+
return program.simd32.m_funcAttrs;
137+
else
138+
return program.simd1.m_funcAttrs;
139+
} (annotations.m_executionEnivronment.CompiledSIMDSize,
140+
annotations.m_kernelProgram);
141+
142+
for (auto& funcAttr : funcAttrs) {
143+
if (!funcAttr.f_isKernel && funcAttr.f_isExternal) {
144+
zeInfoFunction& zeFunction = mZEInfoBuilder.createFunction(funcAttr.f_name);
145+
addFunctionExecEnv(annotations, funcAttr, zeFunction);
146+
}
147+
}
148+
}
149+
126150
void ZEBinaryBuilder::addProgramScopeInfo(const IGC::SOpenCLProgramInfo& programInfo)
127151
{
128152
addGlobalConstants(programInfo);
@@ -493,6 +517,18 @@ void ZEBinaryBuilder::addKernelExecEnv(const SOpenCLKernelInfo& annotations,
493517
}
494518
}
495519

520+
void ZEBinaryBuilder::addFunctionExecEnv(const SOpenCLKernelInfo& annotations,
521+
const vISA::ZEFuncAttribEntry& zeFuncAttr,
522+
zeInfoFunction& zeFunction)
523+
{
524+
// TODO: Currently we only set barrier count and other required information
525+
// such as GRF count and SIMD size in per-function execution environment.
526+
zeInfoExecutionEnv& env = zeFunction.execution_env;
527+
env.grf_count = annotations.m_executionEnivronment.NumGRFRequired;
528+
env.simd_size = annotations.m_executionEnivronment.CompiledSIMDSize;
529+
env.barrier_count = zeFuncAttr.f_BarrierCount;
530+
}
531+
496532
void ZEBinaryBuilder::addLocalIds(uint32_t simdSize, uint32_t grfSize,
497533
bool has_local_id_x, bool has_local_id_y, bool has_local_id_z,
498534
zebin::zeInfoKernel& zeinfoKernel)

IGC/AdaptorOCL/OCL/sp/zebin_builder.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace IGC
2525
namespace vISA
2626
{
2727
struct ZESymEntry;
28+
struct ZEFuncAttribEntry;
2829
}
2930

3031
namespace iOpenCL
@@ -110,10 +111,15 @@ class ZEBinaryBuilder : DisallowCopy
110111
const std::string& kernelName, const char* kernelBinary,
111112
unsigned int kernelBinarySize);
112113

113-
/// add execution environment
114+
/// add kernel execution environment
114115
void addKernelExecEnv(const IGC::SOpenCLKernelInfo& annotations,
115116
zebin::zeInfoKernel& zeinfoKernel);
116117

118+
/// add execution environment for external function
119+
void addFunctionExecEnv(const IGC::SOpenCLKernelInfo& annotations,
120+
const vISA::ZEFuncAttribEntry& zeFuncAttr,
121+
zebin::zeInfoFunction& zeFunction);
122+
117123
/// add experimental properties
118124
void addKernelExperimentalProperties(const IGC::SOpenCLKernelInfo& annotations,
119125
zebin::zeInfoKernel& zeinfoKernel);
@@ -160,6 +166,9 @@ class ZEBinaryBuilder : DisallowCopy
160166
/// into gtpin_info section
161167
void addGTPinInfo(const IGC::SOpenCLKernelInfo& annotations);
162168

169+
/// Add function attributes for external functions.
170+
void addFunctionAttrs(const IGC::SOpenCLKernelInfo& annotations);
171+
163172
/// ------------ Verifier sub-functions ------------
164173
bool hasSystemKernel(
165174
const IGC::OpenCLProgramContext* clContext,

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5629,7 +5629,10 @@ namespace IGC
56295629
visaFunc->GetJitInfo(jitInfo);
56305630
entry.f_spillMemPerThread = jitInfo->spillMemUsed;
56315631

5632-
attrs.emplace_back(entry.f_isKernel, entry.f_hasBarrier, entry.f_privateMemPerThread,
5632+
uint8_t isExternal = F->hasFnAttribute("referenced-indirectly") ? 1 : 0;
5633+
// Set per-function barrier count from vISA information.
5634+
uint32_t barrierCnt = jitInfo->usesBarrier;
5635+
attrs.emplace_back(entry.f_isKernel, isExternal, barrierCnt, entry.f_privateMemPerThread,
56335636
entry.f_spillMemPerThread, F->getName().str());
56345637
attribTable.push_back(entry);
56355638
}
@@ -6230,7 +6233,7 @@ namespace IGC
62306233
pOutput->m_funcRelocationTableEntries);
62316234
}
62326235

6233-
if (IGC_IS_FLAG_ENABLED(EnableRuntimeFuncAttributePatching))
6236+
if (IGC_IS_FLAG_ENABLED(EnableRuntimeFuncAttributePatching) || ZEBinEnabled)
62346237
{
62356238
CreateFuncAttributeTable(pOutput->m_funcAttributeTable,
62366239
pOutput->m_funcAttributeTableSize,

IGC/ZEBinWriter/zebin/source/ZEELFObjectBuilder.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,15 @@ zeInfoKernel& ZEInfoBuilder::createKernel(const std::string& name)
942942
return k;
943943
}
944944

945+
// createFunction - create a zeInfoFunction and add it into zeInfoContainer
946+
zeInfoFunction& ZEInfoBuilder::createFunction(const std::string& name)
947+
{
948+
mContainer.functions.emplace_back();
949+
zeInfoFunction& f = mContainer.functions.back();
950+
f.name = name;
951+
return f;
952+
}
953+
945954
bool ZEInfoBuilder::empty() const
946955
{
947956
return mContainer.kernels.empty();

IGC/ZEBinWriter/zebin/source/ZEELFObjectBuilder.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ class ZEInfoBuilder {
395395
// createKernel - create a zeInfoKernel and add it into zeInfoContainer
396396
zeInfoKernel& createKernel(const std::string& name);
397397

398+
// createFunction - create a zeInfoFunction and add it into zeInfoContainer
399+
zeInfoFunction& createFunction(const std::string& name);
400+
398401
// addGlobalHostAccessSymbol - create a zeInfo global_host_access_table section
399402
// which is used by Runtime to identify a global variable based on host name
400403
void addGlobalHostAccessSymbol(const std::string& device_name, const std::string& host_name);

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ typedef std::vector<zeInfoBindingTableIndex> BindingTableIndicesTy;
138138
typedef std::vector<zeInfoPerThreadMemoryBuffer> PerThreadMemoryBuffersTy;
139139
struct zeInfoKernel
140140
{
141+
bool operator==(const zeInfoKernel& other) const
142+
{
143+
return name == other.name && execution_env == other.execution_env && payload_arguments == other.payload_arguments && per_thread_payload_arguments == other.per_thread_payload_arguments && binding_table_indices == other.binding_table_indices && per_thread_memory_buffers == other.per_thread_memory_buffers && experimental_properties == other.experimental_properties && debug_env == other.debug_env;
144+
}
141145
zeinfo_str_t name;
142146
zeInfoExecutionEnv execution_env;
143147
PayloadArgumentsTy payload_arguments;
@@ -147,16 +151,31 @@ struct zeInfoKernel
147151
zeInfoExperimentalProperties experimental_properties;
148152
zeInfoDebugEnv debug_env;
149153
};
154+
struct zeInfoFunction
155+
{
156+
bool operator==(const zeInfoFunction& other) const
157+
{
158+
return name == other.name && execution_env == other.execution_env;
159+
}
160+
zeinfo_str_t name;
161+
zeInfoExecutionEnv execution_env;
162+
};
150163
typedef std::vector<zeInfoKernel> KernelsTy;
164+
typedef std::vector<zeInfoFunction> FunctionsTy;
151165
typedef std::vector<zeInfoHostAccess> HostAccessesTy;
152166
struct zeInfoContainer
153167
{
168+
bool operator==(const zeInfoContainer& other) const
169+
{
170+
return version == other.version && kernels == other.kernels && functions == other.functions && global_host_access_table == other.global_host_access_table;
171+
}
154172
zeinfo_str_t version;
155173
KernelsTy kernels;
174+
FunctionsTy functions;
156175
HostAccessesTy global_host_access_table;
157176
};
158177
struct PreDefinedAttrGetter{
159-
static zeinfo_str_t getVersionNumber() { return "1.12"; }
178+
static zeinfo_str_t getVersionNumber() { return "1.13"; }
160179

161180
enum class ArgThreadSchedulingMode {
162181
age_based,

IGC/ZEBinWriter/zebin/source/autogen/ZEInfoYAML.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void MappingTraits<zeInfoContainer>::mapping(IO& io, zeInfoContainer& info)
2323
{
2424
io.mapRequired("version", info.version);
2525
io.mapRequired("kernels", info.kernels);
26+
io.mapOptional("functions", info.functions, FunctionsTy());
2627
io.mapOptional("global_host_access_table", info.global_host_access_table, HostAccessesTy());
2728
}
2829
void MappingTraits<zeInfoKernel>::mapping(IO& io, zeInfoKernel& info)
@@ -36,6 +37,11 @@ void MappingTraits<zeInfoKernel>::mapping(IO& io, zeInfoKernel& info)
3637
io.mapOptional("experimental_properties", info.experimental_properties, zeInfoExperimentalProperties());
3738
io.mapOptional("debug_env", info.debug_env, zeInfoDebugEnv());
3839
}
40+
void MappingTraits<zeInfoFunction>::mapping(IO& io, zeInfoFunction& info)
41+
{
42+
io.mapRequired("name", info.name);
43+
io.mapRequired("execution_env", info.execution_env);
44+
}
3945
void MappingTraits<zeInfoExecutionEnv>::mapping(IO& io, zeInfoExecutionEnv& info)
4046
{
4147
io.mapOptional("barrier_count", info.barrier_count, 0);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ SPDX-License-Identifier: MIT
3030
#include "common/LLVMWarningsPop.hpp"
3131
#endif
3232
LLVM_YAML_IS_SEQUENCE_VECTOR(zebin::zeInfoKernel)
33+
LLVM_YAML_IS_SEQUENCE_VECTOR(zebin::zeInfoFunction)
3334
LLVM_YAML_IS_SEQUENCE_VECTOR(zebin::zeInfoPayloadArgument)
3435
LLVM_YAML_IS_SEQUENCE_VECTOR(zebin::zeInfoPerThreadPayloadArgument)
3536
LLVM_YAML_IS_SEQUENCE_VECTOR(zebin::zeInfoBindingTableIndex)
@@ -46,6 +47,10 @@ namespace llvm {
4647
static void mapping(IO& io, zebin::zeInfoKernel& info);
4748
};
4849
template<>
50+
struct MappingTraits<zebin::zeInfoFunction> {
51+
static void mapping(IO& io, zebin::zeInfoFunction& info);
52+
};
53+
template<>
4954
struct MappingTraits<zebin::zeInfoExecutionEnv> {
5055
static void mapping(IO& io, zebin::zeInfoExecutionEnv& info);
5156
};

IGC/ZEBinWriter/zebin/spec/zeinfo.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SPDX-License-Identifier: MIT
77
============================= end_copyright_notice ==========================-->
88

99
# ZE Info
10-
Version 1.12
10+
Version 1.13
1111

1212
## Grammar
1313

@@ -35,6 +35,7 @@ All **literals** have one of the following types:
3535
| ----- | ----- | ----- | ----- |
3636
| version | str | Required | ZE Info version number. See Version above. |
3737
| kernels | KernelsTy | Required | vector |
38+
| functions | FunctionsTy | Optional | vector |
3839
| global_host_access_table | HostAccessesTy | Optional | vector |
3940
<!--- Container --->
4041

@@ -66,15 +67,20 @@ functions:
6667
attribute_seq
6768
~~~
6869

70+
| Attribute | Type | Required/Optional | Description |
71+
| ----- | ----- | ------ | ----- |
72+
| name | str | Required | |
73+
| execution_env | ExecutionEnv | Required | |
74+
<!--- Function Functions --->
75+
6976
Function attribute represents a non-kernel function's information. A ze_info
7077
section may contains more than one function's attributes, each is
7178
represented in a function attribute. The name attribute in function represent the
72-
kernel's name.
79+
function name.
7380

74-
Function attributes may only present when the function can be externally or
75-
indirectly called.
81+
Function attributes may only present when the function can be externally called.
7682

77-
The attributes that are supported in function are: **name** and **Memory Buffer**.
83+
The attributes that are supported in function are: **name** and **Execution Environment**.
7884

7985
## Execution Environment
8086

@@ -293,6 +299,7 @@ Format: \<_Major number_\>.\<_Minor number_\>
293299
- Minor number: Increase when backward-compatible features are added. For example, add new attributes.
294300

295301
## Change Note
302+
- **Version 1.13**: Add functions with the name and execution env.
296303
- **Version 1.12**: Add global_host_access_table to container.
297304
- **Version 1.11**: Add require_disable_eufusion attribute.
298305
- **Version 1.10**: Add thread_scheduling_mode to execution_env.

visa/include/RelocationInfo.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,17 @@ struct ZERelocEntry {
109109
/// ZEFuncAttribEntry - A function attribute entry that will later be transformed to ZE binary format
110110
struct ZEFuncAttribEntry {
111111
uint8_t f_isKernel; // Is the function a kernel
112-
uint8_t f_hasBarrier; // Does the function use barriers
112+
uint8_t f_isExternal; // Is the function external
113+
uint32_t f_BarrierCount; // Number of barriers used by the function
113114
uint32_t f_privateMemPerThread; // Total private memory (in bytes) used by this function per thread
114115
uint32_t f_spillMemPerThread; // Spill mem used (in bytes) in scratch space for this function
115116
std::string f_name; // The function's name
116117

117-
ZEFuncAttribEntry(uint8_t isKernel, uint8_t hasBarrier, uint32_t privateMemPerThread,
118-
uint32_t spillMemPerThread, std::string funcName)
118+
ZEFuncAttribEntry(uint8_t isKernel, uint8_t isExternal, uint32_t barrierCount,
119+
uint32_t privateMemPerThread, uint32_t spillMemPerThread, std::string funcName)
119120
: f_isKernel(isKernel),
120-
f_hasBarrier(hasBarrier),
121+
f_isExternal(isExternal),
122+
f_BarrierCount(barrierCount),
121123
f_privateMemPerThread(privateMemPerThread),
122124
f_spillMemPerThread(spillMemPerThread),
123125
f_name(funcName)

0 commit comments

Comments
 (0)