Skip to content

Commit d71297f

Browse files
authored
[XPU] Changed how XPU discovery works during setup.py (#720)
## Summary Right now we check `xpu-smi` during installation to find out if machine has XPU device. But `xpu-smi` is often missing from user devices, so we end up discovering incorrect platform (`cpu`) and then try to install wrong `triton` dependency. User ends up with `triton-xpu` being overwritten by `triton`. This combination doesn't work. So I check `sycl-ls` which should be available. The output I get on PVC machine: ``` [level_zero:gpu][level_zero:0] Intel(R) oneAPI Unified Runtime over Level-Zero, Intel(R) Data Center GPU Max 1100 12.60.7 [1.6.32567+18] [opencl:cpu][opencl:0] Intel(R) OpenCL, Intel(R) Xeon(R) Gold 6438Y+ OpenCL 3.0 (Build 0) [2024.18.12.0.05_160000] [opencl:gpu][opencl:1] Intel(R) OpenCL Graphics, Intel(R) Data Center GPU Max 1100 OpenCL 3.0 NEO [25.05.32567] ``` The output I get on B570 machine: ``` [level_zero:gpu][level_zero:0] Intel(R) oneAPI Unified Runtime over Level-Zero, Intel(R) Arc(TM) B570 Graphics 20.1.0 [1.6.32567+19] [opencl:cpu][opencl:0] Intel(R) OpenCL, Intel(R) Core(TM) Ultra 7 265K OpenCL 3.0 (Build 0) [2025.19.4.0.18_160000.xmain-hotfix] [opencl:gpu][opencl:1] Intel(R) OpenCL Graphics, Intel(R) Arc(TM) B570 Graphics OpenCL 3.0 NEO [25.05.32567] ``` ## Possible alternative We could just import pytorch and check `torch.xpu.is_available()`. It might even be better that way, since right now if user is missing torch we will try to install cuda torch even for XPU devices. ## Testing Done I tested it by installing on new conda environment from the source code with: ``` pip install torch==2.7.0 torchvision==0.22.0 torchaudio==2.7.0 --index-url https://download.pytorch.org/whl/xpu --no-cache-dir pip install -e . ``` - Hardware Type: XPU - [ ] run `make test` to ensure correctness - [ ] run `make checkstyle` to ensure code style - [ ] run `make test-convergence` to ensure convergence
1 parent ab97c4b commit d71297f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

setup.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ def get_optional_dependencies():
4747
}
4848

4949

50+
def is_xpu_available():
51+
"""
52+
Check if Intel XPU is available.
53+
xpu-smi is often missing right now.
54+
"""
55+
try:
56+
subprocess.run(["xpu-smi"], check=True)
57+
return True
58+
except (subprocess.SubprocessError, FileNotFoundError):
59+
pass
60+
61+
try:
62+
result = subprocess.run("sycl-ls", check=True, capture_output=True, shell=True)
63+
if 'level_zero:gpu' in result.stdout.decode():
64+
return True
65+
except (subprocess.SubprocessError, FileNotFoundError):
66+
pass
67+
68+
return False
69+
70+
5071
def get_platform() -> Literal["cuda", "rocm", "cpu", "xpu"]:
5172
"""
5273
Detect whether the system has NVIDIA or AMD GPU without torch dependency.
@@ -63,11 +84,10 @@ def get_platform() -> Literal["cuda", "rocm", "cpu", "xpu"]:
6384
print("ROCm GPU detected")
6485
return "rocm"
6586
except (subprocess.SubprocessError, FileNotFoundError):
66-
try:
67-
subprocess.run(["xpu-smi"], check=True)
87+
if is_xpu_available():
6888
print("Intel GPU detected")
6989
return "xpu"
70-
except (subprocess.SubprocessError, FileNotFoundError):
90+
else:
7191
print("No GPU detected")
7292
return "cpu"
7393

0 commit comments

Comments
 (0)