Skip to content

Commit 3ee91a4

Browse files
authored
Adding zeDeviceRuntimeRequirementsQuery (#429)
API allows for querying and validating runtime requirements for provided object (module or graph).
1 parent 5661554 commit 3ee91a4

4 files changed

Lines changed: 171 additions & 5 deletions

File tree

scripts/core/common.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class: $xModule
114114
name: "$x_module_handle_t"
115115
--- #--------------------------------------------------------------------------
116116
type: handle
117+
desc: "Handle of driver's graph object"
118+
class: $xGraph
119+
name: "$x_graph_handle_t"
120+
--- #--------------------------------------------------------------------------
121+
type: handle
117122
desc: "Handle of module's build log object"
118123
class: $xModuleBuildLog
119124
name: "$x_module_build_log_handle_t"
@@ -697,6 +702,18 @@ etors:
697702
desc: $x_device_compute_dotproduct_ext_properties_t
698703
version: "1.16"
699704
value: "0x00020043"
705+
- name: RUNTIME_REQUIREMENTS_MODULE_DESC
706+
desc: $x_runtime_requirements_module_desc_t
707+
version: "1.16"
708+
value: "0x00020044"
709+
- name: RUNTIME_REQUIREMENTS_GRAPH_DESC
710+
desc: $x_runtime_requirements_graph_desc_t
711+
version: "1.16"
712+
value: "0x00020045"
713+
- name: RUNTIME_REQUIREMENTS_OUTPUT
714+
desc: $x_validate_runtime_requirements_output_t
715+
version: "1.16"
716+
value: "0x00020046"
700717
--- #--------------------------------------------------------------------------
701718
type: enum
702719
desc: "External memory type flags"

scripts/core/device.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,3 +1050,132 @@ params:
10501050
returns::
10511051
- $X_RESULT_ERROR_INVALID_ARGUMENT:
10521052
- "Provided invalid hDevice or incrementValue pointer"
1053+
--- #--------------------------------------------------------------------------
1054+
type: struct
1055+
desc: "Describes the module for which runtime requirements are being gathered. This structure is accepted as pObjDesc to $xDeviceGetRuntimeRequirements. This structure requires ZE_extension_driver_ddi_handles to be supported by the driver."
1056+
class: $xDevice
1057+
base: $x_base_desc_t
1058+
name: $x_runtime_requirements_module_desc_t
1059+
version: "1.16"
1060+
requires: ["ZE_extension_driver_ddi_handles"]
1061+
members:
1062+
- type: "$x_module_handle_t"
1063+
name: requirementsSrc
1064+
desc: "[in] Module for which the requirements are being gathered"
1065+
--- #--------------------------------------------------------------------------
1066+
type: struct
1067+
desc: "Describes the graph for which runtime requirements are being gathered. This structure is accepted as pObjDesc to $xDeviceGetRuntimeRequirements. This structure requires ZE_extension_driver_ddi_handles to be supported by the driver."
1068+
class: $xDevice
1069+
base: $x_base_desc_t
1070+
name: $x_runtime_requirements_graph_desc_t
1071+
version: "1.16"
1072+
requires: ["ZE_extension_driver_ddi_handles"]
1073+
members:
1074+
- type: "$x_graph_handle_t"
1075+
name: requirementsSrc
1076+
desc: "[in] Graph for which the requirements are being gathered"
1077+
--- #--------------------------------------------------------------------------
1078+
type: function
1079+
desc: "Gathers null-terminated plain text representation of runtime requirements for provided object."
1080+
version: "1.16"
1081+
class: $xDevice
1082+
name: GetRuntimeRequirements
1083+
details:
1084+
- "To gather requirements for a given object (e.g. an L0 module or graph), pObjDesc must point to a structure (e.g. $x_runtime_requirements_module_desc_t or $x_runtime_requirements_graph_desc_t) describing object for which the requirements are being retrieved."
1085+
- "Requirements are copied to user-provided memory pointed to by pRequirements and pSize is set to represent the actual written length of the requirements string in bytes."
1086+
- "The caller can pass nullptr for pRequirements when querying only for size."
1087+
- "The application may call this function from simultaneous threads."
1088+
params:
1089+
- type: $x_device_handle_t
1090+
name: hDevice
1091+
desc: "[in] handle of the device"
1092+
- type: const void*
1093+
name: pObjDesc
1094+
desc: "[in] describes the object for which the requirements are to be gathered"
1095+
- type: size_t*
1096+
name: pSize
1097+
desc: "[in,out] size of requirements string in bytes."
1098+
- type: char*
1099+
name: pRequirements
1100+
desc: "[in,out][optional] holds results of the query."
1101+
returns:
1102+
- $X_RESULT_SUCCESS:
1103+
- "Successfully gathered requirements for provided source (e.g. module)."
1104+
- $X_RESULT_ERROR_INVALID_ARGUMENT:
1105+
- "Provided hDevice handle is invalid"
1106+
- "pObjDesc doesn't point to a structure that describes a supported object for which the requirements can be gathered."
1107+
- $X_RESULT_ERROR_INVALID_NULL_POINTER:
1108+
- "(nullptr != pRequirements) && (nullptr == pSize)."
1109+
- "(nullptr != pRequirements) && (*pSize < requiredSize)."
1110+
--- #--------------------------------------------------------------------------
1111+
type: function
1112+
desc: "Retrieves requirements producer key."
1113+
version: "1.16"
1114+
class: $xDevice
1115+
name: GetRuntimeRequirementsKey
1116+
details:
1117+
- "Retrieves null-terminated plain text that represents the producer of requirements (Example string: 'INTEL.L0.GPU')."
1118+
- "Useful for bookkeeping of the requirements on user side."
1119+
params:
1120+
- type: $x_device_handle_t
1121+
name: hDevice
1122+
desc: "[in] handle of the device"
1123+
- type: "const char**"
1124+
name: pKey
1125+
desc: "[out] returned key"
1126+
returns:
1127+
- $X_RESULT_SUCCESS:
1128+
- "Successfully retrieved the key."
1129+
- $X_RESULT_ERROR_INVALID_NULL_POINTER:
1130+
- "(nullptr == pKey)."
1131+
--- #--------------------------------------------------------------------------
1132+
type: enum
1133+
desc: "Result of runtime requirements validation"
1134+
class: $xDevice
1135+
name: $x_validate_runtime_requirements_result_t
1136+
version: "1.16"
1137+
etors:
1138+
- name: NOT_APPLICABLE
1139+
desc: "Provided requirements are not applicable to underlying device"
1140+
- name: REQUIREMENTS_MET
1141+
desc: "Provided requirements are met and optimal"
1142+
- name: REQUIREMENTS_MET_RECOMPILATION_ADVISABLE
1143+
desc: "Provided requirements are met, but recompilation is advisable"
1144+
- name: REQUIREMENTS_NOT_MET
1145+
desc: "Requirements are not met"
1146+
--- #--------------------------------------------------------------------------
1147+
type: struct
1148+
desc: "Output of $xDeviceValidateRuntimeRequirements"
1149+
class: $xDevice
1150+
name: $x_validate_runtime_requirements_output_t
1151+
base: $x_base_properties_t
1152+
members:
1153+
- type: $x_validate_runtime_requirements_result_t
1154+
name: result
1155+
desc: "[out] Result of the validation call."
1156+
--- #--------------------------------------------------------------------------
1157+
type: function
1158+
desc: "Validates runtime requirements."
1159+
version: "1.16"
1160+
class: $xDevice
1161+
name: ValidateRuntimeRequirements
1162+
details:
1163+
- "To validate existing requirements (e.g. cached from previous runs), requirements string should be passed as pRequirements."
1164+
params:
1165+
- type: $x_device_handle_t
1166+
name: hDevice
1167+
desc: "[in] handle of the device"
1168+
- type: const char*
1169+
name: pRequirements
1170+
desc: "[in] requirements to be validated. Requirements should be null-terminated plain text representation of runtime requirements previously retrieved from the device."
1171+
- type: "$x_validate_runtime_requirements_output_t*"
1172+
name: pOut
1173+
desc: "[in][out] Output of the validation call."
1174+
returns:
1175+
- $X_RESULT_SUCCESS:
1176+
- "Validation call succeeded and result of the validation is available in pOut."
1177+
- $X_RESULT_ERROR_INVALID_ARGUMENT:
1178+
- "Provided hDevice handle is invalid"
1179+
- $X_RESULT_ERROR_INVALID_NULL_POINTER:
1180+
- "(nullptr == pRequirements)."
1181+
- "(nullptr == pOut)."

scripts/parse_specs.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import json
1212
import yaml
1313
import copy
14-
from templates.helper import param_traits, type_traits, value_traits
14+
from templates.helper import param_traits, type_traits, value_traits, get_tag
1515

1616
default_version = "1.0"
1717
all_versions = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "2.0"]
@@ -74,6 +74,20 @@ def _get_etor_value(value, prev):
7474
return int(value)
7575
else:
7676
return prev+1
77+
78+
"""
79+
check if type is declares given requirement
80+
"""
81+
def _declares_requirement(type, requirement):
82+
return requirement in type.get("requires", [])
83+
84+
"""
85+
check if type is allowed to use handles as members
86+
"""
87+
def _handle_members_allowed(parent_desc, member_desc, tags):
88+
return get_tag(member_desc['type'], tags) == "$x" \
89+
and (_version_compare_gequal(parent_desc.get("version", default_version), "1.17")
90+
or _declares_requirement(parent_desc, "ZE_extension_driver_ddi_handles"))
7791

7892
"""
7993
validate documents meet some basic (easily detectable) requirements of code generation
@@ -259,7 +273,7 @@ def __validate_members(d, tags):
259273
if not annotation:
260274
raise Exception(prefix+"'desc' must start with {'[in]', '[out]', '[in,out]'}")
261275

262-
if type_traits.is_handle(item['type']):
276+
if type_traits.is_handle(item['type']) and not _handle_members_allowed(d, item, tags):
263277
raise Exception(prefix+"'type' must not be '*_handle_t': %s"%item['type'])
264278

265279
if item['type'].endswith("flag_t"):

scripts/templates/helper.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ def get_handle(item, meta):
8181
return meta['class'][item['name']]['handle'][0]
8282
except:
8383
return ""
84+
85+
"""
86+
Extracts tag prefix from a name
87+
"""
88+
def get_tag(item, tags):
89+
return next((t for t in tags if item.startswith(t)), None)
8490

8591
"""
8692
Extracts traits from a type name
@@ -210,7 +216,7 @@ class value_traits:
210216
@classmethod
211217
def is_ver(cls, name):
212218
try:
213-
return True if re.match(cls.RE_VERSION, name) else False
219+
return True if name and re.match(cls.RE_VERSION, name) else False
214220
except:
215221
return False
216222

@@ -231,7 +237,7 @@ def get_minor_ver(cls, name):
231237
@classmethod
232238
def is_bit(cls, name):
233239
try:
234-
return True if re.match(cls.RE_BIT, name) else False
240+
return True if name and re.match(cls.RE_BIT, name) else False
235241
except:
236242
return False
237243

@@ -245,7 +251,7 @@ def get_bit_count(cls, name):
245251
@classmethod
246252
def is_hex(cls, name):
247253
try:
248-
return True if re.match(cls.RE_HEX, name) else False
254+
return True if name and re.match(cls.RE_HEX, name) else False
249255
except:
250256
return False
251257

0 commit comments

Comments
 (0)