[llvm] [Offload][omp] Use olGetDeviceInfo to get device info (PR #229693)

Alex Duran via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 05:47:22 PDT 2026


================
@@ -860,9 +860,226 @@ int32_t DeviceTy::launchKernel(void *TgtEntryPtr, void **TgtVarsPtr,
   return RTL->launch_kernel(RTLDeviceID, TgtEntryPtr, LaunchArgs, AsyncInfo);
 }
 
-// Run region on device
+namespace {
+enum class PrintKind {
+  NORMAL,
+  FP_FLAGS,
+};
+
+template <typename T, PrintKind PK = PrintKind::NORMAL>
+void doWrite(llvm::raw_ostream &S, T &&Val) {
+  S << Val;
+}
+
+template <> void doWrite<bool>(llvm::raw_ostream &S, bool &&Val) {
+  S << (Val ? "Yes" : "No");
+}
+template <>
+void doWrite<ol_platform_backend_t>(llvm::raw_ostream &S,
+                                    ol_platform_backend_t &&Val) {
+  switch (Val) {
+  case OL_PLATFORM_BACKEND_UNKNOWN:
+    S << "UNKNOWN";
+    break;
+  case OL_PLATFORM_BACKEND_CUDA:
+    S << "CUDA";
+    break;
+  case OL_PLATFORM_BACKEND_AMDGPU:
+    S << "AMDGPU";
+    break;
+  case OL_PLATFORM_BACKEND_LEVEL_ZERO:
+    S << "LEVEL_ZERO";
+    break;
+  case OL_PLATFORM_BACKEND_HOST:
+    S << "HOST";
+    break;
+  default:
+    S << "<< INVALID >>";
+    break;
+  }
+}
+template <>
+void doWrite<ol_device_type_t>(llvm::raw_ostream &S, ol_device_type_t &&Val) {
+  switch (Val) {
+  case OL_DEVICE_TYPE_GPU:
+    S << "GPU";
+    break;
+  case OL_DEVICE_TYPE_CPU:
+    S << "CPU";
+    break;
+  case OL_DEVICE_TYPE_HOST:
+    S << "HOST";
+    break;
+  default:
+    S << "<< INVALID >>";
+    break;
+  }
+}
+template <>
+void doWrite<ol_dimensions_t>(llvm::raw_ostream &S, ol_dimensions_t &&Val) {
+  S << "{x: " << Val.x << ", y: " << Val.y << ", z: " << Val.z << "}";
+}
+template <>
+void doWrite<ol_device_fp_capability_flags_t, PrintKind::FP_FLAGS>(
+    llvm::raw_ostream &S, ol_device_fp_capability_flags_t &&Val) {
+  S << Val << " {";
+  if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_CORRECTLY_ROUNDED_DIVIDE_SQRT)
+    S << " CORRECTLY_ROUNDED_DIVIDE_SQRT";
+  if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_NEAREST)
+    S << " ROUND_TO_NEAREST";
+  if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_ZERO)
+    S << " ROUND_TO_ZERO";
+  if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_ROUND_TO_INF)
+    S << " ROUND_TO_INF";
+  if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_INF_NAN)
+    S << " INF_NAN";
+  if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_DENORM)
+    S << " DENORM";
+  if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_FMA)
+    S << " FMA";
+  if (Val & OL_DEVICE_FP_CAPABILITY_FLAG_SOFT_FLOAT)
+    S << " SOFT_FLOAT";
+  S << " }";
+}
+
+// Print a liboffload platform info property. Unsupported properties are
+// silently skipped.
+template <typename T>
+void printPlatformValue(llvm::raw_ostream &S, ol_platform_handle_t Plat,
+                        ol_platform_info_t Info, const char *Desc) {
+  if constexpr (std::is_pointer_v<T>) {
+    llvm::SmallVector<uint8_t> Val;
+    size_t Size;
+    if (olGetPlatformInfoSize(Plat, Info, &Size))
+      return;
+    Val.resize(Size);
+    if (olGetPlatformInfo(Plat, Info, Size, Val.data()))
+      return;
+    S << "    " << Desc << ": ";
+    doWrite(S, reinterpret_cast<T>(Val.data()));
+  } else {
+    T Val;
+    if (olGetPlatformInfo(Plat, Info, sizeof(Val), &Val))
+      return;
+    S << "    " << Desc << ": ";
+    doWrite(S, std::move(Val));
+  }
+  S << "\n";
+}
+
+// Print a liboffload device info property. Unsupported properties are
+// silently skipped.
+template <typename T, PrintKind PK = PrintKind::NORMAL>
+void printDeviceValue(llvm::raw_ostream &S, ol_device_handle_t Dev,
+                      ol_device_info_t Info, const char *Desc,
+                      const char *Units = nullptr) {
+  if constexpr (std::is_pointer_v<T>) {
+    llvm::SmallVector<uint8_t> Val;
+    size_t Size;
+    if (olGetDeviceInfoSize(Dev, Info, &Size))
+      return;
+    Val.resize(Size);
+    if (olGetDeviceInfo(Dev, Info, Size, Val.data()))
+      return;
+    S << "    " << Desc << ": ";
+    doWrite<T, PK>(S, reinterpret_cast<T>(Val.data()));
+  } else {
+    T Val;
+    if (olGetDeviceInfo(Dev, Info, sizeof(Val), &Val))
+      return;
+    S << "    " << Desc << ": ";
+    doWrite<T, PK>(S, std::move(Val));
+  }
+  if (Units)
+    S << " " << Units;
+  S << "\n";
+}
+} // namespace
+
 bool DeviceTy::printDeviceInfo() {
----------------
adurang wrote:

Ok with me too. Now by deprecation do you mean:

a) Keep the current code and put a "will be deprecated. Use xxxx" message.
b) Remove the current code and put a "was deprecated. Use xxxx" message

?

https://github.com/llvm/llvm-project/pull/229693


More information about the llvm-commits mailing list