[Openmp-commits] [PATCH] D146081: [OpenMP][libomptarget] Init device when printing device info

Kevin Sala via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Mar 15 02:58:06 PDT 2023


kevinsala updated this revision to Diff 505415.
kevinsala added a comment.

Explicitly initializing devices from `llvm-omp-device-info` tool.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146081/new/

https://reviews.llvm.org/D146081

Files:
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/interface.cpp
  openmp/libomptarget/tools/deviceinfo/llvm-omp-device-info.cpp


Index: openmp/libomptarget/tools/deviceinfo/llvm-omp-device-info.cpp
===================================================================
--- openmp/libomptarget/tools/deviceinfo/llvm-omp-device-info.cpp
+++ openmp/libomptarget/tools/deviceinfo/llvm-omp-device-info.cpp
@@ -20,6 +20,8 @@
   __tgt_init_all_rtls();
 
   for (int Dev = 0; Dev < omp_get_num_devices(); Dev++) {
+    __tgt_init_device(Dev);
+
     printf("Device (%d):\n", Dev);
     if (!__tgt_print_device_info(Dev))
       printf("    print_device_info not implemented\n");
Index: openmp/libomptarget/src/interface.cpp
===================================================================
--- openmp/libomptarget/src/interface.cpp
+++ openmp/libomptarget/src/interface.cpp
@@ -53,6 +53,14 @@
 EXTERN void __tgt_init_all_rtls() { PM->RTLs.initAllRTLs(); }
 
 ////////////////////////////////////////////////////////////////////////////////
+/// Initialize device if not initialized yet
+EXTERN void __tgt_init_device(int64_t DeviceId) {
+  if (!deviceIsReady(DeviceId)) {
+    DP("Could not initialize device %" PRId64 "\n", DeviceId);
+  }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 /// unloads a target shared library
 EXTERN void __tgt_unregister_lib(__tgt_bin_desc *Desc) {
   TIMESCOPE();
@@ -384,6 +392,12 @@
 }
 
 EXTERN int __tgt_print_device_info(int64_t DeviceId) {
+  // Make sure the device is ready.
+  if (!deviceIsReady(DeviceId)) {
+    DP("Device %" PRId64 " is not ready\n", DeviceId);
+    return OMP_TGT_FAIL;
+  }
+
   return PM->Devices[DeviceId]->printDeviceInfo(
       PM->Devices[DeviceId]->RTLDeviceID);
 }
Index: openmp/libomptarget/src/exports
===================================================================
--- openmp/libomptarget/src/exports
+++ openmp/libomptarget/src/exports
@@ -4,6 +4,7 @@
     __tgt_register_lib;
     __tgt_unregister_lib;
     __tgt_init_all_rtls;
+    __tgt_init_device;
     __tgt_target_data_begin;
     __tgt_target_data_end;
     __tgt_target_data_update;
Index: openmp/libomptarget/include/omptarget.h
===================================================================
--- openmp/libomptarget/include/omptarget.h
+++ openmp/libomptarget/include/omptarget.h
@@ -337,6 +337,9 @@
 /// Initialize all RTLs at once
 void __tgt_init_all_rtls();
 
+/// Initialize device if not initialized yet
+void __tgt_init_device(int64_t DeviceId);
+
 /// removes a target shared library from the target execution image
 void __tgt_unregister_lib(__tgt_bin_desc *Desc);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146081.505415.patch
Type: text/x-patch
Size: 2526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230315/e08da14a/attachment.bin>


More information about the Openmp-commits mailing list