Skip to content

Commit 08fca25

Browse files
pkwasnie-intelmnaczk
authored andcommitted
ZEBinary: support implicit arguments const_base and global_base
Allow accessing global and constant variables through implicit arguments const_base and global_base, for kernel only. Before this change, global and constant must be accessed through relocations in ZEBinary path. This prevent them from promoting to BTI at StatelessToSateful pass. ZEBinary spec update: - add new payload_argument types: const_base and global_base - add bit_value to payload_argument for representing const and global buffers' bti index if promoted.
1 parent 8d3e368 commit 08fca25

File tree

7 files changed

+53
-34
lines changed

7 files changed

+53
-34
lines changed

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,18 +1660,31 @@ namespace IGC
16601660
payloadPosition, kernelArg->getAllocateSize());
16611661
break;
16621662

1663+
case KernelArg::ArgType::IMPLICIT_CONSTANT_BASE:
1664+
case KernelArg::ArgType::IMPLICIT_GLOBAL_BASE: {
1665+
auto zeArgType =
1666+
kernelArg->getArgType() ==
1667+
KernelArg::ArgType::IMPLICIT_CONSTANT_BASE
1668+
? zebin::PreDefinedAttrGetter::ArgType::const_base
1669+
: zebin::PreDefinedAttrGetter::ArgType::global_base;
1670+
zebin::zeInfoPayloadArgument &arg =
1671+
zebin::ZEInfoBuilder::addPayloadArgumentImplicit(
1672+
m_kernelInfo.m_zePayloadArgs, zeArgType, payloadPosition,
1673+
kernelArg->getAllocateSize());
1674+
SOpenCLKernelInfo::SResourceInfo resInfo =
1675+
getResourceInfo(kernelArg->getAssociatedArgNo());
1676+
unsigned btiValue = getBTI(resInfo);
1677+
if (btiValue != 0xffffffff)
1678+
arg.bti_value = btiValue;
1679+
break;
1680+
}
1681+
16631682
// We don't need these in ZEBinary, can safely skip them
16641683
case KernelArg::ArgType::IMPLICIT_R0:
16651684
case KernelArg::ArgType::R1:
16661685
case KernelArg::ArgType::STRUCT:
16671686
break;
16681687

1669-
// FIXME: should these be supported?
1670-
// CONSTANT_BASE and GLOBAL_BASE are not required that we should export
1671-
// all globals and constants and let the runtime relocate them when enabling
1672-
// ZEBinary
1673-
case KernelArg::ArgType::IMPLICIT_CONSTANT_BASE:
1674-
case KernelArg::ArgType::IMPLICIT_GLOBAL_BASE:
16751688
case KernelArg::ArgType::IMPLICIT_STAGE_IN_GRID_ORIGIN:
16761689
case KernelArg::ArgType::IMPLICIT_STAGE_IN_GRID_SIZE:
16771690
default:

IGC/Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantAnalysis.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -248,26 +248,26 @@ bool ProgramScopeConstantAnalysis::runOnModule(Module& M)
248248
IGC::appendToUsed(M, globalArray);
249249
}
250250

251-
// Check if zebin is enabled
252-
bool zebinEnable = Ctx->enableZEBinary();
253-
254-
// patch-token-path:
255-
// Just add the implicit argument to each function if a constant
256-
// buffer has been created. This will technically burn a patch
257-
// token on kernels that don't actually use the buffer but it saves
258-
// us having to walk the def-use chain (we can't just check if a
259-
// constant is used in the kernel; for example, a global buffer
260-
// may contain pointers that in turn point into the constant
261-
// address space).
262-
// zebinary path:
263-
// Don't add the implicit arguments and rely solely on relocations
264-
// for global variable reference since the implicit arguments were
265-
// removed from zebinary.
266-
if (!zebinEnable && hasInlineConstantBuffer)
251+
// Kernels and Subroutines:
252+
// Add the implicit arg to the function argument list if a constant buffer is created and there
253+
// is no stack calls
254+
//
255+
// Stackcalls:
256+
// Stackcall ABI does not allow implicit args, so rely on relocation for global variable access
257+
258+
// Workaround: When there is stringConstants in the module, do not insert
259+
// implicit arguments to prevent const vars getting promoted
260+
// at statelessToStateful pass. In zebin path, stateful promotion
261+
// of const vars can't work well with printf strings.
262+
bool skipConstBuffer =
263+
Ctx->enableZEBinary() && !m_pModuleMd->stringConstants.empty();
264+
265+
if (!skipConstBuffer && hasInlineConstantBuffer)
267266
{
268267
for (auto& pFunc : M)
269268
{
270269
if (pFunc.isDeclaration()) continue;
270+
271271
// Skip functions called from function marked with stackcall attribute
272272
if (AddImplicitArgs::hasStackCallInCG(&pFunc, *Ctx)) continue;
273273

@@ -278,7 +278,7 @@ bool ProgramScopeConstantAnalysis::runOnModule(Module& M)
278278
}
279279
}
280280

281-
if (!zebinEnable && hasInlineGlobalBuffer)
281+
if (hasInlineGlobalBuffer)
282282
{
283283
for (auto& pFunc : M)
284284
{

IGC/Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantResolution.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ bool ProgramScopeConstantResolution::runOnModule(Module& M)
7979
return false;
8080
}
8181

82-
if (pCtx->enableZEBinary())
83-
{
84-
// ZEBinary always relies on relocation, so we can ignore this pass
85-
return false;
86-
}
87-
88-
8982
if (RunCautiously) {
9083
if (!needRunConservatively(M))
9184
return false;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct zeInfoPayloadArgument
7676
{
7777
bool operator==(const zeInfoPayloadArgument& other) const
7878
{
79-
return arg_type == other.arg_type && offset == other.offset && size == other.size && arg_index == other.arg_index && addrmode == other.addrmode && addrspace == other.addrspace && access_type == other.access_type && sampler_index == other.sampler_index && source_offset == other.source_offset && slm_alignment == other.slm_alignment && image_type == other.image_type && image_transformable == other.image_transformable && sampler_type == other.sampler_type && is_pipe == other.is_pipe && is_ptr == other.is_ptr;
79+
return arg_type == other.arg_type && offset == other.offset && size == other.size && arg_index == other.arg_index && addrmode == other.addrmode && addrspace == other.addrspace && access_type == other.access_type && sampler_index == other.sampler_index && source_offset == other.source_offset && slm_alignment == other.slm_alignment && image_type == other.image_type && image_transformable == other.image_transformable && sampler_type == other.sampler_type && is_pipe == other.is_pipe && is_ptr == other.is_ptr && bti_value == other.bti_value;
8080
}
8181
zeinfo_str_t arg_type;
8282
zeinfo_int32_t offset = 0;
@@ -93,6 +93,7 @@ struct zeInfoPayloadArgument
9393
zeinfo_str_t sampler_type;
9494
zeinfo_bool_t is_pipe = false;
9595
zeinfo_bool_t is_ptr = false;
96+
zeinfo_int32_t bti_value = -1;
9697
};
9798
struct zeInfoPerThreadPayloadArgument
9899
{
@@ -235,7 +236,7 @@ struct zeInfoContainer
235236
KernelsMiscInfoTy kernels_misc_info;
236237
};
237238
struct PreDefinedAttrGetter{
238-
static zeinfo_str_t getVersionNumber() { return "1.26"; }
239+
static zeinfo_str_t getVersionNumber() { return "1.28"; }
239240

240241
enum class ArgThreadSchedulingMode {
241242
age_based,
@@ -275,7 +276,9 @@ struct PreDefinedAttrGetter{
275276
flat_image_pitch,
276277
sampler_address,
277278
sampler_normalized,
278-
sampler_snap_wa
279+
sampler_snap_wa,
280+
const_base,
281+
global_base
279282
};
280283
enum class ArgAddrMode {
281284
stateless,
@@ -427,6 +430,10 @@ struct PreDefinedAttrGetter{
427430
return "sampler_normalized";
428431
case ArgType::sampler_snap_wa:
429432
return "sampler_snap_wa";
433+
case ArgType::const_base:
434+
return "const_base";
435+
case ArgType::global_base:
436+
return "global_base";
430437
default:
431438
break;
432439
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void MappingTraits<zeInfoPayloadArgument>::mapping(IO& io, zeInfoPayloadArgument
9898
io.mapOptional("sampler_type", info.sampler_type, std::string());
9999
io.mapOptional("is_pipe", info.is_pipe, false);
100100
io.mapOptional("is_ptr", info.is_ptr, false);
101+
io.mapOptional("bti_value", info.bti_value, -1);
101102
}
102103
void MappingTraits<zeInfoPerThreadPayloadArgument>::mapping(IO& io, zeInfoPerThreadPayloadArgument& info)
103104
{

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.26
10+
Version 1.28
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.28**: Add const_base and global_base to payload arguments.
19+
- **Version 1.27**: Add has_sample to execution_env.
1820
- **Version 1.26**: Add rt_global_buffer to payload arguments.
1921
- **Version 1.25**: Add is_ptr attribute to payload arguments.
2022
- **Version 1.24**: Add eu_thread_count to execution_env.

IGC/ZEBinWriter/zebin/spec/zeinfo.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ If an attribute is **Required**, it must be present in payload arguments. If it'
175175
| sampler_type | <sampler_type> | Optional | | Present when addrspace is "sampler" |
176176
| is_pipe | bool | Optional | false | Present when arg_type is "arg_bypointer" and type qualifier is pipe |
177177
| is_ptr | bool | Optional | false | Present when arg_type is "arg_byvalue" and arg is used as pointer |
178+
| bti_value | int32 | Optional | -1 | Present when arg_type is "const_base", "global_base" and when the buffer is promoted to BTI |
178179
<!--- PayloadArgument PayloadArguments -->
179180

180181
### Supported argument types:
@@ -215,6 +216,8 @@ Supported <argument_type> of payload_arguments or per_thread_payload_arguments.
215216
| sampler_address | | Sampler descriptor specifying the image addressing mode |
216217
| sampler_normalized | | Sampler descriptor specifying whether the coordinates are passed in as normalized or unnormalized values |
217218
| sampler_snap_wa | | Sampler descriptor specifying whether snap coordinate workaround is required |
219+
| const_base | | The base address of constant buffer |
220+
| global_base | | The base address of global buffer |
218221
<!--- <argument_type> ArgType -->
219222

220223
arg_byvalue and arg_bypointer are user arguments that are explicitly passed in from the applications. Other kinds of arguments are implicit arguments that are passed in by runtime.

0 commit comments

Comments
 (0)