[llvm-branch-commits] [llvm] [offload][omp] Implement printDeviceInfo through liboffload (PR #221830)

Alex Duran via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 7 14:00:05 PDT 2026


https://github.com/adurang created https://github.com/llvm/llvm-project/pull/221830

<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>

>From 35385c7f42c86e17a24a98976fb6d211ea6de48b Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Mon, 7 Sep 2026 13:59:31 -0700
Subject: [PATCH] [offload][omp] Implement printDeviceInfo through liboffload

---
 offload/liboffload/exports                    |   1 -
 offload/libompaccsupport/device.cpp           | 183 +++++++++++++++++-
 .../common/include/PluginInterface.h          |   6 -
 .../common/src/PluginInterface.cpp            |  19 --
 4 files changed, 181 insertions(+), 28 deletions(-)

diff --git a/offload/liboffload/exports b/offload/liboffload/exports
index cb0ec9a8380a2..ba049b7e82512 100644
--- a/offload/liboffload/exports
+++ b/offload/liboffload/exports
@@ -28,7 +28,6 @@ global:
     "llvm::omp::target::plugin::GenericPluginTy::load_binary(int, __tgt_device_image*, __tgt_device_binary*)";
     "llvm::omp::target::plugin::GenericPluginTy::number_of_devices()";
     "llvm::omp::target::plugin::GenericPluginTy::obtain_device_info(int)";
-    "llvm::omp::target::plugin::GenericPluginTy::print_device_info(int)";
     "llvm::omp::target::plugin::GenericPluginTy::release_interop(int, omp_interop_val_t*)";
     "llvm::omp::target::plugin::GenericPluginTy::set_device_identifier(int, int)";
     "llvm::omp::target::plugin::GenericPluginTy::sync_barrier(omp_interop_val_t*)";
diff --git a/offload/libompaccsupport/device.cpp b/offload/libompaccsupport/device.cpp
index 5d15469705b70..a379d183a04ae 100644
--- a/offload/libompaccsupport/device.cpp
+++ b/offload/libompaccsupport/device.cpp
@@ -470,9 +470,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 0d282d2d73038..fe6c8ede1726e 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -1200,9 +1200,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
   ///
@@ -1746,9 +1743,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 053e15df5cb17..e3bddaefc259d 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -1222,19 +1222,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);
@@ -1651,12 +1638,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);



More information about the llvm-branch-commits mailing list