This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Enable omp_get_num_devices() on Windows
ClosedPublic

Authored by hbae on Feb 5 2021, 2:26 PM.

Details

Summary

This patch enables omp_get_num_devices() and omp_get_initial_device() on
Windows by providing an alternative to dlsym on Windows, and proposes to
add a new libomptarget entry, __tgt_get_num_devices().

Diff Detail

Event Timeline

hbae created this revision.Feb 5 2021, 2:26 PM
hbae requested review of this revision.Feb 5 2021, 2:26 PM
hbae updated this revision to Diff 321945.Feb 6 2021, 8:59 AM
hbae edited the summary of this revision. (Show Details)

Applied similar change to omp_get_initial_device().

If I add GetProcAddress result conversion to (void *) I get linker error if built by clang or gcc. E.g. for clang:

C:\Progs\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\ld.exe: CMakeFiles\omp.dir/objects.a(z_Windows_NT_util.cpp.obj):z_Windows_NT_util.:(.text+0x1dfa): undefined reference to `EnumProcessModules'
C:\Progs\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\ld.exe: CMakeFiles\omp.dir/objects.a(z_Windows_NT_util.cpp.obj):z_Windows_NT_util.:(.text+0x1e26): undefined reference to `EnumProcessModules'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: * [runtime/src/libomp.dll] Error 1
make[1]:
* [runtime/src/CMakeFiles/omp.dir/all] Error 2
make: *** [all] Error 2

That indicates missing -lpsapi on link line.

openmp/runtime/src/z_Windows_NT_util.cpp
1652

clang complains on this line:

C:\tmp\llvm\trunk\runtime\src\z_Windows_NT_util.cpp:1652:12: error: assigning to 'void *' from 'FARPROC'

  (aka 'long long (*)()') converts between void pointer and function pointer
proc = GetProcAddress(modules[i], name);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I guess the result should be converted to (void *) before assignment.

Similar complaint from gcc:

C:/tmp/llvm/trunk/runtime/src/z_Windows_NT_util.cpp:1652:26: error: invalid conversion from 'FARPROC' {aka 'long long int (*)()'} to 'void*' [-fpermissive]
1652 | proc = GetProcAddress(modules[i], name);

|            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
|                          |
|                          FARPROC {aka long long int (*)()}

Two comments, that are not directly related to this patch, but could be addressed while we are here.

openmp/runtime/src/kmp_ftn_entry.h
967–968

Why is there no KMP_EXPAND_NAME macro applied to this function?

971–972

Conceptually, we could really just call the omp_get_num_devices function from above.
I would at least expect that the functions are called in a consistent order.

hbae updated this revision to Diff 323013.Feb 11 2021, 7:46 AM

Addressed issues reported by reviewers.

hbae marked 2 inline comments as done.Feb 11 2021, 7:46 AM
This revision is now accepted and ready to land.Feb 11 2021, 12:24 PM
This revision was landed with ongoing or failed builds.Feb 11 2021, 1:08 PM
This revision was automatically updated to reflect the committed changes.