Skip to content

Commit a583088

Browse files
DianaChensys_zuul
authored andcommitted
ZEBinary: support image for ocl path. Produce image argument during igc kernel codegen
ZEAutoTool: Support user-defined prefix for enum class member Also refined the ZEBinary spec Change-Id: I3fbd97052713d6ac9d423b6cbdf7c4227b643cfe
1 parent 841b46b commit a583088

File tree

6 files changed

+121
-17
lines changed

6 files changed

+121
-17
lines changed

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,11 @@ namespace IGC
662662
0, 0, arg_idx,
663663
zebin::PreDefinedAttrGetter::ArgAddrMode::stateful,
664664
(kernelArg->getArgType() == KernelArg::ArgType::PTR_GLOBAL)?
665-
zebin::PreDefinedAttrGetter::ArgAddrSpace::global :
666-
zebin::PreDefinedAttrGetter::ArgAddrSpace::constant,
665+
zebin::PreDefinedAttrGetter::ArgAddrSpace::global :
666+
zebin::PreDefinedAttrGetter::ArgAddrSpace::constant,
667667
(kernelArg->getArgType() == KernelArg::ArgType::PTR_GLOBAL)?
668-
zebin::PreDefinedAttrGetter::ArgAccessType::readwrite :
669-
zebin::PreDefinedAttrGetter::ArgAccessType::readonly
668+
zebin::PreDefinedAttrGetter::ArgAccessType::readwrite :
669+
zebin::PreDefinedAttrGetter::ArgAccessType::readonly
670670
);
671671
// add the corresponding BTI table index
672672
zebin::ZEInfoBuilder::addBindingTableIndex(m_kernelInfo.m_zeBTIArgs,
@@ -705,7 +705,7 @@ namespace IGC
705705
zebin::PreDefinedAttrGetter::ArgAddrSpace::constant,
706706
(kernelArg->getArgType() == KernelArg::ArgType::PTR_GLOBAL)?
707707
zebin::PreDefinedAttrGetter::ArgAccessType::readwrite :
708-
zebin::PreDefinedAttrGetter::ArgAccessType::readonly
708+
zebin::PreDefinedAttrGetter::ArgAccessType::readonly
709709
);
710710
break;
711711
}
@@ -728,6 +728,81 @@ namespace IGC
728728
case KernelArg::ArgType::IMPLICIT_LOCAL_IDS:
729729
break;
730730

731+
// Images
732+
case KernelArg::ArgType::IMAGE_1D:
733+
case KernelArg::ArgType::BINDLESS_IMAGE_1D:
734+
case KernelArg::ArgType::IMAGE_1D_BUFFER:
735+
case KernelArg::ArgType::BINDLESS_IMAGE_1D_BUFFER:
736+
case KernelArg::ArgType::IMAGE_2D:
737+
case KernelArg::ArgType::BINDLESS_IMAGE_2D:
738+
case KernelArg::ArgType::IMAGE_3D:
739+
case KernelArg::ArgType::BINDLESS_IMAGE_3D:
740+
case KernelArg::ArgType::IMAGE_CUBE:
741+
case KernelArg::ArgType::BINDLESS_IMAGE_CUBE:
742+
case KernelArg::ArgType::IMAGE_CUBE_DEPTH:
743+
case KernelArg::ArgType::BINDLESS_IMAGE_CUBE_DEPTH:
744+
case KernelArg::ArgType::IMAGE_1D_ARRAY:
745+
case KernelArg::ArgType::BINDLESS_IMAGE_1D_ARRAY:
746+
case KernelArg::ArgType::IMAGE_2D_ARRAY:
747+
case KernelArg::ArgType::BINDLESS_IMAGE_2D_ARRAY:
748+
case KernelArg::ArgType::IMAGE_2D_DEPTH:
749+
case KernelArg::ArgType::BINDLESS_IMAGE_2D_DEPTH:
750+
case KernelArg::ArgType::IMAGE_2D_DEPTH_ARRAY:
751+
case KernelArg::ArgType::BINDLESS_IMAGE_2D_DEPTH_ARRAY:
752+
case KernelArg::ArgType::IMAGE_2D_MSAA:
753+
case KernelArg::ArgType::BINDLESS_IMAGE_2D_MSAA:
754+
case KernelArg::ArgType::IMAGE_2D_MSAA_ARRAY:
755+
case KernelArg::ArgType::BINDLESS_IMAGE_2D_MSAA_ARRAY:
756+
case KernelArg::ArgType::IMAGE_2D_MSAA_DEPTH:
757+
case KernelArg::ArgType::BINDLESS_IMAGE_2D_MSAA_DEPTH:
758+
case KernelArg::ArgType::IMAGE_2D_MSAA_DEPTH_ARRAY:
759+
case KernelArg::ArgType::BINDLESS_IMAGE_2D_MSAA_DEPTH_ARRAY:
760+
case KernelArg::ArgType::IMAGE_CUBE_ARRAY:
761+
case KernelArg::ArgType::BINDLESS_IMAGE_CUBE_ARRAY:
762+
case KernelArg::ArgType::IMAGE_CUBE_DEPTH_ARRAY:
763+
case KernelArg::ArgType::BINDLESS_IMAGE_CUBE_DEPTH_ARRAY:
764+
{
765+
int arg_idx = kernelArg->getAssociatedArgNo();
766+
SOpenCLKernelInfo::SResourceInfo resInfo = getResourceInfo(arg_idx);
767+
768+
// check if the image is writeable
769+
bool writeable = false;
770+
if (resInfo.Type == SOpenCLKernelInfo::SResourceInfo::RES_UAV &&
771+
kernelArg->getAccessQual() != IGC::KernelArg::AccessQual::READ_ONLY)
772+
writeable = true;
773+
IGC_ASSERT_MESSAGE(resInfo.Type == SOpenCLKernelInfo::SResourceInfo::RES_UAV ||
774+
resInfo.Type == SOpenCLKernelInfo::SResourceInfo::RES_SRV, "Unknown resource type");
775+
776+
// the image arg is either bindless of stateful. check from "kernelArg->needsAllocation()"
777+
// For statefull image argument, the arg has 0 offset and 0 size
778+
zebin::PreDefinedAttrGetter::ArgAddrMode arg_addrmode =
779+
zebin::PreDefinedAttrGetter::ArgAddrMode::stateful;
780+
uint arg_off = 0;
781+
uint arg_size = 0;
782+
783+
if (kernelArg->needsAllocation()) {
784+
// set to bindless
785+
arg_addrmode =
786+
zebin::PreDefinedAttrGetter::ArgAddrMode::bindless;
787+
arg_off = payloadPosition;
788+
arg_size = kernelArg->getAllocateSize();
789+
} else {
790+
// add bti index for this arg if it's stateful
791+
zebin::ZEInfoBuilder::addBindingTableIndex(m_kernelInfo.m_zeBTIArgs,
792+
getBTI(resInfo), arg_idx);
793+
}
794+
795+
// add the payload argument
796+
zebin::ZEInfoBuilder::addPayloadArgumentByPointer(m_kernelInfo.m_zePayloadArgs,
797+
arg_off, arg_size, arg_idx, arg_addrmode,
798+
zebin::PreDefinedAttrGetter::ArgAddrSpace::image,
799+
writeable ?
800+
zebin::PreDefinedAttrGetter::ArgAccessType::readwrite :
801+
zebin::PreDefinedAttrGetter::ArgAccessType::readonly
802+
);
803+
}
804+
break;
805+
731806
// We don't need these in ZEBinary, can safely skip them
732807
case KernelArg::ArgType::IMPLICIT_R0:
733808
case KernelArg::ArgType::R1:

IGC/ZEBinWriter/ZEAutoTool/fileparser.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
// \\file
4343
// This file declares the struct representation of .ze.info section
4444
//===----------------------------------------------------------------------===//\n
45+
// ******************** DO NOT MODIFY DIRECTLY *********************************
46+
// This file is auto-generated by ZEAutoTool/fileparser.py
47+
4548
#ifndef ZE_INFO_HPP
4649
#define ZE_INFO_HPP
4750
@@ -56,6 +59,9 @@
5659
//
5760
// file
5861
//===----------------------------------------------------------------------===//\n
62+
// ******************** DO NOT MODIFY DIRECTLY *********************************
63+
// This file is auto-generated by ZEAutoTool/fileparser.py
64+
5965
#include <ZEInfoYAML.hpp>
6066
using namespace zebin;
6167
using namespace llvm::yaml;\n
@@ -66,7 +72,9 @@
6672
//
6773
// \\file
6874
// This file declares the mapping between zeInfo structs and YAML
69-
//===----------------------------------------------------------------------===//
75+
//===----------------------------------------------------------------------===//\n
76+
// ******************** DO NOT MODIFY DIRECTLY *********************************
77+
// This file is auto-generated by ZEAutoTool/fileparser.py
7078
7179
#ifndef ZE_INFO_YAML_HPP
7280
#define ZE_INFO_YAML_HPP
@@ -255,23 +263,24 @@ def pandas_parse_top_layers(df, types, output_file, struct_name, check_vectors):
255263
"""
256264
Write PreDefinedAttrGetter lines to ZEInfo.hpp
257265
"""
258-
def pandas_attr_getter(df, class_name, enum_lines, static_lines):
266+
def pandas_attr_getter(df, class_name, enum_prefix, enum_lines, static_lines):
259267
enum_name = " enum class " + class_name + " {\n"
260-
static_name = " static zeinfo_str_t get(" + class_name + " val) {\n switch(val) {\n"
268+
static_name = " static zeinfo_str_t get(" + class_name + " val) {\n switch(val) {\n"
261269
enum_lines.append(enum_name)
262270
static_lines.append(static_name)
263271

264272

265273
name_list = df.iloc[:, 0].values
266274
for index in range(len(name_list)):
267275
item = name_list[index]
268-
static_lines.append(" case " + class_name + "::" + item + ":\n return \"" + item + "\";\n")
276+
enum_item = enum_prefix + item
277+
static_lines.append(" case " + class_name + "::" + enum_item + ":\n return \"" + item + "\";\n")
269278

270279
if index != len(name_list) - 1:
271-
item = " " + item + ",\n"
280+
enum_item = " " + enum_item + ",\n"
272281
else:
273-
item = " " + item + "\n"
274-
enum_lines.append(item)
282+
enum_item = " " + enum_item + "\n"
283+
enum_lines.append(enum_item)
275284
enum_lines.append(" };\n")
276285
static_lines.append(" default:\n break;\n }\n return \"\";\n")
277286
static_lines.append(" }\n")
@@ -332,7 +341,13 @@ def create_zeinfo_hpp_yaml_cpp(src_lines, folder):
332341
else:
333342
pandas_create_zeinfo_hpp(df, struct_name, zeinfo_hpp)
334343
else:
335-
pandas_attr_getter(df, comment.split(" ")[2], enum_lines, static_lines)
344+
# check if the 4th comment existed, which is the prefix of enum class member
345+
enum_prefix = ""
346+
if len(comment.split(" ")) > 3:
347+
tmp = comment.split(" ")[3]
348+
if tmp.startswith("*"):
349+
enum_prefix = tmp[1:] + "_"
350+
pandas_attr_getter(df, comment.split(" ")[2], enum_prefix, enum_lines, static_lines)
336351

337352
yaml_hpp_vectors = check_vectors.copy()
338353
for pair in top_layers_df + container_df:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3030
// This file declares the struct representation of .ze.info section
3131
//===----------------------------------------------------------------------===//
3232

33+
// ******************** DO NOT MODIFY DIRECTLY *********************************
34+
// This file is auto-generated by ZEAutoTool/fileparser.py
35+
3336
#ifndef ZE_INFO_HPP
3437
#define ZE_INFO_HPP
3538

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2929
// file
3030
//===----------------------------------------------------------------------===//
3131

32+
// ******************** DO NOT MODIFY DIRECTLY *********************************
33+
// This file is auto-generated by ZEAutoTool/fileparser.py
34+
3235
#include <ZEInfoYAML.hpp>
3336
using namespace zebin;
3437
using namespace llvm::yaml;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3030
// This file declares the mapping between zeInfo structs and YAML
3131
//===----------------------------------------------------------------------===//
3232

33+
// ******************** DO NOT MODIFY DIRECTLY *********************************
34+
// This file is auto-generated by ZEAutoTool/fileparser.py
35+
3336
#ifndef ZE_INFO_YAML_HPP
3437
#define ZE_INFO_YAML_HPP
3538

IGC/ZEBinWriter/zebin/spec/zeinfo.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ If an attribute is **Required**, it must be present in exection_env. If it's **O
9696
<!--- ExecutionEnv -->
9797

9898
## Payload Arguments
99+
There are two kinds of payload arguments: **Payload Argument** and **Per Thread Payload Arguments**.
100+
Payload arguments include explicit user arguments of a kernel, such as payload_arguments with arg_type that is arg_byvalue or arg_bypointer,
101+
and implicit arguments inserted by the compiler, such as arguments with local_size arg_type.
99102

100103
### Supported attributes in payload arguments:
101104
If an attribute is **Required**, it must be present in payload arguments. If it's **Optional** and it's not present, the **Default** value is used.
@@ -112,6 +115,7 @@ If an attribute is **Required**, it must be present in payload arguments. If it'
112115
<!--- PayloadArgument PayloadArguments -->
113116

114117
## Per Thread Payload Arguments
118+
Per Thread Payload Arguments are implicit arguments inserted by the compiler. They are allocated per-thread.
115119

116120
| Attribute | Type | Description |
117121
| ------ | ------ | ------ |
@@ -121,11 +125,13 @@ If an attribute is **Required**, it must be present in payload arguments. If it'
121125
<!--- PerThreadPayloadArgument PerThreadPayloadArguments -->
122126

123127
## Binding Table Indices
128+
Binding table index of the corresponding payload_argument.
129+
The payload_argument must have **arg_bypointer** arg_type and **stateful** addrmode
124130

125131
| Attribute | Type | Description |
126132
| ------ | ------ | ------ |
127133
| bti_value | int32 | |
128-
| arg_index | int32 | |
134+
| arg_index | int32 | index of the coressponding payload_argument |
129135
<!--- BindingTableIndex BindingTableIndices -->
130136

131137

@@ -178,16 +184,15 @@ arg_byvalue and arg_bypointer are user arguments that are explcitly passed in fr
178184
<!--- <access_type> ArgAccessType -->
179185

180186
## Per Thread Memory Buffer
187+
Memory buffer required by Compiler generated stacks.
181188

182189
| | Type | Description |
183190
| ----- | ----- | ----- |
184191
| type | <allocation_type> | |
185192
| usage | <memory_usage> | |
186-
| size | int32 | |
193+
| size | int32 | Buffer size in bytes |
187194
<!--- PerThreadMemoryBuffer PerThreadMemoryBuffers -->
188195

189-
Memory buffer required by Compiler generated stacks. Size in bytes.
190-
191196
### Supported allocation types:
192197

193198
| Allocation Type | Description |

0 commit comments

Comments
 (0)