[llvm-branch-commits] [llvm] [offload][omp] Use olGetDeviceInfo to get device info (PR #226447)

Alex Duran via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Sep 29 08:52:33 PDT 2026


https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/226447

>From 841d6e9fc2ba113a399766e77a31d58dd97855b9 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 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 5a2a73a11b045..1c8c82c4d7391 100644
--- a/offload/libompaccsupport/device.cpp
+++ b/offload/libompaccsupport/device.cpp
@@ -486,9 +486,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 fff91225ee8ff..19a6c2dcc7723 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -1262,9 +1262,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
   ///
@@ -1778,9 +1775,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 48dc15cd0a31d..80ef304b386c1 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -1240,19 +1240,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);
@@ -1671,12 +1658,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 40f29148f489654f382859c2b5febb8351e2e0bd Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
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 fc3ecf316373f..98a171cb3a132 100644
--- a/offload/include/device.h
+++ b/offload/include/device.h
@@ -171,16 +171,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;
   }
 
 private:
diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h
index 19a6c2dcc7723..30ca13bdd01a3 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -1772,9 +1772,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 80ef304b386c1..355045de7541b 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -1648,16 +1648,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);



More information about the llvm-branch-commits mailing list