Skip to content

Conversation

@ro-i
Copy link
Contributor

@ro-i ro-i commented Oct 21, 2025

Use the implementation in libomptarget. If libomptarget is not available, always return the UID / device number of the host / the initial device.

@llvmbot llvmbot added openmp:libomp OpenMP host runtime openmp:libomptarget OpenMP offload runtime offload labels Oct 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2025

@llvm/pr-subscribers-offload

Author: Robert Imschweiler (ro-i)

Changes

Use the implementation in libomptarget. If libomptarget is not available, always return the UID / device number of the host / the initial device.


Full diff: https://github.com/llvm/llvm-project/pull/164392.diff

15 Files Affected:

  • (modified) offload/include/OpenMP/omp.h (+7)
  • (modified) offload/include/omptarget.h (+2)
  • (modified) offload/libomptarget/OpenMP/API.cpp (+55)
  • (modified) offload/libomptarget/exports (+2)
  • (added) offload/test/api/omp_device_uid.c (+88)
  • (modified) openmp/device/include/DeviceTypes.h (+2)
  • (modified) openmp/device/include/Interface.h (+4)
  • (modified) openmp/device/src/State.cpp (+6)
  • (modified) openmp/runtime/src/dllexports (+2)
  • (modified) openmp/runtime/src/include/omp.h.var (+5)
  • (modified) openmp/runtime/src/include/omp_lib.F90.var (+14)
  • (modified) openmp/runtime/src/include/omp_lib.h.var (+19)
  • (modified) openmp/runtime/src/kmp_ftn_entry.h (+14-2)
  • (modified) openmp/runtime/src/kmp_ftn_os.h (+8)
  • (added) openmp/runtime/test/api/omp_device_uid.c (+89)
diff --git a/offload/include/OpenMP/omp.h b/offload/include/OpenMP/omp.h
index 49d9f1fa75c20..a42724f87cf3a 100644
--- a/offload/include/OpenMP/omp.h
+++ b/offload/include/OpenMP/omp.h
@@ -30,6 +30,13 @@
 
 extern "C" {
 
+/// Definitions
+///{
+
+#define omp_invalid_device -2
+
+///}
+
 /// Type declarations
 ///{
 
diff --git a/offload/include/omptarget.h b/offload/include/omptarget.h
index 794b79e07674e..332b0d9f5cf27 100644
--- a/offload/include/omptarget.h
+++ b/offload/include/omptarget.h
@@ -274,6 +274,8 @@ extern "C" {
 void ompx_dump_mapping_tables(void);
 int omp_get_num_devices(void);
 int omp_get_device_num(void);
+int omp_get_device_from_uid(const char *DeviceUid);
+const char *omp_get_uid_from_device(int DeviceNum);
 int omp_get_initial_device(void);
 void *omp_target_alloc(size_t Size, int DeviceNum);
 void omp_target_free(void *DevicePtr, int DeviceNum);
diff --git a/offload/libomptarget/OpenMP/API.cpp b/offload/libomptarget/OpenMP/API.cpp
index b0f0573833713..cc4b607ccee6d 100644
--- a/offload/libomptarget/OpenMP/API.cpp
+++ b/offload/libomptarget/OpenMP/API.cpp
@@ -40,6 +40,8 @@ EXTERN void ompx_dump_mapping_tables() {
 using namespace llvm::omp::target::ompt;
 #endif
 
+using GenericDeviceTy = llvm::omp::target::plugin::GenericDeviceTy;
+
 void *targetAllocExplicit(size_t Size, int DeviceNum, int Kind,
                           const char *Name);
 void targetFreeExplicit(void *DevicePtr, int DeviceNum, int Kind,
@@ -91,6 +93,59 @@ EXTERN int omp_get_device_num(void) {
   return HostDevice;
 }
 
+EXTERN int omp_get_device_from_uid(const char *DeviceUid) {
+  TIMESCOPE();
+  OMPT_IF_BUILT(ReturnAddressSetterRAII RA(__builtin_return_address(0)));
+
+  if (!DeviceUid) {
+    DP("Call to omp_get_device_from_uid returning omp_invalid_device\n");
+    return omp_invalid_device;
+  }
+  if (strcmp(DeviceUid, GenericDeviceTy::getHostDeviceUid()) == 0) {
+    DP("Call to omp_get_device_from_uid returning host device number %d\n",
+       omp_get_initial_device());
+    return omp_get_initial_device();
+  }
+
+  int DeviceNum = omp_invalid_device;
+
+  auto ExclusiveDevicesAccessor = PM->getExclusiveDevicesAccessor();
+  for (const DeviceTy &Device : PM->devices(ExclusiveDevicesAccessor)) {
+    const char *Uid = Device.RTL->getDevice(Device.RTLDeviceID).getDeviceUid();
+    if (Uid && strcmp(DeviceUid, Uid) == 0) {
+      DeviceNum = Device.DeviceID;
+      break;
+    }
+  }
+
+  DP("Call to omp_get_device_from_uid returning %d\n", DeviceNum);
+  return DeviceNum;
+}
+
+EXTERN const char *omp_get_uid_from_device(int DeviceNum) {
+  TIMESCOPE();
+  OMPT_IF_BUILT(ReturnAddressSetterRAII RA(__builtin_return_address(0)));
+
+  if (DeviceNum == omp_invalid_device) {
+    DP("Call to omp_get_uid_from_device returning nullptr\n");
+    return nullptr;
+  }
+  if (DeviceNum == omp_get_initial_device()) {
+    DP("Call to omp_get_uid_from_device returning host device UID\n");
+    return GenericDeviceTy::getHostDeviceUid();
+  }
+
+  llvm::Expected<DeviceTy &> Device = PM->getDevice(DeviceNum);
+  if (!Device) {
+    FATAL_MESSAGE(DeviceNum, "%s", toString(Device.takeError()).c_str());
+    return nullptr;
+  }
+
+  const char *Uid = Device->RTL->getDevice(Device->RTLDeviceID).getDeviceUid();
+  DP("Call to omp_get_uid_from_device returning %s\n", Uid);
+  return Uid;
+}
+
 EXTERN int omp_get_initial_device(void) {
   TIMESCOPE();
   OMPT_IF_BUILT(ReturnAddressSetterRAII RA(__builtin_return_address(0)));
diff --git a/offload/libomptarget/exports b/offload/libomptarget/exports
index 1374bfea81511..f8fffb085a5dc 100644
--- a/offload/libomptarget/exports
+++ b/offload/libomptarget/exports
@@ -40,6 +40,8 @@ VERS1.0 {
     omp_get_mapped_ptr;
     omp_get_num_devices;
     omp_get_device_num;
+    omp_get_device_from_uid;
+    omp_get_uid_from_device;
     omp_get_initial_device;
     omp_target_alloc;
     omp_target_free;
diff --git a/offload/test/api/omp_device_uid.c b/offload/test/api/omp_device_uid.c
new file mode 100644
index 0000000000000..e07da8e56da98
--- /dev/null
+++ b/offload/test/api/omp_device_uid.c
@@ -0,0 +1,88 @@
+// RUN: %libomptarget-compile-run-and-check-generic
+
+#include <omp.h>
+#include <stdio.h>
+#include <string.h>
+
+// Note that the device UIDs for the "fake" host devices used by libomptarget
+// will always be the same as the UID for the initial device (since it *is* the
+// same device).  The other way round, the device number returned for this UID
+// will always be the initial device.
+
+int is_host_device_uid(const char *device_uid) {
+  return strcmp(device_uid,
+                omp_get_uid_from_device(omp_get_initial_device())) == 0;
+}
+
+int test_omp_device_uid(int device_num) {
+  const char *device_uid = omp_get_uid_from_device(device_num);
+  if (device_uid == NULL) {
+    printf("FAIL for device %d: omp_get_uid_from_device returned NULL\n",
+           device_num);
+    return 0;
+  }
+
+  int device_num_from_uid = omp_get_device_from_uid(device_uid);
+  if (device_num_from_uid != (is_host_device_uid(device_uid)
+                                  ? omp_get_initial_device()
+                                  : device_num)) {
+    printf(
+        "FAIL for device %d: omp_get_device_from_uid returned %d (UID: %s)\n",
+        device_num, device_num_from_uid, device_uid);
+    return 0;
+  }
+
+  if (device_num == omp_get_initial_device())
+    return 1;
+
+  int success = 1;
+
+// Note that the following code may be executed on the host if the host is the
+// device
+#pragma omp target map(tofrom : success) device(device_num)
+  {
+    int device_num = omp_get_device_num();
+
+    // omp_get_uid_from_device() in the device runtime is a dummy function
+    // returning NULL
+    const char *device_uid_target = omp_get_uid_from_device(device_num);
+
+    // omp_get_device_from_uid() in the device runtime is a dummy function
+    // returning omp_invalid_device.
+    device_num_from_uid = omp_get_device_from_uid(device_uid_target);
+
+    // Depending on whether we're executing on the device or the host, we either
+    // got NULL as the device UID or the correct device UID.  Consequently,
+    // omp_get_device_from_uid() either returned omp_invalid_device or the
+    // correct device number (aka omp_get_initial_device()).
+    if (device_uid_target ? device_num_from_uid != omp_get_initial_device()
+                          : device_num_from_uid != omp_invalid_device) {
+      printf("FAIL for device %d (target): omp_get_device_from_uid returned %d "
+             "(UID: %s)\n",
+             device_num, device_num_from_uid, device_uid_target);
+      success = 0;
+    }
+  }
+
+  return success;
+}
+
+int main() {
+  int num_devices = omp_get_num_devices();
+  int num_failed = 0;
+  // (also test initial device aka num_devices)
+  for (int i = 0; i < num_devices + 1; i++) {
+    if (!test_omp_device_uid(i)) {
+      printf("FAIL for device %d\n", i);
+      num_failed++;
+    }
+  }
+  if (num_failed) {
+    printf("FAIL\n");
+    return 1;
+  }
+  printf("PASS\n");
+  return 0;
+}
+
+// CHECK: PASS
diff --git a/openmp/device/include/DeviceTypes.h b/openmp/device/include/DeviceTypes.h
index 2e5d92380f040..b7f9c5fe7b7cd 100644
--- a/openmp/device/include/DeviceTypes.h
+++ b/openmp/device/include/DeviceTypes.h
@@ -21,6 +21,8 @@ template <typename T> using Constant = __gpu_constant T;
 template <typename T> using Local = __gpu_local T;
 template <typename T> using Global = __gpu_local T;
 
+#define omp_invalid_device -2
+
 enum omp_proc_bind_t {
   omp_proc_bind_false = 0,
   omp_proc_bind_true = 1,
diff --git a/openmp/device/include/Interface.h b/openmp/device/include/Interface.h
index c4bfaaa2404b4..71c3b1fc06d40 100644
--- a/openmp/device/include/Interface.h
+++ b/openmp/device/include/Interface.h
@@ -130,6 +130,10 @@ int omp_get_num_devices(void);
 
 int omp_get_device_num(void);
 
+int omp_get_device_from_uid(const char *DeviceUid);
+
+const char *omp_get_uid_from_device(int DeviceNum);
+
 int omp_get_num_teams(void);
 
 int omp_get_team_num();
diff --git a/openmp/device/src/State.cpp b/openmp/device/src/State.cpp
index 475395102f47b..8ccb9d2ca24ff 100644
--- a/openmp/device/src/State.cpp
+++ b/openmp/device/src/State.cpp
@@ -423,6 +423,12 @@ int omp_get_num_devices(void) { return config::getNumDevices(); }
 
 int omp_get_device_num(void) { return config::getDeviceNum(); }
 
+int omp_get_device_from_uid(const char *DeviceUid) {
+  return omp_invalid_device;
+}
+
+const char *omp_get_uid_from_device(int DeviceNum) { return nullptr; }
+
 int omp_get_num_teams(void) { return mapping::getNumberOfBlocksInKernel(); }
 
 int omp_get_team_num() { return mapping::getBlockIdInKernel(); }
diff --git a/openmp/runtime/src/dllexports b/openmp/runtime/src/dllexports
index 3983dae80c9f5..00becd1a657fd 100644
--- a/openmp/runtime/src/dllexports
+++ b/openmp/runtime/src/dllexports
@@ -544,6 +544,8 @@ kmp_set_disp_num_buffers                    890
     omp_get_devices_all_allocator           819
     omp_get_memspace_num_resources          820
     omp_get_submemspace                     821
+    omp_get_device_from_uid                 822
+    omp_get_uid_from_device                 823
     %ifndef stub
         __kmpc_set_default_allocator
         __kmpc_get_default_allocator
diff --git a/openmp/runtime/src/include/omp.h.var b/openmp/runtime/src/include/omp.h.var
index 74f385feb3ea5..e98df731ad888 100644
--- a/openmp/runtime/src/include/omp.h.var
+++ b/openmp/runtime/src/include/omp.h.var
@@ -536,6 +536,11 @@
 
     /* OpenMP 5.2 */
     extern int __KAI_KMPC_CONVENTION omp_in_explicit_task(void);
+    #define omp_invalid_device -2
+
+    /* OpenMP 6.0 */
+    extern int   __KAI_KMPC_CONVENTION  omp_get_device_from_uid(const char *DeviceUid);
+    extern const char *   __KAI_KMPC_CONVENTION  omp_get_uid_from_device(int DeviceNum);
 
     /* LLVM Extensions */
     extern void *llvm_omp_target_dynamic_shared_alloc(void);
diff --git a/openmp/runtime/src/include/omp_lib.F90.var b/openmp/runtime/src/include/omp_lib.F90.var
index 90d7e49ebf549..159b42ab5b5cc 100644
--- a/openmp/runtime/src/include/omp_lib.F90.var
+++ b/openmp/runtime/src/include/omp_lib.F90.var
@@ -215,6 +215,8 @@
 
         integer (kind=omp_interop_kind), parameter, public :: omp_interop_none = 0
 
+        integer (kind=omp_integer_kind), parameter, public :: omp_invalid_device = -2
+
         interface
 
 !         ***
@@ -417,6 +419,18 @@
             integer (kind=omp_integer_kind) omp_get_device_num
           end function omp_get_device_num
 
+          function omp_get_uid_from_device(device_num) bind(c)
+            use omp_lib_kinds
+            integer (kind=omp_integer_kind), value :: device_num
+            character (len=*) omp_get_uid_from_device
+          end function omp_get_uid_from_device
+
+          function omp_get_device_from_uid(device_uid) bind(c)
+            use omp_lib_kinds
+            character (len=*), value :: device_uid
+            integer (kind=omp_integer_kind) omp_get_device_from_uid
+          end function omp_get_device_from_uid
+
           function omp_pause_resource(kind, device_num) bind(c)
             use omp_lib_kinds
             integer (kind=omp_pause_resource_kind), value :: kind
diff --git a/openmp/runtime/src/include/omp_lib.h.var b/openmp/runtime/src/include/omp_lib.h.var
index a50bb018c7cc3..468eb03e99ef1 100644
--- a/openmp/runtime/src/include/omp_lib.h.var
+++ b/openmp/runtime/src/include/omp_lib.h.var
@@ -291,6 +291,9 @@
       integer(kind=omp_interop_kind)omp_interop_none
       parameter(omp_interop_none=0)
 
+      integer(kind=omp_integer_kind)omp_invalid_device
+      parameter(omp_invalid_device=-2)
+
       interface
 
 !       ***
@@ -486,6 +489,18 @@
           integer (kind=omp_integer_kind) omp_get_device_num
         end function omp_get_device_num
 
+        function omp_get_uid_from_device(device_num) bind(c)
+          import
+          integer (kind=omp_integer_kind), value :: device_num
+          character (len=*) omp_get_uid_from_device
+        end function omp_get_uid_from_device
+
+        function omp_get_device_from_uid(device_uid) bind(c)
+          import
+          character (len=*), value :: device_uid
+          integer (kind=omp_integer_kind) omp_get_device_from_uid
+        end function omp_get_device_from_uid
+
         function omp_pause_resource(kind, device_num) bind(c)
           import
           integer (kind=omp_pause_resource_kind), value :: kind
@@ -1159,6 +1174,8 @@
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_initial_device
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_num_devices
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_device_num
+!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_uid_from_device
+!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_device_from_uid
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_pause_resource
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_pause_resource_all
 !DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_supported_active_levels
@@ -1242,6 +1259,8 @@
 !$omp declare target(omp_get_initial_device )
 !$omp declare target(omp_get_num_devices )
 !$omp declare target(omp_get_device_num )
+!$omp declare target(omp_get_uid_from_device )
+!$omp declare target(omp_get_device_from_uid )
 !$omp declare target(omp_pause_resource )
 !$omp declare target(omp_pause_resource_all )
 !$omp declare target(omp_get_supported_active_levels )
diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h
index 2b0063eb23a0a..95cd3965a518d 100644
--- a/openmp/runtime/src/kmp_ftn_entry.h
+++ b/openmp/runtime/src/kmp_ftn_entry.h
@@ -1543,14 +1543,26 @@ int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_MAX_TASK_PRIORITY)(void) {
 #endif
 }
 
-// This function will be defined in libomptarget. When libomptarget is not
-// loaded, we assume we are on the host and return KMP_HOST_DEVICE.
+// These functions will be defined in libomptarget. When libomptarget is not
+// loaded, we assume we are on the host.
 // Compiler/libomptarget will handle this if called inside target.
 int FTN_STDCALL FTN_GET_DEVICE_NUM(void) KMP_WEAK_ATTRIBUTE_EXTERNAL;
 int FTN_STDCALL FTN_GET_DEVICE_NUM(void) {
   return KMP_EXPAND_NAME(FTN_GET_INITIAL_DEVICE)();
 }
 
+const char *FTN_STDCALL FTN_GET_UID_FROM_DEVICE(int device_num)
+    KMP_WEAK_ATTRIBUTE_EXTERNAL;
+const char *FTN_STDCALL FTN_GET_UID_FROM_DEVICE(int device_num) {
+  // Returns the same string as used by libomptarget
+  return "HOST";
+}
+int FTN_STDCALL FTN_GET_DEVICE_FROM_UID(const char *device_uid)
+    KMP_WEAK_ATTRIBUTE_EXTERNAL;
+int FTN_STDCALL FTN_GET_DEVICE_FROM_UID(const char *device_uid) {
+  return KMP_EXPAND_NAME(FTN_GET_INITIAL_DEVICE)();
+}
+
 // Compiler will ensure that this is only called from host in sequential region
 int FTN_STDCALL KMP_EXPAND_NAME(FTN_PAUSE_RESOURCE)(kmp_pause_status_t kind,
                                                     int device_num) {
diff --git a/openmp/runtime/src/kmp_ftn_os.h b/openmp/runtime/src/kmp_ftn_os.h
index ae0ed067235e5..c439a058f22b4 100644
--- a/openmp/runtime/src/kmp_ftn_os.h
+++ b/openmp/runtime/src/kmp_ftn_os.h
@@ -140,6 +140,8 @@
 #define FTN_GET_MEMSPACE_NUM_RESOURCES omp_get_memspace_num_resources
 #define FTN_GET_SUBMEMSPACE omp_get_submemspace
 #define FTN_GET_DEVICE_NUM omp_get_device_num
+#define FTN_GET_UID_FROM_DEVICE omp_get_uid_from_device
+#define FTN_GET_DEVICE_FROM_UID omp_get_device_from_uid
 #define FTN_SET_AFFINITY_FORMAT omp_set_affinity_format
 #define FTN_GET_AFFINITY_FORMAT omp_get_affinity_format
 #define FTN_DISPLAY_AFFINITY omp_display_affinity
@@ -289,6 +291,8 @@
 #define FTN_ALLOC omp_alloc_
 #define FTN_FREE omp_free_
 #define FTN_GET_DEVICE_NUM omp_get_device_num_
+#define FTN_GET_UID_FROM_DEVICE omp_get_uid_from_device_
+#define FTN_GET_DEVICE_FROM_UID omp_get_device_from_uid_
 #define FTN_SET_AFFINITY_FORMAT omp_set_affinity_format_
 #define FTN_GET_AFFINITY_FORMAT omp_get_affinity_format_
 #define FTN_DISPLAY_AFFINITY omp_display_affinity_
@@ -436,6 +440,8 @@
 #define FTN_GET_MEMSPACE_NUM_RESOURCES OMP_GET_MEMSPACE_NUM_RESOURCES
 #define FTN_GET_SUBMEMSPACE OMP_GET_SUBMEMSPACE
 #define FTN_GET_DEVICE_NUM OMP_GET_DEVICE_NUM
+#define FTN_GET_UID_FROM_DEVICE OMP_GET_UID_FROM_DEVICE
+#define FTN_GET_DEVICE_FROM_UID OMP_GET_DEVICE_FROM_UID
 #define FTN_SET_AFFINITY_FORMAT OMP_SET_AFFINITY_FORMAT
 #define FTN_GET_AFFINITY_FORMAT OMP_GET_AFFINITY_FORMAT
 #define FTN_DISPLAY_AFFINITY OMP_DISPLAY_AFFINITY
@@ -585,6 +591,8 @@
 #define FTN_ALLOC OMP_ALLOC_
 #define FTN_FREE OMP_FREE_
 #define FTN_GET_DEVICE_NUM OMP_GET_DEVICE_NUM_
+#define FTN_GET_UID_FROM_DEVICE OMP_GET_UID_FROM_DEVICE_
+#define FTN_GET_DEVICE_FROM_UID OMP_GET_DEVICE_FROM_UID_
 #define FTN_SET_AFFINITY_FORMAT OMP_SET_AFFINITY_FORMAT_
 #define FTN_GET_AFFINITY_FORMAT OMP_GET_AFFINITY_FORMAT_
 #define FTN_DISPLAY_AFFINITY OMP_DISPLAY_AFFINITY_
diff --git a/openmp/runtime/test/api/omp_device_uid.c b/openmp/runtime/test/api/omp_device_uid.c
new file mode 100644
index 0000000000000..975dad73f5b18
--- /dev/null
+++ b/openmp/runtime/test/api/omp_device_uid.c
@@ -0,0 +1,89 @@
+// RUN: %libomp-compile-and-run 2>&1 | FileCheck %s
+// Linking fails for icc 18
+// UNSUPPORTED: icc-18
+
+#include <omp_testsuite.h>
+#include <string.h>
+
+// Note that the device UIDs for the "fake" host devices used by libomptarget
+// will always be the same as the UID for the initial device (since it *is* the
+// same device).  The other way round, the device number returned for this UID
+// will always be the initial device.
+
+int is_host_device_uid(const char *device_uid) {
+  return strcmp(device_uid,
+                omp_get_uid_from_device(omp_get_initial_device())) == 0;
+}
+
+int test_omp_device_uid(int device_num) {
+  const char *device_uid = omp_get_uid_from_device(device_num);
+  if (device_uid == NULL) {
+    printf("FAIL for device %d: omp_get_uid_from_device returned NULL\n",
+           device_num);
+    return 0;
+  }
+
+  int device_num_from_uid = omp_get_device_from_uid(device_uid);
+  if (device_num_from_uid != (is_host_device_uid(device_uid)
+                                  ? omp_get_initial_device()
+                                  : device_num)) {
+    printf(
+        "FAIL for device %d: omp_get_device_from_uid returned %d (UID: %s)\n",
+        device_num, device_num_from_uid, device_uid);
+    return 0;
+  }
+
+  if (device_num == omp_get_initial_device())
+    return 1;
+
+  int success = 1;
+
+// Note that the following code may be executed on the host if the host is the
+// device
+#pragma omp target map(tofrom : success) device(device_num)
+  {
+    int device_num = omp_get_device_num();
+
+    // omp_get_uid_from_device() in the device runtime is a dummy function
+    // returning NULL
+    const char *device_uid_target = omp_get_uid_from_device(device_num);
+
+    // omp_get_device_from_uid() in the device runtime is a dummy function
+    // returning omp_invalid_device.
+    device_num_from_uid = omp_get_device_from_uid(device_uid_target);
+
+    // Depending on whether we're executing on the device or the host, we either
+    // got NULL as the device UID or the correct device UID.  Consequently,
+    // omp_get_device_from_uid() either returned omp_invalid_device or the
+    // correct device number (aka omp_get_initial_device()).
+    if (device_uid_target ? device_num_from_uid != omp_get_initial_device()
+                          : device_num_from_uid != omp_invalid_device) {
+      printf("FAIL for device %d (target): omp_get_device_from_uid returned %d "
+             "(UID: %s)\n",
+             device_num, device_num_from_uid, device_uid_target);
+      success = 0;
+    }
+  }
+
+  return success;
+}
+
+int main() {
+  int num_devices = omp_get_num_devices();
+  int num_failed = 0;
+  // (also test initial device aka num_devices)
+  for (int i = 0; i < num_devices + 1; i++) {
+    if (!test_omp_device_uid(i)) {
+      printf("FAIL for device %d\n", i);
+      num_failed++;
+    }
+  }
+  if (num_failed) {
+    printf("FAIL\n");
+    return 1;
+  }
+  printf("PASS\n");
+  return 0;
+}
+
+// CHECK: PASS

@CatherineMoore
Copy link
Contributor

@CatherineMoore

@ro-i ro-i force-pushed the users/ro-i/openmp-device-uid branch from 039374b to fda29e1 Compare October 21, 2025 19:33
@jhuber6
Copy link
Contributor

jhuber6 commented Oct 21, 2025

Do we have a good way to get a UUID for the host device?

@ro-i
Copy link
Contributor Author

ro-i commented Oct 21, 2025

What do you mean? Regarding the discussion of the fake host devices in #164391? Or whether to put a shared constant in libomp and access it from libomptarget similar to int __kmpc_get_target_offload(void) __attribute__((weak));?

@ro-i ro-i force-pushed the users/ro-i/openmp-device-uid branch 3 times, most recently from 89c5515 to b963a70 Compare October 22, 2025 14:43
@ro-i ro-i force-pushed the users/ro-i/openmp-device-uid branch from b963a70 to a18141c Compare October 23, 2025 07:23
@ro-i ro-i force-pushed the users/ro-i/offload-device-uid branch from fb02cf7 to fff258a Compare October 23, 2025 07:33
@ro-i ro-i force-pushed the users/ro-i/openmp-device-uid branch 2 times, most recently from 6426ccb to 36c6325 Compare October 24, 2025 16:53
@ro-i ro-i mentioned this pull request Oct 24, 2025
Base automatically changed from users/ro-i/offload-device-uid to main November 4, 2025 19:15
Use the implementation in libomptarget. If libomptarget is not
available, always return the UID / device number of the host / the
initial device.
@ro-i ro-i force-pushed the users/ro-i/openmp-device-uid branch from 36c6325 to d070b75 Compare November 4, 2025 20:26
@ro-i
Copy link
Contributor Author

ro-i commented Nov 4, 2025

Ping

1 similar comment
@ro-i
Copy link
Contributor Author

ro-i commented Nov 17, 2025

Ping

Copy link
Contributor

@kevinsala kevinsala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please wait for a Fortran/OpenMP reviewer to approve it.

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ro-i ro-i merged commit 65c4a53 into main Nov 18, 2025
10 checks passed
@ro-i ro-i deleted the users/ro-i/openmp-device-uid branch November 18, 2025 14:22
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder amdgpu-offload-rhel-9-cmake-build-only running on rocm-docker-rhel-9 while building offload,openmp at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/205/builds/28270

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: '../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py --jobs=32' (failure)
...
[17/67] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan.so
[18/67] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan_aliases.so
[19/67] Generating OffloadImplFuncDecls.inc
[20/67] Generating OffloadAPI.h
[21/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.asan.so
[22/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.memprof.so
[23/62] Generating OffloadEntryPoints.inc
[24/62] Generating OffloadPrint.hpp
[25/62] Generating /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/compile_commands.json
[26/62] Generating omp_lib.mod, omp_lib_kinds.mod
FAILED: openmp/runtime/src/omp_lib.mod openmp/runtime/src/omp_lib_kinds.mod /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src/omp_lib.mod /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src/omp_lib_kinds.mod 
cd /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src && /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/bin/flang -cpp -fsyntax-only omp_lib.F90
error: Semantic errors in omp_lib.F90
./omp_lib.F90:425:31: error: A function interface may not declare an assumed-length CHARACTER(*) result
              character (len=*) omp_get_uid_from_device
                                ^^^^^^^^^^^^^^^^^^^^^^^
./omp_lib.F90:425:31: error: Interoperable character function result must have length one
              character (len=*) omp_get_uid_from_device
                                ^^^^^^^^^^^^^^^^^^^^^^^
[27/62] Building CXX object openmp/libompd/src/CMakeFiles/ompd.dir/omp-debug.cpp.o
[28/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_extra.cpp.o
[29/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_cdecl.cpp.o
[30/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_gsupport.cpp.o
[31/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/DeviceImage.cpp.o
[32/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/OMPT/Callback.cpp.o
[33/62] Building CXX object offload/tools/kernelreplay/CMakeFiles/llvm-omp-kernel-replay.dir/llvm-omp-kernel-replay.cpp.o
[34/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/LegacyAPI.cpp.o
[35/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OffloadRTL.cpp.o
[36/62] Building CXX object offload/plugins-nextgen/host/CMakeFiles/omptarget.rtl.host.dir/src/rtl.cpp.o
[37/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/InteropAPI.cpp.o
[38/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/Mapping.cpp.o
[39/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/GlobalHandler.cpp.o
[40/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/device.cpp.o
[41/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/API.cpp.o
[42/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/interface.cpp.o
[43/62] Building CXX object offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadLib.cpp.o
[44/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/PluginManager.cpp.o
[45/62] Building CXX object offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o
[46/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/omptarget.cpp.o
[47/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/PluginInterface.cpp.o
[48/62] Building CXX object offload/plugins-nextgen/cuda/CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o
[49/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/JIT.cpp.o
[50/62] Building CXX object offload/plugins-nextgen/amdgpu/CMakeFiles/omptarget.rtl.amdgpu.dir/src/rtl.cpp.o
[51/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/RPC.cpp.o
ninja: build stopped: subcommand failed.
[8204/8207] Completed 'runtimes-amdgcn-amd-amdhsa'
FAILED: runtimes/runtimes-stamps/runtimes-build /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-stamps/runtimes-build 
cd /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-bins && /usr/bin/cmake --build .
ninja: build stopped: subcommand failed.
Step 7 (build cmake config) failure: build cmake config (failure)
...
[17/67] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan.so
[18/67] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan_aliases.so
[19/67] Generating OffloadImplFuncDecls.inc
[20/67] Generating OffloadAPI.h
[21/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.asan.so
[22/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.memprof.so
[23/62] Generating OffloadEntryPoints.inc
[24/62] Generating OffloadPrint.hpp
[25/62] Generating /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/compile_commands.json
[26/62] Generating omp_lib.mod, omp_lib_kinds.mod
FAILED: openmp/runtime/src/omp_lib.mod openmp/runtime/src/omp_lib_kinds.mod /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src/omp_lib.mod /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src/omp_lib_kinds.mod 
cd /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src && /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/bin/flang -cpp -fsyntax-only omp_lib.F90
error: Semantic errors in omp_lib.F90
./omp_lib.F90:425:31: error: A function interface may not declare an assumed-length CHARACTER(*) result
              character (len=*) omp_get_uid_from_device
                                ^^^^^^^^^^^^^^^^^^^^^^^
./omp_lib.F90:425:31: error: Interoperable character function result must have length one
              character (len=*) omp_get_uid_from_device
                                ^^^^^^^^^^^^^^^^^^^^^^^
[27/62] Building CXX object openmp/libompd/src/CMakeFiles/ompd.dir/omp-debug.cpp.o
[28/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_extra.cpp.o
[29/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_cdecl.cpp.o
[30/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_gsupport.cpp.o
[31/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/DeviceImage.cpp.o
[32/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/OMPT/Callback.cpp.o
[33/62] Building CXX object offload/tools/kernelreplay/CMakeFiles/llvm-omp-kernel-replay.dir/llvm-omp-kernel-replay.cpp.o
[34/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/LegacyAPI.cpp.o
[35/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OffloadRTL.cpp.o
[36/62] Building CXX object offload/plugins-nextgen/host/CMakeFiles/omptarget.rtl.host.dir/src/rtl.cpp.o
[37/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/InteropAPI.cpp.o
[38/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/Mapping.cpp.o
[39/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/GlobalHandler.cpp.o
[40/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/device.cpp.o
[41/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/API.cpp.o
[42/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/interface.cpp.o
[43/62] Building CXX object offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadLib.cpp.o
[44/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/PluginManager.cpp.o
[45/62] Building CXX object offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o
[46/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/omptarget.cpp.o
[47/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/PluginInterface.cpp.o
[48/62] Building CXX object offload/plugins-nextgen/cuda/CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o
[49/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/JIT.cpp.o
[50/62] Building CXX object offload/plugins-nextgen/amdgpu/CMakeFiles/omptarget.rtl.amdgpu.dir/src/rtl.cpp.o
[51/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/RPC.cpp.o
ninja: build stopped: subcommand failed.
[8204/8207] Completed 'runtimes-amdgcn-amd-amdhsa'
FAILED: runtimes/runtimes-stamps/runtimes-build /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-stamps/runtimes-build 
cd /home/botworker/bbot/amdgpu-offload-rhel-9-cmake-build-only/build/runtimes/runtimes-bins && /usr/bin/cmake --build .
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 18, 2025

LLVM Buildbot has detected a new failure on builder amdgpu-offload-ubuntu-22-cmake-build-only running on rocm-docker-ubu-22 while building offload,openmp at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/203/builds/29479

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: '../llvm-zorg/zorg/buildbot/builders/annotated/amdgpu-offload-cmake.py --jobs=32' (failure)
...
[16/67] Generating OffloadAPI.h
[17/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan_aliases.so
[18/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.nsan.so
[19/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.ubsan_standalone.so
[20/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.memprof.so
[21/62] Generating OffloadEntryPoints.inc
[22/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.asan.so
[23/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan.so
[24/62] Generating OffloadPrint.hpp
[25/62] Generating omp_lib.mod, omp_lib_kinds.mod
FAILED: openmp/runtime/src/omp_lib.mod openmp/runtime/src/omp_lib_kinds.mod /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src/omp_lib.mod /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src/omp_lib_kinds.mod 
cd /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src && /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/bin/flang -cpp -fsyntax-only omp_lib.F90
error: Semantic errors in omp_lib.F90
./omp_lib.F90:425:31: error: A function interface may not declare an assumed-length CHARACTER(*) result
              character (len=*) omp_get_uid_from_device
                                ^^^^^^^^^^^^^^^^^^^^^^^
./omp_lib.F90:425:31: error: Interoperable character function result must have length one
              character (len=*) omp_get_uid_from_device
                                ^^^^^^^^^^^^^^^^^^^^^^^
[26/62] Generating /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/compile_commands.json
[27/62] Building CXX object openmp/libompd/src/CMakeFiles/ompd.dir/omp-debug.cpp.o
[28/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_extra.cpp.o
[29/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_cdecl.cpp.o
[30/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_gsupport.cpp.o
[31/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/DeviceImage.cpp.o
[32/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/OMPT/Callback.cpp.o
[33/62] Building CXX object offload/tools/kernelreplay/CMakeFiles/llvm-omp-kernel-replay.dir/llvm-omp-kernel-replay.cpp.o
[34/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/LegacyAPI.cpp.o
[35/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OffloadRTL.cpp.o
[36/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/InteropAPI.cpp.o
[37/62] Building CXX object offload/plugins-nextgen/host/CMakeFiles/omptarget.rtl.host.dir/src/rtl.cpp.o
[38/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/Mapping.cpp.o
[39/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/GlobalHandler.cpp.o
[40/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/API.cpp.o
[41/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/device.cpp.o
[42/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/interface.cpp.o
[43/62] Building CXX object offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadLib.cpp.o
[44/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/PluginManager.cpp.o
[45/62] Building CXX object offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o
[46/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/omptarget.cpp.o
[47/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/PluginInterface.cpp.o
[48/62] Building CXX object offload/plugins-nextgen/cuda/CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o
[49/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/JIT.cpp.o
[50/62] Building CXX object offload/plugins-nextgen/amdgpu/CMakeFiles/omptarget.rtl.amdgpu.dir/src/rtl.cpp.o
[51/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/RPC.cpp.o
ninja: build stopped: subcommand failed.
[8204/8207] Completed 'runtimes-amdgcn-amd-amdhsa'
FAILED: runtimes/runtimes-stamps/runtimes-build /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-stamps/runtimes-build 
cd /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-bins && /usr/bin/cmake --build .
Step 7 (build cmake config) failure: build cmake config (failure)
...
[16/67] Generating OffloadAPI.h
[17/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan_aliases.so
[18/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.nsan.so
[19/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.ubsan_standalone.so
[20/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.memprof.so
[21/62] Generating OffloadEntryPoints.inc
[22/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.asan.so
[23/62] Linking CXX shared library /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib/clang/22/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan.so
[24/62] Generating OffloadPrint.hpp
[25/62] Generating omp_lib.mod, omp_lib_kinds.mod
FAILED: openmp/runtime/src/omp_lib.mod openmp/runtime/src/omp_lib_kinds.mod /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src/omp_lib.mod /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src/omp_lib_kinds.mod 
cd /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-bins/openmp/runtime/src && /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/bin/flang -cpp -fsyntax-only omp_lib.F90
error: Semantic errors in omp_lib.F90
./omp_lib.F90:425:31: error: A function interface may not declare an assumed-length CHARACTER(*) result
              character (len=*) omp_get_uid_from_device
                                ^^^^^^^^^^^^^^^^^^^^^^^
./omp_lib.F90:425:31: error: Interoperable character function result must have length one
              character (len=*) omp_get_uid_from_device
                                ^^^^^^^^^^^^^^^^^^^^^^^
[26/62] Generating /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/compile_commands.json
[27/62] Building CXX object openmp/libompd/src/CMakeFiles/ompd.dir/omp-debug.cpp.o
[28/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_extra.cpp.o
[29/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_cdecl.cpp.o
[30/62] Building CXX object openmp/runtime/src/CMakeFiles/omp.dir/kmp_gsupport.cpp.o
[31/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/DeviceImage.cpp.o
[32/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/OMPT/Callback.cpp.o
[33/62] Building CXX object offload/tools/kernelreplay/CMakeFiles/llvm-omp-kernel-replay.dir/llvm-omp-kernel-replay.cpp.o
[34/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/LegacyAPI.cpp.o
[35/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OffloadRTL.cpp.o
[36/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/InteropAPI.cpp.o
[37/62] Building CXX object offload/plugins-nextgen/host/CMakeFiles/omptarget.rtl.host.dir/src/rtl.cpp.o
[38/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/Mapping.cpp.o
[39/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/GlobalHandler.cpp.o
[40/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/OpenMP/API.cpp.o
[41/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/device.cpp.o
[42/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/interface.cpp.o
[43/62] Building CXX object offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadLib.cpp.o
[44/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/PluginManager.cpp.o
[45/62] Building CXX object offload/liboffload/CMakeFiles/LLVMOffload.dir/src/OffloadImpl.cpp.o
[46/62] Building CXX object offload/libomptarget/CMakeFiles/omptarget.dir/omptarget.cpp.o
[47/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/PluginInterface.cpp.o
[48/62] Building CXX object offload/plugins-nextgen/cuda/CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o
[49/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/JIT.cpp.o
[50/62] Building CXX object offload/plugins-nextgen/amdgpu/CMakeFiles/omptarget.rtl.amdgpu.dir/src/rtl.cpp.o
[51/62] Building CXX object offload/plugins-nextgen/common/CMakeFiles/PluginCommon.dir/src/RPC.cpp.o
ninja: build stopped: subcommand failed.
[8204/8207] Completed 'runtimes-amdgcn-amd-amdhsa'
FAILED: runtimes/runtimes-stamps/runtimes-build /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-stamps/runtimes-build 
cd /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/runtimes/runtimes-bins && /usr/bin/cmake --build .

ro-i added a commit that referenced this pull request Nov 18, 2025
@ro-i ro-i restored the users/ro-i/openmp-device-uid branch November 18, 2025 15:45
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Nov 18, 2025
…_get_device_from_uid()" (#168547)

Reverts llvm/llvm-project#164392 due to fortran issues
nekoshirro pushed a commit to nekoshirro/Alchemist-LLVM that referenced this pull request Nov 24, 2025
…_from_uid()" (#168547)

Reverts llvm/llvm-project#164392 due to fortran issues
Signed-off-by: Hafidz Muzakky <[email protected]>
aadeshps-mcw pushed a commit to aadeshps-mcw/llvm-project that referenced this pull request Nov 26, 2025
…d() (llvm#164392)

Use the implementation in libomptarget. If libomptarget is not
available, always return the UID / device number of the host / the
initial device.
aadeshps-mcw pushed a commit to aadeshps-mcw/llvm-project that referenced this pull request Nov 26, 2025
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Nov 26, 2025
…d() (llvm#164392)

Use the implementation in libomptarget. If libomptarget is not
available, always return the UID / device number of the host / the
initial device.
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

offload openmp:libomp OpenMP host runtime openmp:libomptarget OpenMP offload runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants