Skip to content
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

[flang][OpenMP] Compile proper omp_lib.mod from the openmp/src/include sources #80874

Merged
merged 29 commits into from
Mar 20, 2024

Conversation

mjklemm
Copy link
Contributor

@mjklemm mjklemm commented Feb 6, 2024

This PR changes the build system to use use the sources for the module omp_lib and the omp_lib.h include file from the openmp runtime project and not from a separate copy of these files. This will greatly reduce potential for inconsistencies when adding features to the OpenMP runtime implementation.

When the OpenMP subproject is not configured, this PR also disables the corresponding LIT tests with a "REQUIRES" directive at the beginning of the OpenMP test files.

Flang does not yet support '!$dir if' directives.  So, to make
this file compilable with Flang, they need to be guarded with
__INTEL_COMPILER (since the if is targeting the intel compiler
anyways)
@mjklemm mjklemm self-assigned this Feb 6, 2024
@llvmbot llvmbot added the openmp:libomp OpenMP host runtime label Feb 6, 2024
@mjklemm
Copy link
Contributor Author

mjklemm commented Feb 6, 2024

@jpeyton52 Can you please have a look and see if the __INTEL_COMPILER guards are acceptable for Intel? I'd like to move this PR to eventually pick up omp_lib.f90.var and use it as the MODULE file for the OpenMP API.

@kkwli
Copy link
Collaborator

kkwli commented Feb 6, 2024

I am just wondering if we need to keep those directives. Do we support building by Intel compiler?

@mjklemm
Copy link
Contributor Author

mjklemm commented Feb 6, 2024

I am just wondering if we need to keep those directives. Do we support building by Intel compiler?

I'll let someone from Intel comment on whether they still use this code downstream or what they do with it. I'd be OK with keeping them and just guarding them for the time being.

Copy link
Contributor

@jpeyton52 jpeyton52 left a comment

Choose a reason for hiding this comment

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

For Intel Fortran compiler, there would need to be an additional flag during module compilation, -fpp, to enable preprocessing. I think gfortran is OK without the flag (and they use -cpp). I don't know about other Fortran compilers.

Basically, a two-step process in the CMake where:

  1. cmake/config-ix.cmake: add libomp_check_fortran_flag(-fpp LIBOMP_HAVE_FPP_FORTRAN_FLAG)
  2. cmake/LibompHandleFlags.cmake: add libomp_append(fflags_local -fpp LIBOMP_HAVE_FPP_FORTRAN_FLAG)

The is a single Fortran flag example (-m32) to see in each file.

openmp/runtime/src/include/omp_lib.f90.var Outdated Show resolved Hide resolved
@mjklemm
Copy link
Contributor Author

mjklemm commented Feb 6, 2024

For Intel Fortran compiler, there would need to be an additional flag during module compilation, -fpp, to enable preprocessing. I think gfortran is OK without the flag (and they use -cpp). I don't know about other Fortran compilers.

The compiler won't need it, if the extension changed from f90 to F90, because then it would automatically invoke the preprocessor on the file.

So, may I assume that Intel is generally fine with the change I'm proposing to make the file compilable with Flang?

@jpeyton52
Copy link
Contributor

jpeyton52 commented Feb 6, 2024

The compiler won't need it, if the extension changed from f90 to F90, because then it would automatically invoke the preprocessor on the file.

Haha! I wasn't aware of this Fortran oddity.

So, may I assume that Intel is generally fine with the change I'm proposing to make the file compilable with Flang?

Yes, the change looks fine.

I suppose you just need to rename the file omp_lib.f90.var -> omp_lib.F90.var and replace the filename in openmp/runtime/src/CMakeLists.txt

@llvmbot llvmbot added the flang Flang issues not falling into any other category label Feb 20, 2024
@kiranchandramohan
Copy link
Contributor

@mjklemm Since we are removing the existing omp_lib in the flang directory, it will be good to have a quick RFC to ensure all stakeholders are fine with it.

@mjklemm
Copy link
Contributor Author

mjklemm commented Feb 20, 2024

@mjklemm Since we are removing the existing omp_lib in the flang directory, it will be good to have a quick RFC to ensure all stakeholders are fine with it.

Good idea. Thanks! I have the CMake in place to build the right omp_lib module, but some tests are still failing. I will have to debug this and see where this is coming from. But I will create the RFC hopefully today or tomorrow.

@mjklemm
Copy link
Contributor Author

mjklemm commented Feb 20, 2024

@mjklemm
Copy link
Contributor Author

mjklemm commented Mar 6, 2024

Please enable the OpenMP runtime in the pre-commit or post-commit CI so that we continue to have testing for those that now require the openmp_runtime.

One immediate change to make would be to change the buildkite configuration to include "openmp" in the project list right after flang. That would slight increase the build time for each push to PR, as it would then build the OpenMP runtime, too. Not sure if that's desired.

@jplehr
Copy link
Contributor

jplehr commented Mar 6, 2024

LG. Please wait for other reviewers.

Please enable the OpenMP runtime in the pre-commit or post-commit CI so that we continue to have testing for those that now require the openmp_runtime.

Hi Kiran, more of an info, I guess: We have a Flang+OpenMP buildbot set up in staging for post-commit testing (https://lab.llvm.org/staging/#/builders/140) of flang and openmp (host + gpu offload). We are working on moving that to production.
There will be some more changes and additional coverage coming from our side for pre- and post-commit, though no clear timeline is avail yet.

I also talked with Michael offline and made him aware that our bots all build OpenMP as a runtime, which I believe he mentioned makes another change necessary.

@kiranchandramohan
Copy link
Contributor

Please enable the OpenMP runtime in the pre-commit or post-commit CI so that we continue to have testing for those that now require the openmp_runtime.

One immediate change to make would be to change the buildkite configuration to include "openmp" in the project list right after flang. That would slight increase the build time for each push to PR, as it would then build the OpenMP runtime, too. Not sure if that's desired.

If the post-commit CI of @jplehr is enabled then this is not required at the moment. But I do not think the increase would matter. We might have to check more widely in a discourse post.

LG. Please wait for other reviewers.
Please enable the OpenMP runtime in the pre-commit or post-commit CI so that we continue to have testing for those that now require the openmp_runtime.

Hi Kiran, more of an info, I guess: We have a Flang+OpenMP buildbot set up in staging for post-commit testing (https://lab.llvm.org/staging/#/builders/140) of flang and openmp (host + gpu offload). We are working on moving that to production. There will be some more changes and additional coverage coming from our side for pre- and post-commit, though no clear timeline is avail yet.

Thanks, @jplehr, for the info and your work here. It is great to have more testing for OpenMP+Flang upstream.

I also talked with Michael offline and made him aware that our bots all build OpenMP as a runtime, which I believe he mentioned makes another change necessary.

Did you mean "necessary" or "unnecessary"?

@jplehr
Copy link
Contributor

jplehr commented Mar 6, 2024

I meant "necessary", but @mjklemm would need to confirm that I understood that correctly.

@mjklemm
Copy link
Contributor Author

mjklemm commented Mar 6, 2024

I meant "necessary", but @mjklemm would need to confirm that I understood that correctly.

Yes, that's correct. When building the OpenMP runtime via LLVM_ENABLE_RUNTIMES, it seems that the .mod is not being produced. I'd like to get this into this PR to make sure that it does not break these build types.

@mjklemm
Copy link
Contributor Author

mjklemm commented Mar 12, 2024

Alrighty, I have also been able to test this on Windows and everything seems to be working fine there, too.

Anyone objecting to merge this? If not, please review and approve. :-)

luporl added a commit to luporl/llvm-zorg that referenced this pull request Mar 14, 2024
As discussed in Discourse and proposed in
llvm/llvm-project#80874, Flang will start
to use C/C++ header files and Fortran modules from OpenMP runtime.

When the mentioned PR lands, all of Flang's OpenMP tests will be
skipped as unsupported, unless the OpenMP project is enabled.
Copy link
Contributor

@jpeyton52 jpeyton52 left a comment

Choose a reason for hiding this comment

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

Everything looks OK to me.

…tion

Conflicts:
	flang/test/lit.cfg.py
	flang/test/lit.site.cfg.py.in
@mjklemm mjklemm merged commit fb5fd2d into llvm:main Mar 20, 2024
4 checks passed
@mjklemm mjklemm deleted the fix_omp_lib_compilation branch March 20, 2024 12:47
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
…lude` sources (llvm#80874)

This PR changes the build system to use use the sources for the module
`omp_lib` and the `omp_lib.h` include file from the `openmp` runtime
project and not from a separate copy of these files. This will greatly
reduce potential for inconsistencies when adding features to the OpenMP
runtime implementation.

When the OpenMP subproject is not configured, this PR also disables the
corresponding LIT tests with a "REQUIRES" directive at the beginning of
the OpenMP test files.

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval@gmail.com>
luporl added a commit to llvm/llvm-zorg that referenced this pull request Mar 26, 2024
As discussed in Discourse and proposed in
llvm/llvm-project#80874, Flang will start
to use C/C++ header files and Fortran modules from OpenMP runtime.

When the mentioned PR lands, all of Flang's OpenMP tests will be
skipped as unsupported, unless the OpenMP project is enabled.
@luporl
Copy link
Contributor

luporl commented Apr 3, 2024

I meant "necessary", but @mjklemm would need to confirm that I understood that correctly.

Yes, that's correct. When building the OpenMP runtime via LLVM_ENABLE_RUNTIMES, it seems that the .mod is not being produced. I'd like to get this into this PR to make sure that it does not break these build types.

Hi @mjklemm, are you planning to work on supporting OpenMP runtime when built via LLVM_ENABLE_RUNTIMES in the near future? If not, I can try to implement it.

This would make things easier for the buildbots, that build OpenMP via LLVM_ENABLE_RUNTIMES by default and that also don't specify the projects directly with LLVM_ENABLE_PROJECTS. I've just noticed it now, after enabling OpenMP on some Flang bots with llvm/llvm-zorg#137, that many Flang OpenMP tests are still being skipped.

@mjklemm
Copy link
Contributor Author

mjklemm commented Apr 3, 2024

It is supported. You can build the OpenMP runtime either way.

@mjklemm
Copy link
Contributor Author

mjklemm commented Apr 3, 2024

The .mod file should be produced. It just ends up in a different place than when building the OpenMP runtime as a project.

It should be in runtimes/runtimes-bins/openmp/src, IIRC.

@luporl
Copy link
Contributor

luporl commented Apr 3, 2024

The .mod file was produced, but it seems it wasn't found by Flang:

-- Not building omp_lib.mod, no OpenMP runtime in LLVM_ENABLED_PROJECTS
-- Not copying omp_lib.h, no OpenMP runtime in LLVM_ENABLED_PROJECTS

Also, in https://lab.llvm.org/buildbot/#/builders/173/builds/30842 it can be seen that many OpenMP tests are being skipped. They were running before this patch landed.
It seems LLVM_TOOL_OPENMP_BUILD is only set when openmp is in LLVM_ENABLED_PROJECTS.

@mjklemm
Copy link
Contributor Author

mjklemm commented Apr 3, 2024

These messages are a bit misleading. There should be another one that confirms that the .mod was built via the runtime build settings.

We can check if we can enable the LIT tests again, but that means that we'd have to supply the proper build flag pointing to where the .mod file lives.

A problem also is that when building a project, LLVM sets LLVM_TOOL for the project, but it does not for when building that thing as a runtime. This in turn means, there's no easy way to determine if the OpenMP runtime was built at all.

That's not ideal at this point, but I will continue looking at this and trying to improve the situation and eventually get to a state where the tests are back on.

@luporl
Copy link
Contributor

luporl commented Apr 3, 2024

Ok, thanks. Indeed there is another message mentioning the build of the .mod files.

-- Configuring build of omp_lib.mod and omp_lib_kinds.mod via flang-new

@mjklemm
Copy link
Contributor Author

mjklemm commented Apr 3, 2024

I guess I should file a PR to improve the messages a bit. I tried to be brief. Too brief, I guess. 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category openmp:libomp OpenMP host runtime waiting-for-response
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants