Skip to content

Commit cd0ab93

Browse files
committed
Support INTEL_VARIANT_PROVIDER_FORCE_DEVICE_IP
Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
1 parent b4066c7 commit cd0ab93

4 files changed

Lines changed: 72 additions & 36 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ powershell -c { $env:INSTALLER_DOWNLOAD_URL = 'https://wheelnext.astral.sh/v0.0.
5353
* Each value (`<ip>`) in the list represents human readable form of
5454
Intel hardware device IP (GMDID) quariable via Level Zero [ZE_extension_device_ip_version]
5555

56+
## Environment variables
57+
58+
`INTEL_VARIANT_PROVIDER_FORCE_DEVICE_IP` allows to override GPU architecture detection
59+
performed by plugin. **DISCLAIMER:** this is debug and test purpose variable as it can
60+
lead to a non-functional installation.
61+
5662
## WheelNext package index
5763

5864
[WheelNext] initiative supports aggregated index of the packages which are enabled with variant providers.
@@ -75,7 +81,7 @@ namespace = ["intel"]
7581
7682
[variant.providers.intel]
7783
requires = ["intel_variant_provider"]
78-
enable-if = "platform_system == 'Linux'"
84+
enable-if = "platform_system == 'Linux' or platform_system == 'Windows'"
7985
plugin-api = "intel_variant_provider.plugin:IntelVariantPlugin"
8086
```
8187

intel_variant_provider/devices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
},
7777
}
7878

79-
def get_all_ips():
79+
def get_all_known_ips():
8080
return list(_intel_devips.keys())
8181

8282
# See: https://github.com/intel/compute-runtime/blob/25.27.34303.6/shared/source/helpers/hw_ip_version.h

intel_variant_provider/plugin.py

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,49 +24,62 @@ class VariantFeatureConfig:
2424
multi_value: bool = False
2525

2626

27+
def getAllUniqueDeviceIPs():
28+
pci_vendor_id_intel = 0x8086
29+
devips = []
30+
try:
31+
desc = c_ze_init_driver_type_desc_t()
32+
desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_GPU
33+
drivers = zeInitDrivers(desc)
34+
35+
for driver in drivers:
36+
devices = zeDeviceGet(driver)
37+
for device in devices:
38+
devip = c_ze_device_ip_version_ext_t()
39+
props = zeDeviceGetProperties(device, [devip])
40+
if props.vendorId == pci_vendor_id_intel:
41+
devip = IntelDeviceIp(devip.ipVersion)
42+
for ip in devip.get_all_compat_ips():
43+
# We must return list of unique IPs as a requirement
44+
# of variantlib.
45+
if ip not in devips:
46+
devips.append(ip)
47+
except Exception as e:
48+
warnings.warn(f"Intel driver stack not installed or malfunctions: {e}", UserWarning, stacklevel=1)
49+
return devips
50+
51+
2752
class IntelVariantPlugin:
2853
namespace = "intel"
2954
dynamic = False
3055

3156
@classmethod
3257
@cache
3358
def generate_all_device_ips(cls) -> list[str] | None:
34-
pci_vendor_id_intel = 0x8086
35-
3659
if platform.system() not in ["Linux", "Windows"]:
3760
warnings.warn(f"Unsupported OS: {system}", UserWarning, stacklevel=1)
3861
return []
3962

40-
try:
41-
desc = c_ze_init_driver_type_desc_t()
42-
desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_GPU
43-
drivers = zeInitDrivers(desc)
44-
45-
devips = []
46-
for driver in drivers:
47-
devices = zeDeviceGet(driver)
48-
for device in devices:
49-
devip = c_ze_device_ip_version_ext_t()
50-
props = zeDeviceGetProperties(device, [devip])
51-
if props.vendorId == pci_vendor_id_intel:
52-
devip = IntelDeviceIp(devip.ipVersion)
53-
for ip in devip.get_all_compat_ips():
54-
# Filter out devices which IPs are not explicitly
55-
# known to plugin. This gives consistency with the
56-
# check in validate_property().
57-
if ip not in get_all_ips():
58-
warnings.warn(f"Intel device with {ip} device IP is filtered out as not known to plugin)")
59-
continue
60-
# We must return list of unique IPs as a requirement
61-
# of variantlib.
62-
if ip not in devips:
63-
devips.append(ip)
64-
if not devips:
65-
warnings.warn("No Intel GPU detected", UserWarning, stacklevel=1)
66-
return devips
67-
except Exception as e:
68-
warnings.warn(f"Intel driver stack not installed or malfunctions: {e}", UserWarning, stacklevel=1)
69-
return []
63+
devip = os.getenv("INTEL_VARIANT_PROVIDER_FORCE_DEVICE_IP")
64+
if devip:
65+
unique_devips = [devip]
66+
else:
67+
unique_devips = getAllUniqueDeviceIPs()
68+
69+
devips = []
70+
known_ips = get_all_known_ips()
71+
for ip in unique_devips:
72+
# Filter out devices which IPs are not explicitly
73+
# known to plugin. This gives consistency with the
74+
# check in validate_property().
75+
if ip not in known_ips:
76+
warnings.warn(f"Intel device with {ip} device IP is filtered out as not known to plugin)")
77+
else:
78+
devips.append(ip)
79+
80+
if not devips:
81+
warnings.warn("No Intel GPU detected", UserWarning, stacklevel=1)
82+
return devips
7083

7184
@classmethod
7285
def get_supported_configs(cls) -> list[VariantFeatureConfig]:
@@ -88,7 +101,7 @@ def get_all_configs(cls) -> list[VariantFeatureConfig]:
88101
return [
89102
VariantFeatureConfig(
90103
name="device_ip",
91-
values=get_all_ips(),
104+
values=get_all_known_ips(),
92105
multi_value=True,
93106
),
94107
]

tests/test_plugin.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66
# to internal module variables (such as _g_zelib).
77
import intel_variant_provider.ze as ze
88
from intel_variant_provider.devices import _intel_devips
9-
from intel_variant_provider.plugin import IntelVariantPlugin
9+
from intel_variant_provider.plugin import IntelVariantPlugin, VariantFeatureConfig
1010
from intel_variant_provider.ze import *
1111

1212

1313
@pytest.fixture
1414
def plugin() -> IntelVariantPlugin:
1515
return IntelVariantPlugin()
1616

17+
@pytest.fixture(autouse=True)
18+
def clear_cache():
19+
IntelVariantPlugin.generate_all_device_ips.cache_clear()
20+
21+
1722
def test_get_all_configs(plugin):
1823
configs = plugin.get_all_configs()
1924
assert len(configs) == 1
@@ -40,3 +45,15 @@ def test_no_L0_library(self, plugin, mocker):
4045
mocker.patch(self.cdll_name, side_effect=OSError("No such file"))
4146
with pytest.warns(UserWarning):
4247
assert not plugin.get_supported_configs()
48+
49+
def test_force_existing_ip(self, plugin, monkeypatch):
50+
monkeypatch.setenv("INTEL_VARIANT_PROVIDER_FORCE_DEVICE_IP", "12.60.7")
51+
assert plugin.get_supported_configs() == [
52+
VariantFeatureConfig(name="device_ip", values=["12.60.7"], multi_value=True)
53+
]
54+
55+
def test_force_invalid_ip(self, plugin, monkeypatch):
56+
monkeypatch.setenv("INTEL_VARIANT_PROVIDER_FORCE_DEVICE_IP", "12.99.99")
57+
with pytest.warns(UserWarning):
58+
assert not plugin.get_supported_configs()
59+

0 commit comments

Comments
 (0)