Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions bindings/sysman/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ HOW TO USE STRUCTURE CHAINING
>>> ext = zes_device_ext_properties_t()
>>> ext.stype = ZES_STRUCTURE_TYPE_DEVICE_EXT_PROPERTIES
>>> ext.pNext = None
>>> base.pNext = cast(pointer(ext), c_void_p)
>>> props.pNext = cast(pointer(ext), c_void_p)
>>> pyzes.zesDeviceGetProperties(devices[i], byref(props))
>>> print(f"Extension properties flags: {ext.flags}")
```
Expand Down Expand Up @@ -173,7 +173,7 @@ The Linux Dependencies and Windows Dependencies columns list the external librar
| `zesInit` | Device | 0.1.0 | None | None | None |
| `zesDriverGet` | Device | 0.1.0 | None | None | None |
| `zesDeviceGet` | Device | 0.1.0 | None | None | None |
| `zesDeviceGetProperties` | Device | 0.1.0 | None | None | None |
| `zesDeviceGetProperties` | Device | 0.1.0 | Extensions `zes_device_index_ext_properties_t` and `zes_device_gpu_topology_ext_properties_t` since 0.1.5 | None | None |
| `zesDriverGetDeviceByUuidExp` | Device | 0.1.0 | Experimental API | None | None |
| `zesDeviceGetSubDevicePropertiesExp` | Device | 0.1.0 | Experimental API | None | None |
| `zesDeviceProcessesGetState` | Device | 0.1.0 | None | None | None |
Expand All @@ -184,6 +184,8 @@ The Linux Dependencies and Windows Dependencies columns list the external librar
| `zesDriverEventListenEx` | Driver | 0.1.4 | Linux: Requires superuser | `libudev`, `libnl-genl-3` | None |
| `zesDriverEventRegisterExt` | Driver | 0.1.4 | None | None | None |
| `zesDriverEventListenExt` | Driver | 0.1.4 | Linux: Requires superuser | `libudev`, `libnl-genl-3`, `libtracefs` | None |
| `zesDriverGetApiVersion` | Driver | 0.1.5 | None | None | None |
| `zesDriverGetPciDeviceProperties` | Driver | 0.1.5 | Linux: `configProperties.supportedLinkSpeeds` requires superuser, otherwise reported as 0. Windows: Not supported | None | None |
| `zesDeviceGetState` | Device | 0.1.4 | None | `libigsc` | None |
| `zesDeviceResetExt` | Device | 0.1.4 | Linux: Requires superuser; all device state is lost | None | None |
| `zesDeviceEventRegister` | Device | 0.1.4 | Linux: Requires superuser | None | None |
Expand Down Expand Up @@ -263,6 +265,19 @@ The Linux Dependencies and Windows Dependencies columns list the external librar

RELEASE NOTES
-------------
Version 0.1.5 (unreleased)
- **New API Functions:**
- Driver: `zesDriverGetApiVersion`, `zesDriverGetPciDeviceProperties`
- **New Structures:**
- `zes_device_index_ext_properties_t` (`ZES_STRUCTURE_TYPE_DEVICE_INDEX_EXT_PROPERTIES`), chained on `zesDeviceGetProperties`
- `zes_device_gpu_topology_ext_properties_t` (`ZES_STRUCTURE_TYPE_DEVICE_GPU_TOPOLOGY_EXT_PROPERTIES`), chained on `zesDeviceGetProperties`
- `zes_driver_pci_device_properties_t`, `zes_pci_config_properties_t` and the `ZES_PCI_LINK_SPEED_FLAG_*` flags
- `zes_api_version_t` with `ZES_API_VERSION_*`, and the `ZES_MAKE_VERSION`, `ZES_MAJOR_VERSION` and `ZES_MINOR_VERSION` helpers
- **Examples:**
- `pyzes_black_box_test.py`: the driver properties test (`-D`) prints the Sysman API version and the PCI device list, and the global operations test prints the device index and GPU topology extensions.
- **Documentation:**
- Fixed the structure chaining example, which set `pNext` on an undefined `base` variable

Version 0.1.4
- **New API Functions:**
- Driver: `zesDriverGetProperties`, `zesDriverGetExtensionProperties`, `zesDriverGetExtensionFunctionAddress`, `zesDriverEventListenEx`, `zesDriverEventRegisterExt`, `zesDriverEventListenExt`
Expand Down
172 changes: 171 additions & 1 deletion bindings/sysman/python/source/pyzes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,45 @@ def __str__(self):
return self.__class__.__name__ + "(" + ", ".join(result) + ")"


## Sysman API version (zes_api_version_t) ##
def ZES_MAKE_VERSION(major, minor):
return (major << 16) | (minor & 0x0000FFFF)


def ZES_MAJOR_VERSION(ver):
return ver >> 16


def ZES_MINOR_VERSION(ver):
return ver & 0x0000FFFF


zes_api_version_t = c_int32
ZES_API_VERSION_1_0 = ZES_MAKE_VERSION(1, 0)
ZES_API_VERSION_1_1 = ZES_MAKE_VERSION(1, 1)
ZES_API_VERSION_1_2 = ZES_MAKE_VERSION(1, 2)
ZES_API_VERSION_1_3 = ZES_MAKE_VERSION(1, 3)
ZES_API_VERSION_1_4 = ZES_MAKE_VERSION(1, 4)
ZES_API_VERSION_1_5 = ZES_MAKE_VERSION(1, 5)
ZES_API_VERSION_1_6 = ZES_MAKE_VERSION(1, 6)
ZES_API_VERSION_1_7 = ZES_MAKE_VERSION(1, 7)
ZES_API_VERSION_1_8 = ZES_MAKE_VERSION(1, 8)
ZES_API_VERSION_1_9 = ZES_MAKE_VERSION(1, 9)
ZES_API_VERSION_1_10 = ZES_MAKE_VERSION(1, 10)
ZES_API_VERSION_1_11 = ZES_MAKE_VERSION(1, 11)
ZES_API_VERSION_1_12 = ZES_MAKE_VERSION(1, 12)
ZES_API_VERSION_1_13 = ZES_MAKE_VERSION(1, 13)
ZES_API_VERSION_1_14 = ZES_MAKE_VERSION(1, 14)
ZES_API_VERSION_1_15 = ZES_MAKE_VERSION(1, 15)
ZES_API_VERSION_1_16 = ZES_MAKE_VERSION(1, 16)
ZES_API_VERSION_1_17 = ZES_MAKE_VERSION(1, 17)
ZES_API_VERSION_1_18 = ZES_MAKE_VERSION(1, 18)
ZES_API_VERSION_1_19 = ZES_MAKE_VERSION(1, 19)
ZES_API_VERSION_1_20 = ZES_MAKE_VERSION(1, 20)
ZES_API_VERSION_1_21 = ZES_MAKE_VERSION(1, 21)
ZES_API_VERSION_FORCE_UINT32 = 0x7FFFFFFF
Comment thread
joshuaranjan marked this conversation as resolved.
Resolved


def _LoadZeLibrary():
global gpuLib
if gpuLib is not None:
Expand Down Expand Up @@ -125,7 +164,6 @@ def _LoadZeLibrary():
"Failed to load Level Zero loader on Windows. "
f"Tried paths: {possible_paths}. Errors: {load_errors}"
)

if sys.platform.startswith("linux"):
gpuLib = CDLL(libName)

Expand Down Expand Up @@ -528,6 +566,10 @@ class zes_firmware_handle_t(c_void_p):
ZES_STRUCTURE_TYPE_INFO_LOG_READ_STATUS_EXT = 0x00020023
ZES_STRUCTURE_TYPE_DRIVER_PROPERTIES = 0x2F
ZES_STRUCTURE_TYPE_FIRMWARE_PROPERTIES = 0x8
ZES_STRUCTURE_TYPE_PCI_CONFIG_PROPERTIES = 0x00020024
ZES_STRUCTURE_TYPE_DRIVER_PCI_DEVICE_PROPERTIES = 0x00020025
ZES_STRUCTURE_TYPE_DEVICE_INDEX_EXT_PROPERTIES = 0x00020026
ZES_STRUCTURE_TYPE_DEVICE_GPU_TOPOLOGY_EXT_PROPERTIES = 0x00020027


## Core ze_device UUID struct ##
Expand Down Expand Up @@ -687,6 +729,50 @@ class zes_pci_stats_t(_PrintableStructure):
}


zes_pci_link_speed_flags_t = c_uint32
ZES_PCI_LINK_SPEED_FLAG_GEN1 = 1 << 0
ZES_PCI_LINK_SPEED_FLAG_GEN2 = 1 << 1
ZES_PCI_LINK_SPEED_FLAG_GEN3 = 1 << 2
ZES_PCI_LINK_SPEED_FLAG_GEN4 = 1 << 3
ZES_PCI_LINK_SPEED_FLAG_GEN5 = 1 << 4
ZES_PCI_LINK_SPEED_FLAG_GEN6 = 1 << 5
ZES_PCI_LINK_SPEED_FLAG_GEN7 = 1 << 6
ZES_PCI_LINK_SPEED_FLAG_FORCE_UINT32 = 0x7FFFFFFF


class zes_pci_config_properties_t(_PrintableStructure):
Comment thread
joshuaranjan marked this conversation as resolved.
Resolved
_fields_ = [
("stype", c_int32), # ZES_STRUCTURE_TYPE_PCI_CONFIG_PROPERTIES
("pNext", c_void_p),
("vendorId", c_uint16),
("deviceId", c_uint16),
("subsystemVendorId", c_uint16),
("subsystemDeviceId", c_uint16),
("pcieCapabilityVersion", c_uint32),
("supportedLinkSpeeds", zes_pci_link_speed_flags_t),
("revision", c_ubyte),
]
_fmt_ = {
"vendorId": "0x%04X",
"deviceId": "0x%04X",
"subsystemVendorId": "0x%04X",
"subsystemDeviceId": "0x%04X",
"supportedLinkSpeeds": "0x%08X",
"revision": "0x%02X",
}


class zes_driver_pci_device_properties_t(_PrintableStructure):
_fields_ = [
("stype", c_int32), # ZES_STRUCTURE_TYPE_DRIVER_PCI_DEVICE_PROPERTIES
("pNext", c_void_p), # must be None; no extensions are supported
("address", zes_pci_address_t),
("maxSpeed", zes_pci_speed_t),
("configProperties", zes_pci_config_properties_t),
("status", zes_pci_link_status_t),
]


## ECC enums and structures ##
zes_device_ecc_state_t = c_int32
ZES_DEVICE_ECC_STATE_UNAVAILABLE = 0
Expand Down Expand Up @@ -762,6 +848,39 @@ class zes_subdevice_exp_properties_t(_PrintableStructure):
]


## Sysman zes_device_index_ext_properties_t (extension) ##
ZES_DEVICE_INDEX_EXT_NAME = "ZES_extension_device_index"
ZES_DEVICE_INDEX_EXT_VERSION_1_0 = ZES_MAKE_VERSION(1, 0)
ZES_DEVICE_INDEX_EXT_VERSION_CURRENT = ZES_MAKE_VERSION(1, 0)


class zes_device_index_ext_properties_t(_PrintableStructure):
_fields_ = [
("stype", c_int32), # ZES_STRUCTURE_TYPE_DEVICE_INDEX_EXT_PROPERTIES
("pNext", c_void_p), # optional chain
("deviceIndex", c_uint32), # integer identifier for the Sysman device handle
]


## Sysman zes_device_gpu_topology_ext_properties_t (extension) ##
ZES_DEVICE_GPU_TOPOLOGY_EXT_NAME = "ZES_extension_device_gpu_topology"
ZES_DEVICE_GPU_TOPOLOGY_EXT_VERSION_1_0 = ZES_MAKE_VERSION(1, 0)
ZES_DEVICE_GPU_TOPOLOGY_EXT_VERSION_CURRENT = ZES_MAKE_VERSION(1, 0)


class zes_device_gpu_topology_ext_properties_t(_PrintableStructure):
_fields_ = [
("stype", c_int32), # ZES_STRUCTURE_TYPE_DEVICE_GPU_TOPOLOGY_EXT_PROPERTIES
("pNext", c_void_p), # optional chain
("numSlices", c_uint32),
("numXeCores", c_uint32),
("numVectorEngines", c_uint32),
("numMatrixEngines", c_uint32),
("numThreads", c_uint32),
("generationName", c_char * ZES_STRING_PROPERTY_SIZE),
]


## Memory structures ##
class zes_mem_properties_t(_PrintableStructure):
_fields_ = [
Expand Down Expand Up @@ -2751,6 +2870,57 @@ def zesDriverGetExtensionProperties(hDriver, pCount, pExtensionProperties):
return retVal


def zesDriverGetApiVersion(hDriver, pVersion):
"""Wraps API:
ze_result_t zesDriverGetApiVersion(
zes_driver_handle_t hDriver,
zes_api_version_t* pVersion)

Parameters:
hDriver: driver handle
pVersion: POINTER(zes_api_version_t) - filled with the Sysman API version.
Use ZES_MAJOR_VERSION / ZES_MINOR_VERSION to decode it.
Returns:
ze_result_t - return code only, the version is filled into pVersion
"""
funcPtr = getFunctionPointerList("zesDriverGetApiVersion")
funcPtr.argtypes = [zes_driver_handle_t, POINTER(zes_api_version_t)]
funcPtr.restype = ze_result_t

retVal = funcPtr(hDriver, pVersion)
return retVal


def zesDriverGetPciDeviceProperties(hDriver, pCount, pProperties):
"""Wraps API:
ze_result_t zesDriverGetPciDeviceProperties(
zes_driver_handle_t hDriver,
uint32_t* pCount,
zes_driver_pci_device_properties_t* pProperties)

Reports every device supported by the driver that is present on the PCI
bus, whether or not a kernel mode driver is bound to it.

Parameters:
hDriver: driver handle
pCount: POINTER(c_uint32) - if 0, updated with the number of PCI devices
pProperties: POINTER(zes_driver_pci_device_properties_t) or None.
Each element's pNext must be None.
Returns:
ze_result_t - return code only, properties are filled into pProperties
"""
funcPtr = getFunctionPointerList("zesDriverGetPciDeviceProperties")
funcPtr.argtypes = [
zes_driver_handle_t,
POINTER(c_uint32),
POINTER(zes_driver_pci_device_properties_t),
]
funcPtr.restype = ze_result_t

retVal = funcPtr(hDriver, pCount, pProperties)
return retVal


def zesDriverGetExtensionFunctionAddress(hDriver, name, ppFunctionAddress):
"""Wraps API:
ze_result_t zesDriverGetExtensionFunctionAddress(
Expand Down
13 changes: 13 additions & 0 deletions bindings/sysman/python/source/pyzes/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,16 @@ The scripts add `bindings/sysman/python/source` to `sys.path`, so they import th
- Python 3.10+
- Intel GPU with Level-Zero drivers installed
- pyzes module

---

## pyzes_black_box_test.py Coverage

| Option | Test | APIs exercised |
|--------|------|----------------|
| `-D`, `--driverproperties` | Driver properties | `zesDriverGetProperties`, `zesDriverGetApiVersion`, `zesDriverGetPciDeviceProperties`, `zesDriverGetExtensionProperties`, `zesDriverGetExtensionFunctionAddress` |
| `-g`, `--global` | Global operations | `zesDeviceGetProperties` with the `zes_device_index_ext_properties_t` and `zes_device_gpu_topology_ext_properties_t` extensions chained, `zesDeviceGetSubDevicePropertiesExp`, `zesDriverGetDeviceByUuidExp`, `zesDeviceProcessesGetState` |

`zesDriverGetPciDeviceProperties` lists every supported device on the PCI bus, including devices with no kernel mode driver bound. A revision of `0xFF` is flagged as "device not responding". On drivers that return `ZE_RESULT_ERROR_UNSUPPORTED_FEATURE`, the test reports it as not supported instead of failing.

Run `python3 pyzes_black_box_test.py -h` for the full list of options.
Loading
Loading