Skip to content

Conversation

@ro-i
Copy link
Contributor

@ro-i ro-i commented Dec 2, 2025

Taking omp_get_uid_from_device and omp_get_device_from_uid as examples.

OpenMP 6.0 defines these functions as follows:

const char *omp_get_uid_from_device(int device_num);

character(:) function omp_get_uid_from_device(device_num)
  pointer :: omp_get_uid_from_device
  integer, intent(in) :: device_num

and

int omp_get_device_from_uid(const char *uid);

integer function omp_get_device_from_uid(uid)
  character(len=*), intent(in) :: uid

As a result, we cannot directly map the Fortran API declarations to the C API declarations. We need some adapter code to do the conversion.

However, this means that we cannot just define the two functions as omp_* in kmp_ftn_entry.h without clashing with the adapter code.

The current situation is less than ideal, as demonstrated by this draft PR, which shall serve as a base for discussing different solution approaches.


@mjklemm as discussed

@ro-i ro-i requested review from Meinersbur, jplehr and mjklemm December 2, 2025 21:53
Taking omp_get_uid_from_device and omp_get_device_from_uid as examples.

OpenMP 6.0 defines these functions as follows:
```
const char *omp_get_uid_from_device(int device_num);

character(:) function omp_get_uid_from_device(device_num)
  pointer :: omp_get_uid_from_device
  integer, intent(in) :: device_num
```
and
```
int omp_get_device_from_uid(const char *uid);

integer function omp_get_device_from_uid(uid)
  character(len=*), intent(in) :: uid
```

As a result, we cannot directly map the Fortran API declarations to the
C API declarations. We need some adapter code to do the conversion.

However, this means that we cannot just define the two functions as
omp_* in kmp_ftn_entry.h without clashing with the adapter code.

The current situation is less than ideal, as demonstrated by this draft
PR, which shall serve as a base for discussing different solution
approaches.
@ro-i ro-i force-pushed the users/ro-i/openmp-device-uid-fortran branch from b964ce2 to 6572a68 Compare December 2, 2025 21:53
Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

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

I would suggest to build on top of #169638 and only support LLVM_ENABLE_RUNTIMES build mode to avoid fixing the many differences between the build modes. For instance, the difference between LIBOMP_FORTRAN_MODULES_COMPILER and CMAKE_Fortran_COMPILER. With only LIBOMP_FORTRAN_MODULES_COMPILER set, like a bootstrapping build currently does, you cannot use target_sources(omp kmp_ftn_support.f90), because CMake does not know a Fortran compiler. Also, with openmp and flang-rt built in the same runtimes-bin, the tight libflang_rt.runtime.a to use is just target_link_libraries(omp flang_rt.runtime)

AFAIK, RTLD_NEXT depend on link order, making this a very fragile solution. Why is it needed anyway, given that the Fortran code already has a wrapper to __kmp_get_uid_from_device_?

"${_FC_PREFIX}/lib/clang/*/lib/*/libflang_rt.runtime.a"
)
if(_FLANG_RT_CANDIDATES)
list(GET _FLANG_RT_CANDIDATES 0 _FLANG_RT_LIB)
Copy link
Member

Choose a reason for hiding this comment

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

IIUC this just takes the first libflang_rt.runtime.a. This will likely if compiling more than one flang_rt for another target, or of building libflang_rt.runtime.so instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants