Skip to content

Commit

Permalink
Friendly handle mem_get_info's runtime error message (pytorch#146899)
Browse files Browse the repository at this point in the history
# Motivation
Friendly handle the runtime error message if the device doesn't support querying the available free memory. See intel/torch-xpu-ops#1352

Pull Request resolved: pytorch#146899
Approved by: https://github.com/EikanWang
  • Loading branch information
guangyey authored and Ryo-not-rio committed Feb 24, 2025
1 parent 6f05cd2 commit 24532f8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions torch/csrc/xpu/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,15 @@ static void initXpuMethodBindings(PyObject* module) {
m.def("_xpu_getMemoryInfo", [](c10::DeviceIndex device_index) {
#if SYCL_COMPILER_VERSION >= 20250000
auto total = at::xpu::getDeviceProperties(device_index)->global_mem_size;
auto free = c10::xpu::get_raw_device(device_index)
.get_info<sycl::ext::intel::info::device::free_memory>();
auto& device = c10::xpu::get_raw_device(device_index);
TORCH_CHECK(
device.has(sycl::aspect::ext_intel_free_memory),
"The device (",
at::xpu::getDeviceProperties(device_index)->name,
") doesn't support querying the available free memory. ",
"You can file an issue at https://github.com/pytorch/pytorch/issues ",
"to help us prioritize its implementation.");
auto free = device.get_info<sycl::ext::intel::info::device::free_memory>();
return std::make_tuple(free, total);
#else
TORCH_CHECK_NOT_IMPLEMENTED(
Expand Down

0 comments on commit 24532f8

Please sign in to comment.