Skip to content

[openmp] Deprecate LLVM_ENABLE_PROJECTS in favor of LLVM_ENABLE_RUNTIMES #124711

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

petrhosek
Copy link
Member

We plan to make this a hard error in the LLVM 21 release.

Link #124014

We plan to make this a hard error in the LLVM 21 release.

Link llvm#124014
@petrhosek petrhosek added cmake Build system in general and CMake in particular openmp labels Jan 28, 2025
@petrhosek petrhosek requested a review from ye-luo January 28, 2025 07:06
@llvmbot
Copy link
Member

llvmbot commented Jan 28, 2025

@llvm/pr-subscribers-openmp

Author: Petr Hosek (petrhosek)

Changes

We plan to make this a hard error in the LLVM 21 release.

Link #124014


Full diff: https://github.com/llvm/llvm-project/pull/124711.diff

1 Files Affected:

  • (modified) llvm/CMakeLists.txt (+7)
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index c9ff3696e22d69..4cb4e90fa5c7e8 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -164,6 +164,13 @@ if ("compiler-rt" IN_LIST LLVM_ENABLE_PROJECTS)
     "https://compiler-rt.llvm.org/ for building the runtimes.")
 endif()
 
+if ("openmp" IN_LIST LLVM_ENABLE_PROJECTS)
+  message(WARNING "Using LLVM_ENABLE_PROJECTS=openmp is deprecated now, and will "
+    "become a fatal error in the LLVM 21 release.  Please use "
+    "-DLLVM_ENABLE_RUNTIMES=openmp or see the instructions at "
+    "https://openmp.llvm.org/ for building the runtimes.")
+endif()
+
 # Select the runtimes to build
 #
 # As we migrate runtimes to using the bootstrapping build, the set of default runtimes

@Meinersbur
Copy link
Member

Flang currently only works with LLVM_ENABLE_PROJECTS=openmp:

if (LLVM_TOOL_OPENMP_BUILD)
message(STATUS "OpenMP runtime support enabled via LLVM_ENABLED_PROJECTS, building omp_lib.mod")
set(base ${FLANG_INTRINSIC_MODULES_DIR}/omp_lib)
add_custom_command(OUTPUT ${base}.mod ${base}_kinds.mod
COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
COMMAND flang -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90
DEPENDS flang ${FLANG_INTRINSIC_MODULES_DIR}/iso_c_binding.mod ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90 ${depends}
)
add_custom_command(OUTPUT ${base}.f18.mod
DEPENDS ${base}.mod
COMMAND ${CMAKE_COMMAND} -E copy ${base}.mod ${base}.f18.mod)
add_custom_command(OUTPUT ${base}_kinds.f18.mod
DEPENDS ${base}.mod
COMMAND ${CMAKE_COMMAND} -E copy ${base}_kinds.mod ${base}_kinds.f18.mod)
list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod)
install(FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
else()
message(STATUS "Not building omp_lib.mod, no OpenMP runtime in LLVM_ENABLED_PROJECTS")
endif()
endif()

Cannot remove it before Flang also supports LLVM_ENABLE_RUNTIMES=openmp

@jplehr
Copy link
Contributor

jplehr commented Jan 28, 2025

Thank you for putting this up. I think I understand the motivation, however, from the issue you linked, I do not get the sense of urgent and strong support of this direction right now. I also wondered who "we" refers to.

I think this should be discussed a bit more, and I do not see the need to put us on this tight timeline right away.

@jhuber6
Copy link
Contributor

jhuber6 commented Jan 28, 2025

Flang currently only works with LLVM_ENABLE_PROJECTS=openmp:

if (LLVM_TOOL_OPENMP_BUILD)
message(STATUS "OpenMP runtime support enabled via LLVM_ENABLED_PROJECTS, building omp_lib.mod")
set(base ${FLANG_INTRINSIC_MODULES_DIR}/omp_lib)
add_custom_command(OUTPUT ${base}.mod ${base}_kinds.mod
COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
COMMAND flang -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90
DEPENDS flang ${FLANG_INTRINSIC_MODULES_DIR}/iso_c_binding.mod ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90 ${depends}
)
add_custom_command(OUTPUT ${base}.f18.mod
DEPENDS ${base}.mod
COMMAND ${CMAKE_COMMAND} -E copy ${base}.mod ${base}.f18.mod)
add_custom_command(OUTPUT ${base}_kinds.f18.mod
DEPENDS ${base}.mod
COMMAND ${CMAKE_COMMAND} -E copy ${base}_kinds.mod ${base}_kinds.f18.mod)
list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod)
install(FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
else()
message(STATUS "Not building omp_lib.mod, no OpenMP runtime in LLVM_ENABLED_PROJECTS")
endif()
endif()

Cannot remove it before Flang also supports LLVM_ENABLE_RUNTIMES=openmp

Why does flang depend on OpenMP? It's not like clang does. If it's the runtime, hopefully we'll have that resolved with your patches since runtime builds can depend on other runtimes.

@jplehr
Copy link
Contributor

jplehr commented Jan 28, 2025

Flang currently only works with LLVM_ENABLE_PROJECTS=openmp:

if (LLVM_TOOL_OPENMP_BUILD)
message(STATUS "OpenMP runtime support enabled via LLVM_ENABLED_PROJECTS, building omp_lib.mod")
set(base ${FLANG_INTRINSIC_MODULES_DIR}/omp_lib)
add_custom_command(OUTPUT ${base}.mod ${base}_kinds.mod
COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
COMMAND flang -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90
DEPENDS flang ${FLANG_INTRINSIC_MODULES_DIR}/iso_c_binding.mod ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90 ${depends}
)
add_custom_command(OUTPUT ${base}.f18.mod
DEPENDS ${base}.mod
COMMAND ${CMAKE_COMMAND} -E copy ${base}.mod ${base}.f18.mod)
add_custom_command(OUTPUT ${base}_kinds.f18.mod
DEPENDS ${base}.mod
COMMAND ${CMAKE_COMMAND} -E copy ${base}_kinds.mod ${base}_kinds.f18.mod)
list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod)
install(FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
else()
message(STATUS "Not building omp_lib.mod, no OpenMP runtime in LLVM_ENABLED_PROJECTS")
endif()
endif()

Cannot remove it before Flang also supports LLVM_ENABLE_RUNTIMES=openmp

Why does flang depend on OpenMP? It's not like clang does. If it's the runtime, hopefully we'll have that resolved with your patches since runtime builds can depend on other runtimes.

I believe this comes from Fortran module (.mod) files being compiler dependent. But they are also an integral part of the compiler. So, if flang wants to allow use omp_lib then it needs to have the OpenMP .mod file compiled. But it can/should/must (?) only do so when OpenMP is actually enabled.
I'm not saying that the way this is currently done is great, just trying to give a bit of context. @Meinersbur can likely correct me if I'm wrong.

@jhuber6
Copy link
Contributor

jhuber6 commented Jan 28, 2025

I believe this comes from Fortran module (.mod) files being compiler dependent. But they are also an integral part of the compiler. So, if flang wants to allow use omp_lib then it needs to have the OpenMP .mod file compiled. But it can/should/must (?) only do so when OpenMP is actually enabled. I'm not saying that the way this is currently done is great, just trying to give a bit of context. @Meinersbur can likely correct me if I'm wrong.

I figured it was just like clang which put those in the resource directory.

@Meinersbur
Copy link
Member

For Flang to support OpenMP, omp_lib.F90 must be compiled omp_lib.mod with the Flang that is going to use it, similar to the runtime library. Currently this is done within the Flang. omp_lib.F90 is generated by

configure_file(${LIBOMP_INC_DIR}/omp_lib.F90.var omp_lib.F90 @ONLY)

so Flang needs to know the location of the generated file.

I don't know where ideally the location for the build rules and omp_lib.F90.var would be. It could also be done in the libomp project when flang is detected, or maybe in flang-rt.

@ye-luo
Copy link
Contributor

ye-luo commented Jan 29, 2025

Flang currently only works with LLVM_ENABLE_PROJECTS=openmp:

I'm afraid this is not true in the first place. My nightly tests builds openmp as runtime and I'm using flang+openmp to test my applications.

@Meinersbur
Copy link
Member

Flang currently only works with LLVM_ENABLE_PROJECTS=openmp:

I'm afraid this is not true in the first place. My nightly tests builds openmp as runtime and I'm using flang+openmp to test my applications.

Where do you get omp_lib.mod from?

@ye-luo
Copy link
Contributor

ye-luo commented Jan 29, 2025

Flang currently only works with LLVM_ENABLE_PROJECTS=openmp:

I'm afraid this is not true in the first place. My nightly tests builds openmp as runtime and I'm using flang+openmp to test my applications.

Where do you get omp_lib.mod from?

from last night

yeluo@jlselogin7:/soft/compilers/llvm/main-20250129> find -name omp_lib.mod
./include/flang/omp_lib.mod

@Meinersbur
Copy link
Member

The line

${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90
is a direct reference to the build directory layout in an LLVM_ENABLE_PROJECTS=openmp configuration. I don't see how it could work with LLVM_ENABLE_RUNTIMES=openmp where it would be something like ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins/openmp/runtime/src/omp_lib.F90 (assuming LLVM_RUNTIME_TARGETS=default).

@Meinersbur
Copy link
Member

I have been overseeing something.

There is a second set of build instructions at
https://github.com/llvm/llvm-project/blob/main/openmp/runtime/src/CMakeLists.txt#L378-L383
Actually, there are three:
https://github.com/llvm/llvm-project/blob/main/openmp/runtime/src/CMakeLists.txt#L400-L406

However, they are emitted into ${CMAKE_CURRENT_BINARY_DIR} (which is runtimes/runtimes-bins/openmp/runtime/src) where flang does not find them by default, so the regression tests add another -J flag to the compiler invocation. ninja check-flang was still failing with all the OpenMP tests because add_dependence(check-flang runtimes) (or similar) is missing.

@Meinersbur
Copy link
Member

Adding the missing dependency in #130975. After that, I don't see any remaining issue for deprecating LLVM_ENABLE_PROJECTS=openmp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants