From d905f1350a86e80e5b2e68f0a812d4a6bf91f6ec Mon Sep 17 00:00:00 2001 From: "Yu, Guangye" Date: Wed, 27 Nov 2024 16:56:56 +0000 Subject: [PATCH] Friendly catch exception when fail to initialize XPU devices (#141658) Pull Request resolved: https://github.com/pytorch/pytorch/pull/141658 Approved by: https://github.com/EikanWang --- c10/xpu/XPUFunctions.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/c10/xpu/XPUFunctions.cpp b/c10/xpu/XPUFunctions.cpp index e0d7e6d075f..1e74626ec2e 100644 --- a/c10/xpu/XPUFunctions.cpp +++ b/c10/xpu/XPUFunctions.cpp @@ -44,8 +44,18 @@ void enumDevices(std::vector>& devices) { } inline void initGlobalDevicePoolState() { - // Enumerate all GPU devices and record them. - enumDevices(gDevicePool.devices); + // Attempt to initialize XPU devices. If no device is found or the driver is + // not installed correctly, issue a warning message instead of raising an + // exception to avoid disrupting the user experience. + try { + // Enumerate all GPU devices and record them. + enumDevices(gDevicePool.devices); + } catch (const sycl::exception& e) { + TORCH_WARN( + "Failed to initialize XPU devices. The driver may not be installed, installed incorrectly, or incompatible with the current setup. ", + "Please refer to the guideline (https://github.com/pytorch/pytorch?tab=readme-ov-file#intel-gpu-support) for proper installation and configuration."); + return; + } if (gDevicePool.devices.empty()) { TORCH_WARN("XPU device count is zero!"); return;