Created
March 9, 2026 11:05
-
-
Save jaromil/3891eb08bd1af6413113d2ff92c7fc6a to your computer and use it in GitHub Desktop.
Detects available GPU and NPU devices by probing ONNX Runtime, OpenVINO, and Windows device information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This script is a compact hardware probe that tries to identify GPU and NPU acceleration devices available on the local | |
| # machine. It first checks ONNX Runtime execution providers and EP device metadata when onnxruntime is installed, then | |
| # queries OpenVINO for any exposed devices, and finally falls back to a Windows PnP device-name scan to catch hardware that | |
| # may be present even when runtime libraries are missing. The goal is not deep validation or benchmarking, but a quick | |
| # practical signal of whether the system appears to expose GPU or NPU-capable hardware that could be used for inference. | |
| import platform | |
| import subprocess | |
| try: | |
| import onnxruntime as ort | |
| except Exception: | |
| ort = None | |
| def ep_devices(): | |
| if ort is None: | |
| return [] | |
| try: | |
| return list(ort.get_ep_devices()) | |
| except Exception: | |
| return [] | |
| def ov_devices(): | |
| try: | |
| import openvino as ov | |
| return list(ov.Core().available_devices) | |
| except Exception: | |
| return [] | |
| def windows_ai_devices(): | |
| if platform.system() != "Windows": | |
| return [] | |
| cmd = [ | |
| "powershell", | |
| "-NoProfile", | |
| "-Command", | |
| "Get-PnpDevice | Where-Object { $_.FriendlyName -match 'NPU|Neural|AI Boost|Adreno|AMD|NVIDIA|Intel' } | Select-Object -ExpandProperty FriendlyName", | |
| ] | |
| try: | |
| out = subprocess.run(cmd, capture_output=True, text=True, check=False).stdout | |
| return [line.strip() for line in out.splitlines() if line.strip()] | |
| except Exception: | |
| return [] | |
| providers = list(ort.get_available_providers()) if ort else [] | |
| devices = ep_devices() | |
| openvino = ov_devices() | |
| windows = windows_ai_devices() | |
| gpu_hits = [] | |
| npu_hits = [] | |
| for d in devices: | |
| ep = getattr(d, "ep_name", "") | |
| hw = getattr(d, "hardware_device", None) or getattr(d, "device", None) | |
| kind = str(getattr(hw, "type", getattr(d, "device_type", ""))).upper() | |
| dev_id = getattr(hw, "device_id", getattr(d, "device_id", "?")) | |
| row = f"{ep} | {kind or 'UNKNOWN'} | id={dev_id}" | |
| if "GPU" in kind: | |
| gpu_hits.append(row) | |
| if "NPU" in kind: | |
| npu_hits.append(row) | |
| for name in openvino: | |
| row = f"OpenVINO | {name}" | |
| if "GPU" in name.upper(): | |
| gpu_hits.append(row) | |
| if "NPU" in name.upper(): | |
| npu_hits.append(row) | |
| for name in windows: | |
| upper = name.upper() | |
| if any(x in upper for x in ("NVIDIA", "AMD", "INTEL", "ADRENO", "GPU")): | |
| gpu_hits.append(f"Windows PnP | {name}") | |
| if any(x in upper for x in ("NPU", "NEURAL", "AI BOOST")): | |
| npu_hits.append(f"Windows PnP | {name}") | |
| print("ONNX Runtime version:", ort.__version__ if ort else "not installed") | |
| print("Providers:", providers) | |
| print("GPU detected:", bool(gpu_hits) or any(p in providers for p in ("CUDAExecutionProvider", "DmlExecutionProvider", "OpenVINOExecutionProvider", "ROCMExecutionProvider", "CoreMLExecutionProvider"))) | |
| for item in gpu_hits: | |
| print(" ", item) | |
| print("NPU detected:", bool(npu_hits) or any(p in providers for p in ("QNNExecutionProvider", "VitisAIExecutionProvider"))) | |
| for item in npu_hits: | |
| print(" ", item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment