Remove auto-detection for XPU on Windows

This commit is contained in:
Yu, Guangye 2025-07-06 13:32:07 +00:00
parent 2fdfe34853
commit 5bb8b45e33
5 changed files with 11 additions and 33 deletions

1
Cargo.lock generated
View file

@ -5906,7 +5906,6 @@ dependencies = [
"clap", "clap",
"either", "either",
"fs-err 3.1.1", "fs-err 3.1.1",
"regex",
"schemars", "schemars",
"serde", "serde",
"thiserror 2.0.12", "thiserror 2.0.12",

View file

@ -19,7 +19,6 @@ uv-static = { workspace = true }
clap = { workspace = true, optional = true } clap = { workspace = true, optional = true }
either = { workspace = true } either = { workspace = true }
fs-err = { workspace = true } fs-err = { workspace = true }
regex = { workspace = true }
schemars = { workspace = true, optional = true } schemars = { workspace = true, optional = true }
serde = { workspace = true } serde = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }

View file

@ -1,7 +1,6 @@
use std::path::Path; use std::path::Path;
use std::str::FromStr; use std::str::FromStr;
use regex::Regex;
use tracing::debug; use tracing::debug;
use walkdir::WalkDir; use walkdir::WalkDir;
@ -64,7 +63,6 @@ impl Accelerator {
/// 5. `nvidia-smi --query-gpu=driver_version --format=csv,noheader`. /// 5. `nvidia-smi --query-gpu=driver_version --format=csv,noheader`.
/// 6. `rocm_agent_enumerator`, which lists the AMD GPU architectures. /// 6. `rocm_agent_enumerator`, which lists the AMD GPU architectures.
/// 7. `/sys/bus/pci/devices`, filtering for the Intel GPU via PCI. /// 7. `/sys/bus/pci/devices`, filtering for the Intel GPU via PCI.
/// 8. `powershell` command querying `Win32_VideoController` to detect Intel GPU.
pub fn detect() -> Result<Option<Self>, AcceleratorError> { pub fn detect() -> Result<Option<Self>, AcceleratorError> {
// Constants used for PCI device detection // Constants used for PCI device detection
const PCI_BASE_CLASS_MASK: u32 = 0x00ff_0000; const PCI_BASE_CLASS_MASK: u32 = 0x00ff_0000;
@ -202,33 +200,6 @@ impl Accelerator {
} }
} }
// Query Intel GPU by `powershell` command via `Win32_VideoController`.
//
// See: https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-videocontroller
if let Ok(output) = std::process::Command::new("powershell")
.arg("-Command")
.arg("Get-WmiObject Win32_VideoController | Select-Object -ExpandProperty PNPDeviceID")
.output()
{
if output.status.success() {
let stdout = String::from_utf8(output.stdout)?;
let re = Regex::new(r"VEN_([0-9A-Fa-f]{4})").unwrap();
for caps in re.captures_iter(&stdout) {
let vendor = u32::from_str_radix(&caps[1], 16)?;
if vendor == PCI_VENDOR_ID_INTEL {
debug!("Detected Intel GPU from PCI, vendor=0x{:04x}", vendor);
return Ok(Some(Self::Xpu));
}
}
} else {
debug!(
"Failed to query Intel GPU with powershell with status `{}`: {}",
output.status,
String::from_utf8_lossy(&output.stderr)
);
}
}
debug!("Failed to detect GPU driver version"); debug!("Failed to detect GPU driver version");
Ok(None) Ok(None)

View file

@ -351,10 +351,11 @@ impl TorchStrategy {
} }
}, },
TorchStrategy::Xpu { os } => match os { TorchStrategy::Xpu { os } => match os {
Os::Manylinux { .. } | Os::Windows => Either::Right(Either::Right(Either::Left( Os::Manylinux { .. } => Either::Right(Either::Right(Either::Left(
std::iter::once(TorchBackend::Xpu.index_url()), std::iter::once(TorchBackend::Xpu.index_url()),
))), ))),
Os::Musllinux { .. } Os::Windows
| Os::Musllinux { .. }
| Os::Macos { .. } | Os::Macos { .. }
| Os::FreeBsd { .. } | Os::FreeBsd { .. }
| Os::NetBsd { .. } | Os::NetBsd { .. }

View file

@ -460,4 +460,12 @@ $ # With an environment variable.
$ UV_TORCH_BACKEND=cu126 uv pip install torch torchvision $ UV_TORCH_BACKEND=cu126 uv pip install torch torchvision
``` ```
On Windows, Intel GPU (XPU) is not automatically selected with `--torch-backend=auto`, but you can
manually specify it using `--torch-backend=xpu`:
```shell
$ # Manual selection for Intel GPU.
$ uv pip install torch torchvision --torch-backend=xpu
```
At present, `--torch-backend` is only available in the `uv pip` interface. At present, `--torch-backend` is only available in the `uv pip` interface.