Skip to content
49 changes: 38 additions & 11 deletions src/runtime_src/core/tools/common/XBUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,40 @@ XBUtilities::Timer::format_time(std::chrono::duration<double> duration)
return formatted_time;
}

static std::string
get_device_id(const std::shared_ptr<xrt_core::device>& device,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse the same function as used by HIP? See hip_device_get_uuid(hipDevice_t device) defined in hip_device.cpp. Can that code be moved to some common place from where both HIP and xrt-smi can call it?

Copy link
Copy Markdown
Collaborator Author

@sandilya-xilinx sandilya-xilinx Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sonals, Implemented Centralized BDF-to-UUID logic in pcie_bdf::to_uuid() [src/runtime_src/core/common/query_requests.h]. Please review

xrt_core::query::device_class::type device_class)
{
// Ryzen/NPU: no ROM or xclbin UUID — derive from PCIe BDF.
// Byte layout matches hip_device_get_uuid().
if (device_class == xrt_core::query::device_class::type::ryzen) {
auto bdf = xrt_core::device_query<xrt_core::query::pcie_bdf>(device);
xuid_t uid = {};
auto* ptr = reinterpret_cast<uint8_t*>(&uid);
std::apply([&ptr](const auto&... fields) {
((std::memcpy(ptr, &fields, sizeof(fields)), ptr += sizeof(fields)), ...);
}, bdf);
return xrt::uuid(uid).to_string();
}

// Alveo 2RP: UUID from loaded xclbin logic region
try {
auto logic_uuids = xrt_core::device_query<xrt_core::query::logic_uuids>(device);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the UUID logic capture from XCLBIN ?
IMO, let's restrict to ryzen devices cases only.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alveo code is existing code and now with newer code there is exclusive if/else for Ryzen vs Alveo

if (!logic_uuids.empty())
return xrt_core::query::interface_uuids::to_uuid_upper_string(logic_uuids[0]);
}
catch(...) {}

// Alveo 1RP: timestamp-based ROM id
try {
return xrt_core::query::rom_time_since_epoch::to_string(
xrt_core::device_query<xrt_core::query::rom_time_since_epoch>(device));
}
catch(...) {}

return "";
}

boost::property_tree::ptree
XBUtilities::get_available_devices(bool inUserDomain)
{
Expand Down Expand Up @@ -120,17 +154,10 @@ XBUtilities::get_available_devices(bool inUserDomain)
break;
}

try { //1RP
pt_dev.put("id", xrt_core::query::rom_time_since_epoch::to_string(xrt_core::device_query<xrt_core::query::rom_time_since_epoch>(device)));
}
catch(...) {
// The id wasn't added
}

try { //2RP
auto logic_uuids = xrt_core::device_query<xrt_core::query::logic_uuids>(device);
if (!logic_uuids.empty())
pt_dev.put("id", xrt_core::query::interface_uuids::to_uuid_upper_string(logic_uuids[0]));
try {
auto id = get_device_id(device, device_class);
if (!id.empty())
pt_dev.put("id", id);
}
catch(...) {
// The id wasn't added
Expand Down
Loading