-
Couldn't load subscription status.
- Fork 1.6k
CMake: Pass OpenMP compiler and linker flags through CMake targets
#5180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a6e2183 to
b0746c7
Compare
bf2f49f to
18ccac9
Compare
|
Ok, this is ready. If appropriate, I can also remove all OpenMP related code in |
|
see #5169 for the needed setup |
|
A successful test on Linux x86_64, where libomp is installed system-wide in /usr/. I ran the following: and the linkage is correct: |
|
Also works on M1 up to date system, with openblas.pc looks correct too. |
Using `OpenMP::OpenMP_LANG` targets for CMake is less error-prone than passing the compiler and linker flags manually. Furthermore, it allows the user to customize those flags by setting `OpenMP_LANG_FLAGS`, `OpenMP_LANG_LIB_NAMES`, and `OpenMP_omp_LIBRARY`.
18ccac9 to
251c3f8
Compare
|
Hi @martin-frbg, could you initiate those pending checks for the GitHub workflow? Thanks for the help. |
|
The loongarch64 test does not use cmake, so the frozen test was not related to this PR. |
|
yes, that was probably some network error in the cloud |
|
Thank you! |
| if (USE_OPENMP AND (NOT NOFORTRAN)) | ||
| # Disable OpenMP for LAPACK Fortran codes on Windows. | ||
| if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") | ||
| target_link_libraries(LAPACK_OVERRIDES OpenMP::OpenMP_Fortran) | ||
| endif() | ||
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason Why?
You know there is GNU Fortran and Flang (MinGW) for Windows that could build lapack+OpenMP on Windows.
@ywwry66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is simply because the code was there before, added in 0beea3a, and I didn't investigate the feasibility of enabling OpenMP for OpenBLAS on Windows while working on this PR. But you are probably right, as your PR has passed the CI tests. @MehdiChinoune
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flang/OpenMP on Windows is still a bit dubious (it compiles but led to errors last time I checked, and I need to check again with a current version). but the restriction you complain about is only in the CMake configuration, and indeed mostly historical from when CMake usually implied someone using Visual Studio.
|
Has this fix been released to the See this issue: ocaml/opam-repository#27483 |
|
No, homebrew folks closed the corresponding issue as won't fix. With the rationale that it works with the "real" gcc, i.e. GNU gcc, not the clang renamed by Apple to gcc. |
|
Ahem, do I get this right that the entire motivation for this PR is that the homebrew package is set up to be built with OpenMP enabled, while the native AppleClang does not support OpenMP at all ? |
|
No, the native Apple clang does support OpenMP, but it requires a non-standard option to do so. And, as all clangs, it cannot use GNU OpenMP, aka libgomp, it needs llvm's OpenMP, aka libomp. So you can build and use OpenMP-enabled openblas with gfortran+clang, but with llvm's OpenMP; in addition, Apple's clang does not grok |
|
According to https://mac.r-project.org/openmp/ that would be |
|
I don't know what you mean by "another compiler". gcc (the real thing, not a renamed Apple clang) cannot handle macOS headers, as they use blocks. Do you mean to use several C compilers to build a project ? Building a project with several C compilers isn't standard, and would require custom scripts... |
Well, such a library is available in Homebrew. But the current OpenBLAS won't easily allow to create a homebrew formula to use it instead of incompatible with clang libgomp. (R Project overcomplicates things here IMHO)
I don't follow here. Do you mean to say that there is a way to use libgomp with clang? |
While one of the applications of the PR is to allow building OpenBLAS on macOS with GCC+Apple Clang with OpenMP support, the main motivation is to let CMake handle OpenMP related Fortran flags automatically, and at the same time offers better customizability. In this regard, the changes are very generic and an overall improvement to the old cmake code that handles flags manually, and I don't see how they are invasive. Admittedly, the test I added that caused the NVHPC issue was a little sloppy. My suggestion here is to either demote the error to warning or remove it altogether instead of reverting the entire PR. |
|
Not allowing a seamless treatment of OpenBLAS on macOS would basically push users to Apple's Accelerate framework, which, after years of lagging behind OpenBLAS in following BLAS/LAPACK standards, has caught up. E.g., numpy/scipy, one of the most popular BLAS/LAPACK-using Python libraries, switched to using Accelerate in their binary wheels. |
Using
OpenMP::OpenMP_LANGtargets for CMake is less error-prone than passing the compiler and linker flags manually. Furthermore, it allows the user to customize those flags by settingOpenMP_LANG_FLAGS,OpenMP_LANG_LIB_NAMES, andOpenMP_omp_LIBRARY.