[Openmp-commits] [openmp] [OpenMP][OMPT] Map `ompt_get_num_devices` to runtime function (PR #200790)

Jan André Reuter via Openmp-commits openmp-commits at lists.llvm.org
Mon Jun 1 04:55:40 PDT 2026


https://github.com/Thyre created https://github.com/llvm/llvm-project/pull/200790

Since 82e94a593433f36734e2d34898d353a2ecb65b8b, `ompt_get_num_devices` was hard coded to always provide a return value of `1`, regardless of the actual number of devices. Tools relying on this return value were henced forced to use other approaches to estimate the number of available devices.

To improve the situtation, map the returned value to the one provided by `omp_get_num_devices()`. This does not resolve the issue completely though. When OMPT is initialized through `libomptarget.so`, the PluginManager, providing the number of devices, is not initialized until after OMPT has been fully set up. This means that tools, trying to retrieve the number of devices during the _initialize_ callback, will still receive the incorrect number of devices.

Still, this is a significant improvement compared to the prior state, providing an incorrect result for most of the program runtime.

Closes #196829

>From 1b62ca236791d9bda426cff4ad6ba4ba7228e57d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Andr=C3=A9=20Reuter?= <j.reuter at fz-juelich.de>
Date: Mon, 1 Jun 2026 13:52:07 +0200
Subject: [PATCH] [OpenMP][OMPT] Map `ompt_get_num_devices` to runtime func
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since 82e94a593433f36734e2d34898d353a2ecb65b8b, `ompt_get_num_devices` was hard
coded to always provide a return value of `1`, regardless of the actual number
of devices. Tools relying on this return value were henced forced to use other
approaches to estimate the number of available devices.

To improve the situtation, map the returned value to the one provided by
`omp_get_num_devices()`. This does not resolve the issue completely though.
When OMPT is initialized through `libomptarget.so`, the PluginManager,
providing the number of devices, is not initialized until after OMPT has been
fully set up. This means that tools, trying to retrieve the number of devices
during the _initialize_ callback, will still receive the incorrect number of
devices.

Still, this is a significant improvement compared to the prior state, providing
an incorrect result for most of the program runtime.

Signed-off-by: Jan André Reuter <j.reuter at fz-juelich.de>
---
 openmp/runtime/src/ompt-general.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/openmp/runtime/src/ompt-general.cpp b/openmp/runtime/src/ompt-general.cpp
index 959457d380d03..a708a8d76fcf4 100644
--- a/openmp/runtime/src/ompt-general.cpp
+++ b/openmp/runtime/src/ompt-general.cpp
@@ -864,8 +864,10 @@ OMPT_API_ROUTINE int ompt_get_target_info(uint64_t *device_num,
   return 0; // thread is not in a target region
 }
 
+extern "C" int omp_get_num_devices(void);
+
 OMPT_API_ROUTINE int ompt_get_num_devices(void) {
-  return 1; // only one device (the current device) is available
+  return omp_get_num_devices();
 }
 
 /*****************************************************************************



More information about the Openmp-commits mailing list