https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/226447
>From b67c031d4b486cb3c03547216d15a1f96c0df751 Mon Sep 17 00:00:00 2001 From: "Duran, Alex" <[email protected]> Date: Mon, 7 Sep 2026 13:59:31 -0700 Subject: [PATCH 1/2] [offload][omp] Implement printDeviceInfo through liboffload --- offload/libompaccsupport/device.cpp | 183 +++++++++++++++++- .../common/include/PluginInterface.h | 6 - .../common/src/PluginInterface.cpp | 19 -- 3 files changed, 181 insertions(+), 27 deletions(-) diff --git a/offload/libompaccsupport/device.cpp b/offload/libompaccsupport/device.cpp index 04d753a6d49d2..fac4dc7926481 100644 --- a/offload/libompaccsupport/device.cpp +++ b/offload/libompaccsupport/device.cpp @@ -890,9 +890,188 @@ int32_t DeviceTy::launchKernel(void *TgtEntryPtr, void **TgtVarsPtr, return RTL->launch_kernel(RTLDeviceID, TgtEntryPtr, LaunchArgs, AsyncInfo); } -// Run region on device +static llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, + ol_device_type_t Value) { + switch (Value) { + case OL_DEVICE_TYPE_DEFAULT: + return OS << "DEFAULT"; + case OL_DEVICE_TYPE_ALL: + return OS << "ALL"; + case OL_DEVICE_TYPE_GPU: + return OS << "GPU"; + case OL_DEVICE_TYPE_CPU: + return OS << "CPU"; + case OL_DEVICE_TYPE_HOST: + return OS << "HOST"; + default: + return OS << "<< INVALID >>"; + } +} + +static llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, + const ol_dimensions_t &Value) { + return OS << "{x: " << Value.x << ", y: " << Value.y << ", z: " << Value.z + << "}"; +} + +static void printFPCapabilityFlags(llvm::raw_ostream &OS, + ol_device_fp_capability_flags_t Value) { + OS << Value << " {"; + if (Value & OL_DEVICE_FP_CAPABILITY_FLAG_CORRECTLY_ROUNDED_DIVIDE_SQRT) + OS << " CORRECTLY_ROUNDED_DIVIDE_SQRT"; + if (Value & OL_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_NEAREST) + OS << " ROUND_TO_NEAREST"; + if (Value & OL_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_ZERO) + OS << " ROUND_TO_ZERO"; + if (Value & OL_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_INF) + OS << " ROUND_TO_INF"; + if (Value & OL_DEVICE_FP_CAPABILITY_FLAG_INF_NAN) + OS << " INF_NAN"; + if (Value & OL_DEVICE_FP_CAPABILITY_FLAG_DENORM) + OS << " DENORM"; + if (Value & OL_DEVICE_FP_CAPABILITY_FLAG_FMA) + OS << " FMA"; + if (Value & OL_DEVICE_FP_CAPABILITY_FLAG_SOFT_FLOAT) + OS << " SOFT_FLOAT"; + OS << " }"; +} + +// Print a scalar liboffload device info property, if supported. +template <typename T> +static void printDeviceInfoScalar(ol_device_handle_t DeviceHandle, + ol_device_info_t PropName, + llvm::StringRef Label, + llvm::StringRef Units = "") { + T Value{}; + if (olGetDeviceInfo(DeviceHandle, PropName, sizeof(Value), &Value)) + return; + llvm::outs() << " " << Label << ": " << Value; + if (!Units.empty()) + llvm::outs() << " " << Units; + llvm::outs() << "\n"; +} + +// Print a boolean liboffload device info property, if supported. +static void printDeviceInfoBool(ol_device_handle_t DeviceHandle, + ol_device_info_t PropName, + llvm::StringRef Label) { + bool Value = false; + if (olGetDeviceInfo(DeviceHandle, PropName, sizeof(Value), &Value)) + return; + llvm::outs() << " " << Label << ": " << (Value ? "Yes" : "No") << "\n"; +} + +// Print a floating point capability liboffload device info property, if +// supported. +static void printDeviceInfoFPCapability(ol_device_handle_t DeviceHandle, + ol_device_info_t PropName, + llvm::StringRef Label) { + ol_device_fp_capability_flags_t Value{}; + if (olGetDeviceInfo(DeviceHandle, PropName, sizeof(Value), &Value)) + return; + llvm::outs() << " " << Label << ": "; + printFPCapabilityFlags(llvm::outs(), Value); + llvm::outs() << "\n"; +} + +// Print a string liboffload device info property, if supported. +static void printDeviceInfoString(ol_device_handle_t DeviceHandle, + ol_device_info_t PropName, + llvm::StringRef Label) { + size_t Size = 0; + if (olGetDeviceInfoSize(DeviceHandle, PropName, &Size) || Size == 0) + return; + + llvm::SmallVector<char> Value(Size); + if (olGetDeviceInfo(DeviceHandle, PropName, Size, Value.data())) + return; + + llvm::outs() << " " << Label << ": " << Value.data() << "\n"; +} + bool DeviceTy::printDeviceInfo() { - RTL->print_device_info(RTLDeviceID); + llvm::outs() << "Device " << DeviceID << ":\n"; + printDeviceInfoScalar<ol_device_type_t>(DeviceHandle, OL_DEVICE_INFO_TYPE, + "Type"); + printDeviceInfoScalar<ol_platform_handle_t>( + DeviceHandle, OL_DEVICE_INFO_PLATFORM, "Platform"); + printDeviceInfoString(DeviceHandle, OL_DEVICE_INFO_NAME, "Name"); + printDeviceInfoString(DeviceHandle, OL_DEVICE_INFO_PRODUCT_NAME, + "Product Name"); + printDeviceInfoString(DeviceHandle, OL_DEVICE_INFO_UID, "UID"); + printDeviceInfoString(DeviceHandle, OL_DEVICE_INFO_VENDOR, "Vendor"); + printDeviceInfoString(DeviceHandle, OL_DEVICE_INFO_DRIVER_VERSION, + "Driver Version"); + printDeviceInfoScalar<uint32_t>( + DeviceHandle, OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE, "Max Work Group Size"); + printDeviceInfoScalar<ol_dimensions_t>( + DeviceHandle, OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE_PER_DIMENSION, + "Max Work Group Size Per Dimension"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, OL_DEVICE_INFO_MAX_WORK_SIZE, + "Max Work Size"); + printDeviceInfoScalar<ol_dimensions_t>( + DeviceHandle, OL_DEVICE_INFO_MAX_WORK_SIZE_PER_DIMENSION, + "Max Work Size Per Dimension"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, OL_DEVICE_INFO_VENDOR_ID, + "Vendor ID"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_NUM_COMPUTE_UNITS, + "Number of Compute Units"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_MAX_CLOCK_FREQUENCY, + "Max Clock Frequency", "MHz"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_MEMORY_CLOCK_RATE, + "Memory Clock Rate", "MHz"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, OL_DEVICE_INFO_ADDRESS_BITS, + "Address Bits"); + printDeviceInfoScalar<uint64_t>(DeviceHandle, + OL_DEVICE_INFO_MAX_MEM_ALLOC_SIZE, + "Max Memory Allocation Size", "B"); + printDeviceInfoScalar<uint64_t>(DeviceHandle, OL_DEVICE_INFO_GLOBAL_MEM_SIZE, + "Global Memory Size", "B"); + printDeviceInfoScalar<uint64_t>(DeviceHandle, + OL_DEVICE_INFO_WORK_GROUP_LOCAL_MEM_SIZE, + "Work Group Local Memory Size", "B"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, OL_DEVICE_INFO_NUM_LANES, + "Number of Lanes"); + printDeviceInfoBool(DeviceHandle, OL_DEVICE_INFO_SINGLE_FP_SUPPORT, + "Single Precision Floating Point Support"); + printDeviceInfoFPCapability(DeviceHandle, OL_DEVICE_INFO_SINGLE_FP_CONFIG, + "Single Precision Floating Point Capability"); + printDeviceInfoBool(DeviceHandle, OL_DEVICE_INFO_DOUBLE_FP_SUPPORT, + "Double Precision Floating Point Support"); + printDeviceInfoFPCapability(DeviceHandle, OL_DEVICE_INFO_DOUBLE_FP_CONFIG, + "Double Precision Floating Point Capability"); + printDeviceInfoBool(DeviceHandle, OL_DEVICE_INFO_HALF_FP_SUPPORT, + "Half Precision Floating Point Support"); + printDeviceInfoFPCapability(DeviceHandle, OL_DEVICE_INFO_HALF_FP_CONFIG, + "Half Precision Floating Point Capability"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_CHAR, + "Native Vector Width For Char"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_SHORT, + "Native Vector Width For Short"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_INT, + "Native Vector Width For Int"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_LONG, + "Native Vector Width For Long"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_FLOAT, + "Native Vector Width For Float"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_DOUBLE, + "Native Vector Width For Double"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, + OL_DEVICE_INFO_NATIVE_VECTOR_WIDTH_HALF, + "Native Vector Width For Half"); + printDeviceInfoBool(DeviceHandle, OL_DEVICE_INFO_COOPERATIVE_LAUNCH_SUPPORT, + "Cooperative Kernel Launch Support"); + printDeviceInfoScalar<uint32_t>(DeviceHandle, OL_DEVICE_INFO_DRIVER_ID, + "Driver ID"); return true; } diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h index 48564d64ec61e..32c4d348027a3 100644 --- a/offload/plugins-nextgen/common/include/PluginInterface.h +++ b/offload/plugins-nextgen/common/include/PluginInterface.h @@ -1161,9 +1161,6 @@ struct GenericDeviceTy : public DeviceAllocatorTy { Expected<InfoTreeNode> obtainInfo(); virtual Expected<InfoTreeNode> obtainInfoImpl() = 0; - /// Print information about the device. - Error printInfo(); - /// Return true if the device has work that is either queued or currently /// running /// @@ -1681,9 +1678,6 @@ struct GenericPluginTy { /// Obtain information about the given device. InfoTreeNode obtain_device_info(int32_t DeviceId); - /// Prints information about the given devices supported by the plugin. - void print_device_info(int32_t DeviceId); - /// Remove the event from the plugin. void set_info_flag(uint32_t NewInfoLevel); diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp index a682f119a6523..320f7d19278ba 100644 --- a/offload/plugins-nextgen/common/src/PluginInterface.cpp +++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp @@ -935,19 +935,6 @@ Expected<InfoTreeNode> GenericDeviceTy::obtainInfo() { return InfoOrErr; } -Error GenericDeviceTy::printInfo() { - auto InfoOrErr = obtainInfo(); - - // Get the vendor-specific info entries describing the device properties. - if (auto Err = InfoOrErr.takeError()) - return Err; - - // Print all info entries. - InfoOrErr->print(); - - return Plugin::success(); -} - Error GenericDeviceTy::createEvent(void **EventPtrStorage, bool EnableProfiling) { return createEventImpl(EventPtrStorage, EnableProfiling); @@ -1366,12 +1353,6 @@ InfoTreeNode GenericPluginTy::obtain_device_info(int32_t DeviceId) { return std::move(*InfoOrErr); } -void GenericPluginTy::print_device_info(int32_t DeviceId) { - if (auto Err = getDevice(DeviceId).printInfo()) - REPORT() << "Failure to print device " << DeviceId - << " info: " << toString(std::move(Err)); -} - void GenericPluginTy::set_info_flag(uint32_t NewInfoLevel) { std::atomic<uint32_t> &InfoLevel = getInfoLevelInternal(); InfoLevel.store(NewInfoLevel); >From 26ac46d5cd81ba77df7661d4ef983ad6fd12f97c Mon Sep 17 00:00:00 2001 From: "Duran, Alex" <[email protected]> Date: Mon, 7 Sep 2026 14:10:09 -0700 Subject: [PATCH 2/2] [offload][omp] Query device info directly through liboffload Route DeviceTy::getInfo through olGetDeviceInfo instead of the plugin's obtain_device_info, and drop the now-unused GenericPluginTy::obtain_device_info wrapper and its liboffload export. --- offload/include/device.h | 13 ++++--------- .../common/include/PluginInterface.h | 3 --- .../plugins-nextgen/common/src/PluginInterface.cpp | 10 ---------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/offload/include/device.h b/offload/include/device.h index 9e10d2a2f76fc..cd76a1605d9d3 100644 --- a/offload/include/device.h +++ b/offload/include/device.h @@ -212,16 +212,11 @@ struct DeviceTy { /// Get information from the device. template <typename T> T getInfo(DeviceInfo Info) const { - InfoTreeNode DevInfo = RTL->obtain_device_info(RTLDeviceID); - - auto EntryOpt = DevInfo.get(Info); - if (!EntryOpt) - return 0; - - auto Entry = *EntryOpt; - if (!std::holds_alternative<T>(Entry->Value)) + T Value{}; + if (olGetDeviceInfo(DeviceHandle, static_cast<ol_device_info_t>(Info), + sizeof(Value), &Value)) return T{}; - return std::get<T>(Entry->Value); + return Value; } /// Record the launch-geometry properties for the kernel at \p KernelPtr, diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h index 32c4d348027a3..4d8fb68ed254a 100644 --- a/offload/plugins-nextgen/common/include/PluginInterface.h +++ b/offload/plugins-nextgen/common/include/PluginInterface.h @@ -1675,9 +1675,6 @@ struct GenericPluginTy { KernelLaunchArgsTy &LaunchArgs, __tgt_async_info *AsyncInfoPtr); - /// Obtain information about the given device. - InfoTreeNode obtain_device_info(int32_t DeviceId); - /// Remove the event from the plugin. void set_info_flag(uint32_t NewInfoLevel); diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp index 320f7d19278ba..0d1bd4a436bd4 100644 --- a/offload/plugins-nextgen/common/src/PluginInterface.cpp +++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp @@ -1343,16 +1343,6 @@ int32_t GenericPluginTy::launch_kernel(int32_t DeviceId, void *TgtEntryPtr, return OFFLOAD_SUCCESS; } -InfoTreeNode GenericPluginTy::obtain_device_info(int32_t DeviceId) { - auto InfoOrErr = getDevice(DeviceId).obtainInfo(); - if (auto Err = InfoOrErr.takeError()) { - REPORT() << "Failure to obtain device " << DeviceId - << " info: " << toString(std::move(Err)); - return InfoTreeNode{}; - } - return std::move(*InfoOrErr); -} - void GenericPluginTy::set_info_flag(uint32_t NewInfoLevel) { std::atomic<uint32_t> &InfoLevel = getInfoLevelInternal(); InfoLevel.store(NewInfoLevel); _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
