Add uuid to XPU device properties (#161392)

# Motivation
Fix https://github.com/intel/torch-xpu-ops/issues/1955
Refer to https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/supported/sycl_ext_intel_device_info.md#device-uuid, `ext::intel::info::device::uuid` returns `std::array<unsigned char, 16>` as the UUID.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/161392
Approved by: https://github.com/EikanWang, https://github.com/albanD
This commit is contained in:
Yu, Guangye
2025-09-01 14:58:29 +00:00
committed by PyTorch MergeBot
parent 8703debf66
commit f8746b878d
9 changed files with 73 additions and 46 deletions

View File

@ -295,8 +295,23 @@ static void registerXpuDeviceProperties(PyObject* module) {
return static_cast<int64_t>(prop.architecture);
};
#endif
// Wrapper class for XPU UUID
struct XPUuuid {
XPUuuid(const std::array<unsigned char, 16>& uuid) : bytes(uuid) {}
const std::array<unsigned char, 16>& bytes{};
};
auto m = py::handle(module).cast<py::module>();
py::class_<XPUuuid>(m, "_XPUuuid")
.def_property_readonly(
"bytes",
[](const XPUuuid& uuid) {
return std::vector<uint8_t>(uuid.bytes.begin(), uuid.bytes.end());
})
.def("__str__", [](const XPUuuid& uuid) {
return uuid_to_string(reinterpret_cast<const char*>(uuid.bytes.data()));
});
#define DEFINE_READONLY_MEMBER(member) \
def_readonly(#member, &DeviceProp::member)
@ -328,6 +343,9 @@ static void registerXpuDeviceProperties(PyObject* module) {
.def_property_readonly("architecture", get_device_architecture)
#endif
.def_property_readonly("type", get_device_type)
.def_property_readonly(
"uuid",
[](const DeviceProp& prop) -> XPUuuid { return XPUuuid(prop.uuid); })
.def(
"__repr__",
[&get_device_type, &gpu_subslice_count](const DeviceProp& prop) {
@ -335,7 +353,9 @@ static void registerXpuDeviceProperties(PyObject* module) {
stream << "_XpuDeviceProperties(name='" << prop.name
<< "', platform_name='" << prop.platform_name << "', type='"
<< get_device_type(prop) << "', device_id=0x" << std::hex
<< std::uppercase << prop.device_id << std::dec
<< std::uppercase << prop.device_id << std::dec << ", uuid="
<< uuid_to_string(
reinterpret_cast<const char*>(prop.uuid.data()))
<< ", driver_version='" << prop.driver_version
<< "', total_memory="
<< prop.global_mem_size / (1024ull * 1024) << "MB"