Files
Jan André Reuter 0a4798ad4b [OMPT][OpenMP] Use omp_initial_device for host in callbacks (#192924)
The OpenMP specification offers different ways for identifying the host
device. While users of the OpenMP API can use `omp_get_initial_device()`
or the constant `omp_initial_device` (available since OpenMP v5.2), a
tool needs to rely on the `initial_device_num` passed by the OpenMP
runtime during the `initialize` callback.

In #134451, it was discovered that the `initial_device_num` passed is
always `0`, regardless of any device are available for offload
execution. For host-only OpenMP code, this matches the result of
`omp_get_num_devices()`, and is a valid result. In the case of devices
being available though, this passed identifier is incorrect. While
`libomp` calls `omp_get_num_devices()`, `libomptarget` has not fully
initialized its PluginManager at that point, hence returning no
available devices. Tools relying on `initial_device_num` might therefore
incorrectly assume host-side execution when some code runs on a device.
Since the `ompt_get_num_devices()` entry point is also not fully
implemented, tools currently need to do on-the-fly handling for the host
device.

To make handling easier, consistently use the `omp_initial_device`
identifier as the `initial_device_num` and for all device callbacks.
This does not rely on knowing the number of available devices during
OMPT initialization in the runtime and ensures a consistent value for
tools to handle.

Closes #134451

Signed-off-by: Jan André Reuter <j.reuter@fz-juelich.de>
2026-04-29 12:06:41 +02:00
..