From dc94f2cbadfd192fe3d43bd00fd5a1d0ead5ab8d Mon Sep 17 00:00:00 2001 From: Robert Imschweiler Date: Tue, 4 Nov 2025 20:15:47 +0100 Subject: [Offload] Add device UID (#164391) Introduced in OpenMP 6.0, the device UID shall be a unique identifier of a device on a given system. (Not necessarily a UUID.) Since it is not guaranteed that the (U)UIDs defined by the device vendor libraries, such as HSA, do not overlap with those of other vendors, the device UIDs in offload are always combined with the offload plugin name. In case the vendor library does not specify any device UID for a given device, we fall back to the offload-internal device ID. The device UID can be retrieved using the `llvm-offload-device-info` tool. --- .../plugins-nextgen/common/src/PluginInterface.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'offload/plugins-nextgen/common/src/PluginInterface.cpp') diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp index 36d643b..d7e5a21 100644 --- a/offload/plugins-nextgen/common/src/PluginInterface.cpp +++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp @@ -715,6 +715,10 @@ GenericDeviceTy::GenericDeviceTy(GenericPluginTy &Plugin, int32_t DeviceId, DeviceId(DeviceId), GridValues(OMPGridValues), PeerAccesses(NumDevices, PeerAccessState::PENDING), PeerAccessesLock(), PinnedAllocs(*this), RPCServer(nullptr) { + // Conservative fall-back to the plugin's device uid for the case that no real + // vendor (u)uid will become available later. + setDeviceUidFromVendorUid(std::to_string(static_cast(DeviceId))); + #ifdef OMPT_SUPPORT OmptInitialized.store(false); // Bind the callbacks to this device's member functions @@ -1524,15 +1528,22 @@ Error GenericDeviceTy::enqueueHostCall(void (*Callback)(void *), void *UserData, return Err; } +Expected GenericDeviceTy::obtainInfo() { + auto InfoOrErr = obtainInfoImpl(); + if (InfoOrErr) + InfoOrErr->add("UID", getDeviceUid(), "", DeviceInfo::UID); + return InfoOrErr; +} + Error GenericDeviceTy::printInfo() { - auto Info = obtainInfoImpl(); + auto InfoOrErr = obtainInfo(); // Get the vendor-specific info entries describing the device properties. - if (auto Err = Info.takeError()) + if (auto Err = InfoOrErr.takeError()) return Err; // Print all info entries. - Info->print(); + InfoOrErr->print(); return Plugin::success(); } @@ -1603,6 +1614,10 @@ Expected GenericDeviceTy::isAccessiblePtr(const void *Ptr, size_t Size) { return isAccessiblePtrImpl(Ptr, Size); } +void GenericDeviceTy::setDeviceUidFromVendorUid(StringRef VendorUid) { + DeviceUid = std::string(Plugin.getName()) + "-" + std::string(VendorUid); +} + Error GenericPluginTy::init() { if (Initialized) return Plugin::success(); -- cgit v1.1