diff --git a/bindings/sysman/python/README.md b/bindings/sysman/python/README.md index 9ce7df96..89984c1d 100644 --- a/bindings/sysman/python/README.md +++ b/bindings/sysman/python/README.md @@ -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}") ``` @@ -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 | @@ -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 | @@ -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` diff --git a/bindings/sysman/python/source/pyzes/__init__.py b/bindings/sysman/python/source/pyzes/__init__.py index f8649213..17cbbdea 100644 --- a/bindings/sysman/python/source/pyzes/__init__.py +++ b/bindings/sysman/python/source/pyzes/__init__.py @@ -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 + + def _LoadZeLibrary(): global gpuLib if gpuLib is not None: @@ -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) @@ -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 ## @@ -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): + _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 @@ -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_ = [ @@ -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( diff --git a/bindings/sysman/python/source/pyzes/examples/README.md b/bindings/sysman/python/source/pyzes/examples/README.md index 56177a4e..a9b0c59a 100644 --- a/bindings/sysman/python/source/pyzes/examples/README.md +++ b/bindings/sysman/python/source/pyzes/examples/README.md @@ -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. diff --git a/bindings/sysman/python/source/pyzes/examples/pyzes_black_box_test.py b/bindings/sysman/python/source/pyzes/examples/pyzes_black_box_test.py index 1748a9a8..06340833 100755 --- a/bindings/sysman/python/source/pyzes/examples/pyzes_black_box_test.py +++ b/bindings/sysman/python/source/pyzes/examples/pyzes_black_box_test.py @@ -161,6 +161,18 @@ def get_pci_link_status_string(link_status): return status_map.get(link_status, f"UNKNOWN_PCI_LINK_STATUS_{link_status}") +def get_pci_link_speeds_string(link_speeds): + """Convert supported PCI link speed flags to string""" + if link_speeds == 0: + return "Unknown" + gens = [ + f"Gen{gen}" + for gen in range(1, 8) + if link_speeds & getattr(pz, f"ZES_PCI_LINK_SPEED_FLAG_GEN{gen}") + ] + return ", ".join(gens) if gens else f"0x{link_speeds:08X}" + + def get_pci_quality_issues_string(quality_issues): """Convert PCI quality issue flags to string""" if quality_issues == 0: @@ -577,10 +589,20 @@ def test_global_operation(driver_handle, device_handle, device_index): # Test Device Properties print_verbose("=== Device Properties Test ===") + # Chain the device index and GPU topology extensions: + # properties -> index_ext -> topology_ext + topology_ext = pz.zes_device_gpu_topology_ext_properties_t() + topology_ext.stype = pz.ZES_STRUCTURE_TYPE_DEVICE_GPU_TOPOLOGY_EXT_PROPERTIES + topology_ext.pNext = None + + index_ext = pz.zes_device_index_ext_properties_t() + index_ext.stype = pz.ZES_STRUCTURE_TYPE_DEVICE_INDEX_EXT_PROPERTIES + index_ext.pNext = cast(pointer(topology_ext), c_void_p) + # Initialize properties structure properties = pz.zes_device_properties_t() properties.stype = pz.ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES - properties.pNext = None + properties.pNext = cast(pointer(index_ext), c_void_p) rc = pz.zesDeviceGetProperties(device_handle, byref(properties)) if not check_rc(f"zesDeviceGetProperties(device {device_index})", rc): @@ -616,6 +638,26 @@ def test_global_operation(driver_handle, device_handle, device_index): print_verbose(f" Vendor ID: 0x{properties.core.vendorId:04X}") print_verbose(f" Device ID: 0x{properties.core.deviceId:04X}") + # Drivers leave extension structures they don't support untouched + print_verbose( + "\n=== Device Index Extension (zes_device_index_ext_properties_t) ===" + ) + print_verbose(f" Device Index: {index_ext.deviceIndex}") + + print_verbose( + "\n=== GPU Topology Extension (zes_device_gpu_topology_ext_properties_t) ===" + ) + generation_name = topology_ext.generationName.decode("utf-8", errors="ignore") + if generation_name or topology_ext.numXeCores: + print_verbose(f" Generation Name: {generation_name}") + print_verbose(f" Slices: {topology_ext.numSlices}") + print_verbose(f" Xe Cores: {topology_ext.numXeCores}") + print_verbose(f" Vector Engines: {topology_ext.numVectorEngines}") + print_verbose(f" Matrix Engines: {topology_ext.numMatrixEngines}") + print_verbose(f" Hardware Threads: {topology_ext.numThreads}") + else: + print_verbose(" GPU topology extension not filled in by the driver") + # Test Subdevice Properties (Experimental API) print_verbose("\n=== Subdevice Properties Test (Experimental) ===") if properties.numSubdevices > 0: @@ -741,9 +783,13 @@ def test_pci_module(device_handle, device_index): """Test PCI properties, state, and stats operations""" print(f"\n---- Device {device_index} PCI Test ----") + config_props = pz.zes_pci_config_properties_t() + config_props.stype = pz.ZES_STRUCTURE_TYPE_PCI_CONFIG_PROPERTIES + config_props.pNext = None + properties = pz.zes_pci_properties_t() properties.stype = pz.ZES_STRUCTURE_TYPE_PCI_PROPERTIES - properties.pNext = None + properties.pNext = cast(pointer(config_props), c_void_p) rc = pz.zesDevicePciGetProperties(device_handle, byref(properties)) if not check_rc(f"zesDevicePciGetProperties(device {device_index})", rc): @@ -763,6 +809,25 @@ def test_pci_module(device_handle, device_index): print_verbose(f" Have Packet Counters: {bool(properties.havePacketCounters)}") print_verbose(f" Have Replay Counters: {bool(properties.haveReplayCounters)}") + print_verbose("\n=== PCI Config Properties (zes_pci_config_properties_t) ===") + if config_props.vendorId or config_props.deviceId: + print_verbose(f" Vendor ID: 0x{config_props.vendorId:04X}") + print_verbose(f" Device ID: 0x{config_props.deviceId:04X}") + print_verbose(f" Subsystem Vendor ID: 0x{config_props.subsystemVendorId:04X}") + print_verbose(f" Subsystem Device ID: 0x{config_props.subsystemDeviceId:04X}") + revision_note = ( + " (device not responding)" if config_props.revision == 0xFF else "" + ) + print_verbose(f" Revision: 0x{config_props.revision:02X}{revision_note}") + print_verbose( + f" PCIe Capability Version: {config_props.pcieCapabilityVersion}" + ) + print_verbose( + f" Supported Link Speeds: {get_pci_link_speeds_string(config_props.supportedLinkSpeeds)}" + ) + else: + print_verbose(" PCI config properties not filled in by the driver") + state = pz.zes_pci_state_t() state.stype = pz.ZES_STRUCTURE_TYPE_PCI_STATE state.pNext = None @@ -1920,8 +1985,77 @@ def print_received_events(device_count, num_device_events, events, driver_events ) +def test_driver_pci_device_properties(driver_handle, driver_index): + """List every supported device on the PCI bus, including devices with no KMD bound""" + pci_count = c_uint32(0) + rc = pz.zesDriverGetPciDeviceProperties(driver_handle, byref(pci_count), None) + if rc == pz.ZE_RESULT_ERROR_UNSUPPORTED_FEATURE: + print_verbose(" PCI Device Properties: Not supported by the driver") + return True + if not check_rc( + f"zesDriverGetPciDeviceProperties(driver {driver_index}, count)", rc + ): + return False + + print_verbose(f" Found {pci_count.value} PCI device(s)") + if pci_count.value == 0: + return True + + pci_devices = (pz.zes_driver_pci_device_properties_t * pci_count.value)() + for i in range(pci_count.value): + pci_devices[i].stype = pz.ZES_STRUCTURE_TYPE_DRIVER_PCI_DEVICE_PROPERTIES + pci_devices[i].pNext = None + pci_devices[i].configProperties.stype = ( + pz.ZES_STRUCTURE_TYPE_PCI_CONFIG_PROPERTIES + ) + pci_devices[i].configProperties.pNext = None + + rc = pz.zesDriverGetPciDeviceProperties( + driver_handle, byref(pci_count), pci_devices + ) + if not check_rc( + f"zesDriverGetPciDeviceProperties(driver {driver_index}, data)", rc + ): + return False + + for i in range(pci_count.value): + pci_device = pci_devices[i] + address = pci_device.address + config = pci_device.configProperties + print_verbose( + f" PCI Device {i}: {address.domain:04x}:{address.bus:02x}:" + f"{address.device:02x}.{address.function:x}" + ) + print_verbose( + f" Vendor ID: 0x{config.vendorId:04X}, Device ID: 0x{config.deviceId:04X}" + ) + print_verbose( + f" Subsystem Vendor ID: 0x{config.subsystemVendorId:04X}, " + f"Subsystem Device ID: 0x{config.subsystemDeviceId:04X}" + ) + revision_note = " (device not responding)" if config.revision == 0xFF else "" + print_verbose(f" Revision: 0x{config.revision:02X}{revision_note}") + print_verbose(f" PCIe Capability Version: {config.pcieCapabilityVersion}") + print_verbose( + f" Supported Link Speeds: {get_pci_link_speeds_string(config.supportedLinkSpeeds)}" + ) + max_speed = pci_device.maxSpeed + if max_speed.gen < 0 and max_speed.width < 0: + print_verbose(" Max Speed: Unknown") + else: + print_verbose( + f" Max Speed: Gen {max_speed.gen}, Width x{max_speed.width}, " + f"Bandwidth {max_speed.maxBandwidth} bytes/s" + ) + print_verbose( + f" Link Status: {get_pci_link_status_string(pci_device.status)}" + ) + + return True + + def test_driver_properties_module(driver_handle, driver_index): - """Test driver properties, extensions, and the extension function lookup""" + """Test driver properties, API version, PCI device list, extensions, and the extension function lookup""" print(f"\n---- Driver {driver_index} Driver Properties Test ----") props = pz.zes_driver_properties_t() @@ -1936,6 +2070,16 @@ def test_driver_properties_module(driver_handle, driver_index): ) print_verbose(f" Driver Version: {props.driverVersion}") + api_version = pz.zes_api_version_t() + rc = pz.zesDriverGetApiVersion(driver_handle, byref(api_version)) + if check_rc(f"zesDriverGetApiVersion(driver {driver_index})", rc): + print_verbose( + f" Sysman API Version: {pz.ZES_MAJOR_VERSION(api_version.value)}." + f"{pz.ZES_MINOR_VERSION(api_version.value)}" + ) + + test_driver_pci_device_properties(driver_handle, driver_index) + ext_count = c_uint32(0) rc = pz.zesDriverGetExtensionProperties(driver_handle, byref(ext_count), None) if check_rc(f"zesDriverGetExtensionProperties(driver {driver_index}, count)", rc): diff --git a/bindings/sysman/python/test/unit_tests/test_device.py b/bindings/sysman/python/test/unit_tests/test_device.py index edef739c..8e623b57 100644 --- a/bindings/sysman/python/test/unit_tests/test_device.py +++ b/bindings/sysman/python/test/unit_tests/test_device.py @@ -218,6 +218,132 @@ def mock_get_properties(firmware_handle, properties_ptr): mock_get_func.assert_called_with("zesFirmwareGetProperties") mock_func.assert_called_once() + def _walk_device_properties_chain(self, properties): + """Fills chained extensions the way the driver would, keyed on stype.""" + pyzes = self.pyzes + pNext = properties.pNext + while pNext: + base = cast(pNext, POINTER(pyzes.zes_device_index_ext_properties_t)) + stype = base.contents.stype + if stype == pyzes.ZES_STRUCTURE_TYPE_DEVICE_INDEX_EXT_PROPERTIES: + base.contents.deviceIndex = 2 + pNext = base.contents.pNext + elif stype == pyzes.ZES_STRUCTURE_TYPE_DEVICE_GPU_TOPOLOGY_EXT_PROPERTIES: + topo = cast( + pNext, POINTER(pyzes.zes_device_gpu_topology_ext_properties_t) + ).contents + topo.numSlices = 1 + topo.numXeCores = 32 + topo.numVectorEngines = 256 + topo.numMatrixEngines = 256 + topo.numThreads = 2048 + topo.generationName = b"xe3p" + pNext = topo.pNext + else: + self.fail(f"unexpected stype 0x{stype:X} in pNext chain") + + def test_GivenDeviceIndexExtChainedWhenCallingZesDeviceGetPropertiesThenDeviceIndexIsReturned( + self, mock_get_func + ): + def mock_get_properties(device_handle, properties_ptr): + properties = properties_ptr._obj + properties.numSubdevices = 0 + self._walk_device_properties_chain(properties) + return self.pyzes.ZE_RESULT_SUCCESS + + mock_func = MagicMock(side_effect=mock_get_properties) + mock_get_func.return_value = mock_func + + index_ext = self.pyzes.zes_device_index_ext_properties_t() + index_ext.stype = self.pyzes.ZES_STRUCTURE_TYPE_DEVICE_INDEX_EXT_PROPERTIES + index_ext.pNext = None + + properties = self.pyzes.zes_device_properties_t() + properties.stype = self.pyzes.ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES + properties.pNext = cast(pointer(index_ext), c_void_p) + + result = self.pyzes.zesDeviceGetProperties( + self.pyzes.zes_device_handle_t(), byref(properties) + ) + + self.assertEqual(result, self.pyzes.ZE_RESULT_SUCCESS) + self.assertEqual(index_ext.deviceIndex, 2) + self.assertEqual( + self.pyzes.ZES_STRUCTURE_TYPE_DEVICE_INDEX_EXT_PROPERTIES, 0x00020026 + ) + mock_get_func.assert_called_with("zesDeviceGetProperties") + mock_func.assert_called_once() + + def test_GivenGpuTopologyExtChainedWhenCallingZesDeviceGetPropertiesThenTopologyIsReturned( + self, mock_get_func + ): + def mock_get_properties(device_handle, properties_ptr): + self._walk_device_properties_chain(properties_ptr._obj) + return self.pyzes.ZE_RESULT_SUCCESS + + mock_func = MagicMock(side_effect=mock_get_properties) + mock_get_func.return_value = mock_func + + topo_ext = self.pyzes.zes_device_gpu_topology_ext_properties_t() + topo_ext.stype = ( + self.pyzes.ZES_STRUCTURE_TYPE_DEVICE_GPU_TOPOLOGY_EXT_PROPERTIES + ) + topo_ext.pNext = None + + properties = self.pyzes.zes_device_properties_t() + properties.stype = self.pyzes.ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES + properties.pNext = cast(pointer(topo_ext), c_void_p) + + result = self.pyzes.zesDeviceGetProperties( + self.pyzes.zes_device_handle_t(), byref(properties) + ) + + self.assertEqual(result, self.pyzes.ZE_RESULT_SUCCESS) + self.assertEqual(topo_ext.numSlices, 1) + self.assertEqual(topo_ext.numXeCores, 32) + self.assertEqual(topo_ext.numVectorEngines, 256) + self.assertEqual(topo_ext.numMatrixEngines, 256) + self.assertEqual(topo_ext.numThreads, 2048) + self.assertEqual(topo_ext.generationName, b"xe3p") + self.assertEqual( + self.pyzes.ZES_STRUCTURE_TYPE_DEVICE_GPU_TOPOLOGY_EXT_PROPERTIES, + 0x00020027, + ) + mock_get_func.assert_called_with("zesDeviceGetProperties") + mock_func.assert_called_once() + + def test_GivenIndexAndTopologyExtsChainedWhenCallingZesDeviceGetPropertiesThenBothAreFilled( + self, mock_get_func + ): + def mock_get_properties(device_handle, properties_ptr): + self._walk_device_properties_chain(properties_ptr._obj) + return self.pyzes.ZE_RESULT_SUCCESS + + mock_get_func.return_value = MagicMock(side_effect=mock_get_properties) + + topo_ext = self.pyzes.zes_device_gpu_topology_ext_properties_t() + topo_ext.stype = ( + self.pyzes.ZES_STRUCTURE_TYPE_DEVICE_GPU_TOPOLOGY_EXT_PROPERTIES + ) + topo_ext.pNext = None + + index_ext = self.pyzes.zes_device_index_ext_properties_t() + index_ext.stype = self.pyzes.ZES_STRUCTURE_TYPE_DEVICE_INDEX_EXT_PROPERTIES + index_ext.pNext = cast(pointer(topo_ext), c_void_p) + + properties = self.pyzes.zes_device_properties_t() + properties.stype = self.pyzes.ZES_STRUCTURE_TYPE_DEVICE_PROPERTIES + properties.pNext = cast(pointer(index_ext), c_void_p) + + result = self.pyzes.zesDeviceGetProperties( + self.pyzes.zes_device_handle_t(), byref(properties) + ) + + self.assertEqual(result, self.pyzes.ZE_RESULT_SUCCESS) + self.assertEqual(index_ext.deviceIndex, 2) + self.assertEqual(topo_ext.numXeCores, 32) + self.assertEqual(topo_ext.generationName, b"xe3p") + if __name__ == "__main__": unittest.main() diff --git a/bindings/sysman/python/test/unit_tests/test_driver.py b/bindings/sysman/python/test/unit_tests/test_driver.py index 53c9fed9..919cac42 100644 --- a/bindings/sysman/python/test/unit_tests/test_driver.py +++ b/bindings/sysman/python/test/unit_tests/test_driver.py @@ -231,6 +231,137 @@ def mock_listen_ext( mock_get_func.assert_called_with("zesDriverEventListenExt") mock_func.assert_called_once() + def test_GivenValidDriverHandleWhenCallingZesDriverGetApiVersionThenCallSucceedsWithVersion( + self, mock_get_func + ): + def mock_get_api_version(driver_handle, version_ptr): + version_ptr._obj.value = self.pyzes.ZES_API_VERSION_1_21 + return self.pyzes.ZE_RESULT_SUCCESS + + mock_func = MagicMock(side_effect=mock_get_api_version) + mock_get_func.return_value = mock_func + + driver_handle = self.pyzes.zes_driver_handle_t() + version = self.pyzes.zes_api_version_t() + + result = self.pyzes.zesDriverGetApiVersion(driver_handle, byref(version)) + + self.assertEqual(result, self.pyzes.ZE_RESULT_SUCCESS) + self.assertEqual(version.value, self.pyzes.ZES_API_VERSION_1_21) + self.assertEqual(self.pyzes.ZES_MAJOR_VERSION(version.value), 1) + self.assertEqual(self.pyzes.ZES_MINOR_VERSION(version.value), 21) + mock_get_func.assert_called_with("zesDriverGetApiVersion") + mock_func.assert_called_once() + + def test_GivenApiVersionMacrosWhenComputingVersionsThenValuesMatchCHeader( + self, mock_get_func + ): + self.assertEqual(self.pyzes.ZES_MAKE_VERSION(1, 21), 0x00010015) + self.assertEqual(self.pyzes.ZES_API_VERSION_1_0, 0x00010000) + self.assertEqual(self.pyzes.ZES_MAJOR_VERSION(0x00020003), 2) + self.assertEqual(self.pyzes.ZES_MINOR_VERSION(0x00020003), 3) + + def test_GivenValidDriverHandleWhenCallingZesDriverGetPciDevicePropertiesThenCallSucceedsWithValidCount( + self, mock_get_func + ): + mock_count = 2 + + def mock_get_pci_device_properties(driver_handle, count_ptr, properties_ptr): + self.assertFalse(bool(properties_ptr)) + count_ptr._obj.value = mock_count + return self.pyzes.ZE_RESULT_SUCCESS + + mock_func = MagicMock(side_effect=mock_get_pci_device_properties) + mock_get_func.return_value = mock_func + + driver_handle = self.pyzes.zes_driver_handle_t() + count = c_uint32(0) + + result = self.pyzes.zesDriverGetPciDeviceProperties( + driver_handle, byref(count), None + ) + + self.assertEqual(result, self.pyzes.ZE_RESULT_SUCCESS) + self.assertEqual(count.value, mock_count) + mock_get_func.assert_called_with("zesDriverGetPciDeviceProperties") + mock_func.assert_called_once() + + def test_GivenValidDriverHandleWhenCallingZesDriverGetPciDevicePropertiesWithArrayThenCallSucceedsWithProperties( + self, mock_get_func + ): + mock_count = 2 + + def mock_get_pci_device_properties(driver_handle, count_ptr, properties_ptr): + count_ptr._obj.value = mock_count + for i in range(mock_count): + props = properties_ptr[i] + props.address.domain = 0 + props.address.bus = 0x03 + i + props.address.device = 0 + props.address.function = 0 + props.maxSpeed.gen = -1 + props.maxSpeed.width = -1 + props.maxSpeed.maxBandwidth = -1 + props.status = self.pyzes.ZES_PCI_LINK_STATUS_GOOD + props.configProperties.stype = ( + self.pyzes.ZES_STRUCTURE_TYPE_PCI_CONFIG_PROPERTIES + ) + props.configProperties.vendorId = 0x8086 + props.configProperties.deviceId = 0x674C + props.configProperties.subsystemVendorId = 0x8086 + props.configProperties.subsystemDeviceId = 0x1234 + props.configProperties.supportedLinkSpeeds = ( + self.pyzes.ZES_PCI_LINK_SPEED_FLAG_GEN1 + | self.pyzes.ZES_PCI_LINK_SPEED_FLAG_GEN5 + ) + # second device has a revision of 0xFF (device fell off the bus) + properties_ptr[0].configProperties.revision = 0x01 + properties_ptr[1].configProperties.revision = 0xFF + return self.pyzes.ZE_RESULT_SUCCESS + + mock_func = MagicMock(side_effect=mock_get_pci_device_properties) + mock_get_func.return_value = mock_func + + driver_handle = self.pyzes.zes_driver_handle_t() + count = c_uint32(mock_count) + properties = (self.pyzes.zes_driver_pci_device_properties_t * mock_count)() + for i in range(mock_count): + properties[i].stype = ( + self.pyzes.ZES_STRUCTURE_TYPE_DRIVER_PCI_DEVICE_PROPERTIES + ) + properties[i].pNext = None + + result = self.pyzes.zesDriverGetPciDeviceProperties( + driver_handle, byref(count), properties + ) + + self.assertEqual(result, self.pyzes.ZE_RESULT_SUCCESS) + self.assertEqual(count.value, mock_count) + self.assertEqual(properties[0].address.bus, 0x03) + self.assertEqual(properties[1].address.bus, 0x04) + self.assertEqual(properties[0].maxSpeed.gen, -1) + self.assertEqual(properties[0].status, self.pyzes.ZES_PCI_LINK_STATUS_GOOD) + self.assertEqual(properties[0].configProperties.vendorId, 0x8086) + self.assertEqual(properties[0].configProperties.deviceId, 0x674C) + self.assertEqual(properties[0].configProperties.subsystemDeviceId, 0x1234) + self.assertEqual(properties[0].configProperties.supportedLinkSpeeds, 0x11) + self.assertEqual(properties[0].configProperties.revision, 0x01) + self.assertEqual(properties[1].configProperties.revision, 0xFF) + mock_get_func.assert_called_with("zesDriverGetPciDeviceProperties") + mock_func.assert_called_once() + + def test_GivenPciConfigPropertiesStructWhenCheckingLayoutThenSizeMatchesCStruct( + self, mock_get_func + ): + # stype(4) + pad(4) + pNext(8) + 4*uint16(8) + 2*uint32(8) + uint8(1) + pad(7) + self.assertEqual(sizeof(self.pyzes.zes_pci_config_properties_t), 40) + self.assertEqual( + self.pyzes.ZES_STRUCTURE_TYPE_PCI_CONFIG_PROPERTIES, 0x00020024 + ) + self.assertEqual( + self.pyzes.ZES_STRUCTURE_TYPE_DRIVER_PCI_DEVICE_PROPERTIES, 0x00020025 + ) + if __name__ == "__main__": unittest.main() diff --git a/bindings/sysman/python/test/unit_tests/test_init.py b/bindings/sysman/python/test/unit_tests/test_init.py index c2585dee..6b1e3322 100644 --- a/bindings/sysman/python/test/unit_tests/test_init.py +++ b/bindings/sysman/python/test/unit_tests/test_init.py @@ -214,5 +214,12 @@ def test_GivenWindowsPlatformWhenLoadingLibraryThenLibraryIsLoaded( self.assertIsNotNone(self.pyzes.gpuLib) +class TestLinuxLoaderNames(unittest.TestCase): + def setUp(self): + import pyzes + + self.pyzes = pyzes + + if __name__ == "__main__": unittest.main()