Skip to content

Commit 7732534

Browse files
committed
Build omp_lib.mod on device
1 parent 109050c commit 7732534

File tree

11 files changed

+144
-89
lines changed

11 files changed

+144
-89
lines changed

flang-rt/CMakeLists.txt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ include(CMakePushCheckState)
4343
############################
4444

4545
# Path to LLVM development tools (FileCheck, llvm-lit, not, ...)
46-
set(LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}")
46+
set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin")
4747

4848
# Fortran compiler not optional for building Flang-RT
4949
enable_language(Fortran)
@@ -113,14 +113,8 @@ elseif (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
113113
option(FLANG_RT_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS "Do not compile global variables' definitions when producing PTX library" OFF)
114114
elseif (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP")
115115
# Support for OpenMP offloading
116-
else ()
117-
message(FATAL_ERROR "Invalid value '${FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT}' for FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT; must be empty, 'CUDA', or 'OpenMP'")
118-
endif ()
119-
120-
121-
if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP" OR LLVM_TARGET_TRIPLE MATCHES "^nvptx")
122-
set(FLANG_RT_DEVICE_ARCHITECTURES "all" CACHE STRING
123-
"List of offload device architectures to be used to compile the Fortran runtime (e.g. 'gfx1103;sm_90')"
116+
set(FLANG_RT_DEVICE_ARCHITECTURES "${RUNTIMES_DEVICE_ARCHITECTURES}" CACHE STRING
117+
"List of OpenMP device architectures to be used to compile the Fortran runtime (e.g. 'gfx1103;sm_90')"
124118
)
125119

126120
if (FLANG_RT_DEVICE_ARCHITECTURES STREQUAL "all")
@@ -139,6 +133,8 @@ if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP" OR LLVM_TARGET_TRIPL
139133
set(FLANG_RT_DEVICE_ARCHITECTURES ${all_gpu_architectures})
140134
endif()
141135
list(REMOVE_DUPLICATES FLANG_RT_DEVICE_ARCHITECTURES)
136+
else ()
137+
message(FATAL_ERROR "Invalid value '${FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT}' for FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT; must be empty, 'CUDA', or 'OpenMP'")
142138
endif ()
143139

144140

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,11 @@ function (add_flangrt_library name)
234234
target_compile_features(${tgtname} PRIVATE cxx_std_17)
235235

236236
target_compile_options(${tgtname} PRIVATE
237-
# Always enable preprocessor regardless of file extention
237+
# Always enable preprocessor regardless of file extension
238238
"$<$<COMPILE_LANGUAGE:Fortran>:-cpp>"
239239

240-
# Missing type descriptors are expected for intrinsic modules
240+
# Missing type descriptors are expected for intrinsic modules
241241
"$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-mmlir;SHELL:-ignore-missing-type-desc>"
242-
243-
# Flang bug workaround: Reformating of cooked token buffer causes identifier to be split between lines
244-
"$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-Xflang;SHELL:-fno-reformat>"
245242
)
246243

247244
# When building the flang runtime if LTO is enabled the archive file
@@ -300,11 +297,6 @@ function (add_flangrt_library name)
300297
target_compile_options(${tgtname} PRIVATE
301298
$<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden -Wno-unknown-cuda-version --cuda-feature=+ptx63>
302299
)
303-
foreach (_arch IN LISTS FLANG_RT_DEVICE_ARCHITECTURES)
304-
target_compile_options(${tgtname} PRIVATE
305-
-march=${_arch}
306-
)
307-
endforeach()
308300
elseif (APPLE)
309301
# Clang on Darwin enables non-POSIX extensions by default.
310302
# This causes some macros to leak, such as HUGE from <math.h>, which

flang-rt/cmake/modules/AddFlangRTOffload.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ macro(enable_omp_offload_compilation name files)
106106
PROPERTIES COMPILE_DEFINITIONS OMP_OFFLOAD_BUILD
107107
)
108108

109-
# If building flang-rt together with libomp, ensure that libomp is built first and found because -fopenmp will try to link it.
109+
# If building flang-rt together with libomp, ensure that libomp is built
110+
# first and found because -fopenmp will try to link it.
110111
if (TARGET omp)
111112
add_dependencies(${name} omp)
112113
target_link_options(${name}.static PUBLIC "-L$<TARGET_FILE_DIR:omp>")

openmp/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ endif()
9595
# Check and set up common compiler flags.
9696
include(config-ix)
9797
include(HandleOpenMPOptions)
98+
include(LibompUtils)
99+
100+
101+
# Set libomp version
102+
set(LIBOMP_VERSION_MAJOR 5)
103+
set(LIBOMP_VERSION_MINOR 0)
104+
105+
# Set the OpenMP Year and Month associated with version
106+
set(LIBOMP_OMP_YEAR_MONTH 201611)
107+
108+
# Get the build number from kmp_version.cpp
109+
libomp_get_build_number("${CMAKE_CURRENT_SOURCE_DIR}/runtime" LIBOMP_VERSION_BUILD)
110+
math(EXPR LIBOMP_VERSION_BUILD_YEAR "${LIBOMP_VERSION_BUILD}/10000")
111+
math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
112+
113+
# Currently don't record any timestamps
114+
set(LIBOMP_BUILD_DATE "No_Timestamp")
115+
98116

99117
# Check for flang
100118
set(OPENMP_TEST_Fortran_COMPILER_default "")
@@ -104,6 +122,13 @@ endif ()
104122
set(OPENMP_TEST_Fortran_COMPILER "${OPENMP_TEST_Fortran_COMPILER_default}" CACHE STRING
105123
"Fortran compiler to use for testing OpenMP runtime libraries.")
106124

125+
if (LLVM_RUNTIMES_BUILD)
126+
set(LIBOMP_FORTRAN_MODULES "${RUNTIMES_FLANG_MODULES_ENABLED}" CACHE BOOL
127+
"Create Fortran module files? (requires fortran compiler)")
128+
else ()
129+
set(LIBOMP_FORTRAN_MODULES OFF)
130+
endif ()
131+
107132
# Set up testing infrastructure.
108133
include(OpenMPTesting)
109134

@@ -136,6 +161,10 @@ else()
136161
get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
137162
endif()
138163

164+
if(LIBOMP_FORTRAN_MODULES)
165+
add_subdirectory(module)
166+
endif()
167+
139168
# Use the current compiler target to determine the appropriate runtime to build.
140169
if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx" OR
141170
"${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn|^nvptx")
File renamed without changes.

openmp/module/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
# Build the module files if a Fortran compiler is available.
10+
# Only LLVM_ENABLE_RUNTIMES=openmp is supported, LLVM_ENABLE_PROJECTS=openmp
11+
# has been deprecated.
12+
13+
configure_file(omp_lib.F90.var "{CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90" @ONLY)
14+
15+
# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod. Only
16+
# these files are used, the object file itself can be discarded.
17+
# FIXME: Adding it to libomp.so would allow implementing Fortran API in Fortran
18+
add_library(libomp-mod OBJECT
19+
"{CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
20+
)
21+
set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Fortran Modules")
22+
23+
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
24+
target_compile_options(libomp-mod PRIVATE -fno-range-check)
25+
endif()
26+
27+
flang_module_target(libomp-mod PUBLIC)
28+
if (FORTRAN_MODULE_DEPS)
29+
add_dependencies(libomp-mod ${FORTRAN_MODULE_DEPS})
30+
endif ()
File renamed without changes.

openmp/runtime/CMakeLists.txt

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ 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
2319
include(LibompUtils)
2420
include(LibompGetArchitecture)
@@ -102,21 +98,12 @@ libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc ppc64 ppc64le aarch
10298
set(LIBOMP_LIB_TYPE normal CACHE STRING
10399
"Performance,Profiling,Stubs library (normal/profile/stubs)")
104100
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)
107101
set(LIBOMP_MIC_ARCH knc CACHE STRING
108102
"Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) (knf/knc). Ignored if not Intel(R) MIC Architecture build.")
109103
if("${LIBOMP_ARCH}" STREQUAL "mic")
110104
libomp_check_variable(LIBOMP_MIC_ARCH knf knc)
111105
endif()
112106

113-
if (LLVM_RUNTIMES_BUILD)
114-
set(LIBOMP_FORTRAN_MODULES "${RUNTIMES_FLANG_MODULES_ENABLED}" CACHE BOOL
115-
"Create Fortran module files? (requires fortran compiler)")
116-
else ()
117-
set(LIBOMP_FORTRAN_MODULES OFF)
118-
endif ()
119-
120107

121108
# - Support for universal fat binary builds on Mac
122109
# - Having this extra variable allows people to build this library as a universal library
@@ -167,14 +154,6 @@ set(LIBOMP_USE_HWLOC FALSE CACHE BOOL
167154
set(LIBOMP_HWLOC_INSTALL_DIR /usr/local CACHE PATH
168155
"Install path for hwloc library")
169156

170-
# Get the build number from kmp_version.cpp
171-
libomp_get_build_number("${CMAKE_CURRENT_SOURCE_DIR}" LIBOMP_VERSION_BUILD)
172-
math(EXPR LIBOMP_VERSION_BUILD_YEAR "${LIBOMP_VERSION_BUILD}/10000")
173-
math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
174-
175-
# Currently don't record any timestamps
176-
set(LIBOMP_BUILD_DATE "No_Timestamp")
177-
178157
# Architecture
179158
set(IA32 FALSE)
180159
set(INTEL64 FALSE)
@@ -477,3 +456,5 @@ set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE)
477456
# make these variables available for tools/libompd:
478457
set(LIBOMP_SRC_DIR ${LIBOMP_SRC_DIR} PARENT_SCOPE)
479458
set(LIBOMP_OMPD_SUPPORT ${LIBOMP_OMPD_SUPPORT} PARENT_SCOPE)
459+
460+

openmp/runtime/cmake/LibompExports.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +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 befoe 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 ${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR}
7173
COMMAND ${CMAKE_COMMAND} -E copy ${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR}
7274
)
73-
75+
add_dependencies(omp libomp-mod)
7476
add_custom_command(TARGET omp POST_BUILD
7577
COMMAND ${CMAKE_COMMAND} -E copy omp_lib.h ${LIBOMP_EXPORTS_CMN_DIR}
7678
)

openmp/runtime/src/CMakeLists.txt

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ if(WIN32)
377377
endif()
378378
endif()
379379

380+
configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
381+
382+
# Move files to exports/ directory if requested
383+
if(${LIBOMP_COPY_EXPORTS})
384+
include(LibompExports)
385+
endif()
386+
380387
# Micro test rules for after library has been built (cmake/LibompMicroTests.cmake)
381388
include(LibompMicroTests)
382389
add_custom_target(libomp-micro-tests)
@@ -452,35 +459,7 @@ if(${LIBOMP_OMPT_SUPPORT})
452459
install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} RENAME ompt.h)
453460
set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
454461
endif()
455-
456-
457-
# Build the module files if a Fortran compiler is available.
458-
# Only LLVM_ENABLE_RUNTIMES=openmp is supported, LLVM_ENABLE_PROJECTS=openmp
459-
# has been deprecated.
460-
# TODO: openmp/runtimes/CMakeLists.txt is only included for host
461-
# (non-amdgpu/nvptx) targets, but device side code needs a module as well.
462462
if(LIBOMP_FORTRAN_MODULES)
463-
configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
464-
configure_file(${LIBOMP_INC_DIR}/omp_lib.F90.var omp_lib.F90 @ONLY)
465-
466-
# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod. Only
467-
# these files are used, the library itself can be discarded. Cannot use an
468-
# OBJECT library to avoid creating the library because LibompExports.cmake
469-
# attaches a POST_BUILD command to libomp-mod.
470-
add_library(libomp-mod STATIC
471-
omp_lib.F90
472-
)
473-
set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Fortran Modules")
474-
475-
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
476-
target_compile_options(libomp-mod PRIVATE -fno-range-check)
477-
endif()
478-
479-
flang_module_target(libomp-mod PUBLIC)
480-
if (FORTRAN_MODULE_DEPS)
481-
add_dependencies(libomp-mod ${FORTRAN_MODULE_DEPS})
482-
endif ()
483-
484463
set (destination ${LIBOMP_HEADERS_INSTALL_PATH})
485464
if (NOT ${LIBOMP_MODULES_INSTALL_PATH} STREQUAL "")
486465
set (destination ${LIBOMP_MODULES_INSTALL_PATH})
@@ -490,8 +469,3 @@ if(LIBOMP_FORTRAN_MODULES)
490469
DESTINATION ${destination}
491470
)
492471
endif()
493-
494-
# Move files to exports/ directory if requested
495-
if(LIBOMP_COPY_EXPORTS)
496-
include(LibompExports)
497-
endif()

0 commit comments

Comments
 (0)