Skip to content

Commit 830ef4e

Browse files
authored
[openmp][NFCI] Move .mod code out of runtimes subdir (#169909)
Extracted out of #169638. The motivation is that we want to build Fortran module files for device triples (amdgpu-amd-amdhsa and nvptx64-nvidia-cuda) as well, but the runtimes/ directory is only included for host devices. This PR itself should not change anything, including that omp_lib.mod is only built on host devices triple. Some dependencies used for building omp_lib.mod are hoisted out of runtimes/ as well. IMHO they all make sense to hoist, e.g. LIBOMP_VERSION_MAJOR/LIBOMP_VERSION_MINOR should be usable in the entire OpenMP subproject.
1 parent af27159 commit 830ef4e

File tree

11 files changed

+106
-86
lines changed

11 files changed

+106
-86
lines changed

openmp/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
66
# Add path for custom modules
77
list(INSERT CMAKE_MODULE_PATH 0
88
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
9+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
910
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
1011
)
1112

@@ -95,6 +96,25 @@ endif()
9596
# Check and set up common compiler flags.
9697
include(config-ix)
9798
include(HandleOpenMPOptions)
99+
include(LibompUtils)
100+
include(LibompHandleFlags)
101+
102+
103+
# Set libomp version
104+
set(LIBOMP_VERSION_MAJOR 5)
105+
set(LIBOMP_VERSION_MINOR 0)
106+
107+
# Set the OpenMP Year and Month associated with version
108+
set(LIBOMP_OMP_YEAR_MONTH 201611)
109+
110+
# Get the build number from kmp_version.cpp
111+
libomp_get_build_number("${CMAKE_CURRENT_SOURCE_DIR}/runtime" LIBOMP_VERSION_BUILD)
112+
math(EXPR LIBOMP_VERSION_BUILD_YEAR "${LIBOMP_VERSION_BUILD}/10000")
113+
math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
114+
115+
# Currently don't record any timestamps
116+
set(LIBOMP_BUILD_DATE "No_Timestamp")
117+
98118

99119
# Check for flang
100120
set(OPENMP_TEST_Fortran_COMPILER_default "")
@@ -104,6 +124,9 @@ endif ()
104124
set(OPENMP_TEST_Fortran_COMPILER "${OPENMP_TEST_Fortran_COMPILER_default}" CACHE STRING
105125
"Fortran compiler to use for testing OpenMP runtime libraries.")
106126

127+
set(LIBOMP_FORTRAN_MODULES FALSE CACHE BOOL
128+
"Create Fortran module files? (requires fortran compiler)")
129+
107130
# Set up testing infrastructure.
108131
include(OpenMPTesting)
109132

@@ -139,6 +162,8 @@ if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx" OR
139162
"${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn|^nvptx")
140163
add_subdirectory(device)
141164
else()
165+
add_subdirectory(module)
166+
142167
# Build host runtime library, after LIBOMPTARGET variables are set since they
143168
# are needed to enable time profiling support in the OpenMP runtime.
144169
add_subdirectory(runtime)
File renamed without changes.

openmp/module/CMakeLists.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#//===----------------------------------------------------------------------===//
2+
#//
3+
#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
#// See https://llvm.org/LICENSE.txt for license information.
5+
#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#//
7+
#//===----------------------------------------------------------------------===//
8+
9+
include(LibompCheckFortranFlag)
10+
11+
set(LIBOMP_FFLAGS "" CACHE STRING
12+
"Appended user specified Fortran compiler flags. These are only used if LIBOMP_FORTRAN_MODULES==TRUE.")
13+
14+
# Enabling Fortran if it is needed
15+
if (LIBOMP_FORTRAN_MODULES)
16+
enable_language(Fortran)
17+
18+
libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
19+
endif ()
20+
21+
# Building the Fortran module files
22+
# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
23+
configure_file(omp_lib.F90.var omp_lib.F90 @ONLY)
24+
configure_file(omp_lib.h.var "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.h" @ONLY)
25+
26+
set(BUILD_FORTRAN_MODULES False)
27+
if (LIBOMP_FORTRAN_MODULES_COMPILER)
28+
# If libomp is built as an LLVM runtime and the flang compiler is available,
29+
# compile the Fortran module files.
30+
message(STATUS "configuring openmp to build Fortran module files using '${LIBOMP_FORTRAN_MODULES_COMPILER}'")
31+
set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
32+
add_custom_target(libomp-mod ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod")
33+
add_custom_command(
34+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
35+
COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE} "-J${CMAKE_CURRENT_BINARY_DIR}/../runtime/src"
36+
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}"
37+
)
38+
set(BUILD_FORTRAN_MODULES True)
39+
elseif (LIBOMP_FORTRAN_MODULES)
40+
# The following requests explicit building of the Fortran module files
41+
# Workaround for gfortran to build modules with the
42+
# omp_sched_monotonic integer parameter
43+
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
44+
set(ADDITIONAL_Fortran_FLAGS "-fno-range-check")
45+
endif ()
46+
add_custom_target(libomp-mod ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod")
47+
set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Misc")
48+
libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)
49+
if (CMAKE_Fortran_COMPILER_SUPPORTS_F90)
50+
set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
51+
else ()
52+
message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")
53+
endif ()
54+
add_custom_command(
55+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
56+
COMMAND ${CMAKE_Fortran_COMPILER} -c ${ADDITIONAL_Fortran_FLAGS}
57+
${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE} "-J${CMAKE_CURRENT_BINARY_DIR}/../runtime/src"
58+
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}"
59+
)
60+
set_property(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src" PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "omp_lib${CMAKE_C_OUTPUT_EXTENSION}")
61+
set(BUILD_FORTRAN_MODULES True)
62+
endif ()
63+
64+
65+
if (BUILD_FORTRAN_MODULES)
66+
set(destination "${LIBOMP_HEADERS_INSTALL_PATH}")
67+
if (LIBOMP_MODULES_INSTALL_PATH)
68+
set(destination "${LIBOMP_MODULES_INSTALL_PATH}")
69+
endif ()
70+
install(FILES
71+
"${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod"
72+
"${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
73+
"${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.h"
74+
DESTINATION ${destination}
75+
)
76+
endif ()
File renamed without changes.
File renamed without changes.

openmp/runtime/CMakeLists.txt

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ endif()
1515
# Add cmake directory to search for custom cmake functions
1616
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
1717

18-
# Set libomp version
19-
set(LIBOMP_VERSION_MAJOR 5)
20-
set(LIBOMP_VERSION_MINOR 0)
21-
2218
# These include files are in the cmake/ subdirectory
23-
include(LibompUtils)
2419
include(LibompGetArchitecture)
25-
include(LibompHandleFlags)
2620
include(LibompDefinitions)
2721

2822
# Determine the target architecture
@@ -102,15 +96,12 @@ libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc ppc64 ppc64le aarch
10296
set(LIBOMP_LIB_TYPE normal CACHE STRING
10397
"Performance,Profiling,Stubs library (normal/profile/stubs)")
10498
libomp_check_variable(LIBOMP_LIB_TYPE normal profile stubs)
105-
# Set the OpenMP Year and Month associated with version
106-
set(LIBOMP_OMP_YEAR_MONTH 201611)
10799
set(LIBOMP_MIC_ARCH knc CACHE STRING
108100
"Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) (knf/knc). Ignored if not Intel(R) MIC Architecture build.")
109101
if("${LIBOMP_ARCH}" STREQUAL "mic")
110102
libomp_check_variable(LIBOMP_MIC_ARCH knf knc)
111103
endif()
112-
set(LIBOMP_FORTRAN_MODULES FALSE CACHE BOOL
113-
"Create Fortran module files? (requires fortran compiler)")
104+
114105

115106
# - Support for universal fat binary builds on Mac
116107
# - Having this extra variable allows people to build this library as a universal library
@@ -147,8 +138,6 @@ else()
147138
set(LIBOMP_LIBFLAGS "" CACHE STRING
148139
"Appended user specified linked libs flags. (e.g., -lm)")
149140
endif()
150-
set(LIBOMP_FFLAGS "" CACHE STRING
151-
"Appended user specified Fortran compiler flags. These are only used if LIBOMP_FORTRAN_MODULES==TRUE.")
152141

153142
# Should the libomp library and generated headers be copied into the original source exports/ directory
154143
# Turning this to FALSE aids parallel builds to not interfere with each other.
@@ -163,14 +152,6 @@ set(LIBOMP_USE_HWLOC FALSE CACHE BOOL
163152
set(LIBOMP_HWLOC_INSTALL_DIR /usr/local CACHE PATH
164153
"Install path for hwloc library")
165154

166-
# Get the build number from kmp_version.cpp
167-
libomp_get_build_number("${CMAKE_CURRENT_SOURCE_DIR}" LIBOMP_VERSION_BUILD)
168-
math(EXPR LIBOMP_VERSION_BUILD_YEAR "${LIBOMP_VERSION_BUILD}/10000")
169-
math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
170-
171-
# Currently don't record any timestamps
172-
set(LIBOMP_BUILD_DATE "No_Timestamp")
173-
174155
# Architecture
175156
set(IA32 FALSE)
176157
set(INTEL64 FALSE)
@@ -272,10 +253,6 @@ set(LIBOMP_TOOLS_DIR ${LIBOMP_BASE_DIR}/tools)
272253
set(LIBOMP_INC_DIR ${LIBOMP_SRC_DIR}/include)
273254
set(LIBOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
274255

275-
# Enabling Fortran if it is needed
276-
if(${LIBOMP_FORTRAN_MODULES})
277-
enable_language(Fortran)
278-
endif()
279256
# Enable MASM Compiler if it is needed (Windows only)
280257
if(WIN32)
281258
enable_language(ASM_MASM)

openmp/runtime/cmake/LibompExports.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ if(${LIBOMP_OMPT_SUPPORT})
6565
)
6666
endif()
6767
if(${LIBOMP_FORTRAN_MODULES})
68-
add_custom_command(TARGET libomp-mod POST_BUILD
68+
# We cannot attach a POST_BUILD command to libomp-mod, so instead attach it
69+
# to omp and ensure that libomp-mod is built before by adding a dependency
70+
add_custom_command(TARGET omp POST_BUILD
6971
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_MOD_DIR}
7072
COMMAND ${CMAKE_COMMAND} -E copy omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR}
7173
COMMAND ${CMAKE_COMMAND} -E copy omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR}
7274
)
75+
add_dependencies(omp libomp-mod)
7376
add_custom_command(TARGET omp POST_BUILD
7477
COMMAND ${CMAKE_COMMAND} -E copy omp_lib.h ${LIBOMP_EXPORTS_CMN_DIR}
7578
)

openmp/runtime/cmake/config-ix.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ include(CheckIncludeFile)
1616
include(CheckLibraryExists)
1717
include(CheckIncludeFiles)
1818
include(CheckSymbolExists)
19-
include(LibompCheckFortranFlag)
2019
include(LLVMCheckCompilerLinkerFlag)
2120

2221
# Check for versioned symbols
@@ -97,9 +96,6 @@ if(WIN32)
9796
endforeach()
9897
endforeach()
9998
endif()
100-
if(${LIBOMP_FORTRAN_MODULES})
101-
libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
102-
endif()
10399

104100
# Check non-posix pthread API here before CMAKE_REQUIRED_DEFINITIONS gets messed up
105101
check_symbol_exists(pthread_setname_np "pthread.h" LIBOMP_HAVE_PTHREAD_SETNAME_NP)

0 commit comments

Comments
 (0)