Skip to content

Commit 27539c3

Browse files
committed
Revert "[Flang] Remove FLANG_INCLUDE_RUNTIME (#124126)"
The production buildbot master apparently has not yet been restarted since llvm/llvm-zorg#393 landed. This reverts commit 96d1bae.
1 parent 545ea0d commit 27539c3

File tree

17 files changed

+902
-19
lines changed

17 files changed

+902
-19
lines changed

flang-rt/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,7 @@ can be any compiler supporting the same ABI.
9191
In addition to the compiler, the build must be able to find LLVM development
9292
tools such as `lit` and `FileCheck` that are not found in an LLVM's install
9393
directory. Use `CMAKE_BINARY_DIR` to point to directory where LLVM has
94-
been built. When building Flang as part of a bootstrapping build
95-
(`LLVM_ENABLE_PROJECTS=flang`), Flang-RT is automatically added
96-
unless configured with `-DFLANG_ENABLE_FLANG_RT=OFF`. Add that option to avoid
97-
having two conflicting versions of the same library.
98-
99-
A simple build configuration might look like the following:
94+
been built. A simple build configuration might look like the following:
10095

10196
```bash
10297
cmake -S <path-to-llvm-project-source>/runtimes \

flang/CMakeLists.txt

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ if (LLVM_ENABLE_EH)
2323
endif()
2424

2525
set(FLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
26+
set(FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang-rt")
2627

2728
# Python is needed for symbol extracting tool
2829
set(LLVM_MINIMUM_PYTHON_VERSION 3.8)
@@ -258,10 +259,24 @@ else()
258259
include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
259260
endif()
260261

261-
if (FLANG_STANDALONE_BUILD)
262-
message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, compile a standalone Flang-RT.")
263-
elseif (NOT "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
264-
message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, either set FLANG_ENABLE_FLANG_RT=ON, add LLVM_ENABLE_RUNTIMES=flang-rt, or compile a standalone Flang-RT.")
262+
set(FLANG_INCLUDE_RUNTIME_default ON)
263+
if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
264+
set(FLANG_INCLUDE_RUNTIME_default OFF)
265+
endif ()
266+
option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ${FLANG_INCLUDE_RUNTIME_default})
267+
if (FLANG_INCLUDE_RUNTIME)
268+
if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
269+
message(WARNING "Building Flang-RT using LLVM_ENABLE_RUNTIMES. FLANG_INCLUDE_RUNTIME=${FLANG_INCLUDE_RUNTIME} ignored.")
270+
set(FLANG_INCLUDE_RUNTIME OFF)
271+
else ()
272+
message(STATUS "Building Flang-RT in-tree")
273+
endif ()
274+
else ()
275+
if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
276+
message(STATUS "Building Flang-RT using LLVM_ENABLE_RUNTIMES")
277+
else ()
278+
message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, either add LLVM_ENABLE_RUNTIMES=flang-rt, or compile a standalone Flang-RT.")
279+
endif ()
265280
endif ()
266281

267282
set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
@@ -486,6 +501,12 @@ if (FLANG_INCLUDE_TESTS)
486501
add_compile_definitions(FLANG_INCLUDE_TESTS=1)
487502
endif()
488503

504+
option(FLANG_CUF_RUNTIME
505+
"Compile CUDA Fortran runtime sources" OFF)
506+
if (FLANG_CUF_RUNTIME)
507+
find_package(CUDAToolkit REQUIRED)
508+
endif()
509+
489510
add_subdirectory(include)
490511
add_subdirectory(lib)
491512
add_subdirectory(cmake/modules)
@@ -496,6 +517,10 @@ if (FLANG_BUILD_TOOLS)
496517
add_subdirectory(tools)
497518
endif()
498519

520+
if (FLANG_INCLUDE_RUNTIME)
521+
add_subdirectory(runtime)
522+
endif ()
523+
499524
if (LLVM_INCLUDE_EXAMPLES)
500525
add_subdirectory(examples)
501526
endif()
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
option(FLANG_EXPERIMENTAL_CUDA_RUNTIME
2+
"Compile Fortran runtime as CUDA sources (experimental)" OFF
3+
)
4+
5+
option(FLANG_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS
6+
"Do not compile global variables' definitions when producing PTX library" OFF
7+
)
8+
9+
set(FLANG_LIBCUDACXX_PATH "" CACHE PATH "Path to libcu++ package installation")
10+
11+
set(FLANG_EXPERIMENTAL_OMP_OFFLOAD_BUILD "off" CACHE STRING
12+
"Compile Fortran runtime as OpenMP target offload sources (experimental). Valid options are 'off', 'host_device', 'nohost'")
13+
14+
set(FLANG_OMP_DEVICE_ARCHITECTURES "all" CACHE STRING
15+
"List of OpenMP device architectures to be used to compile the Fortran runtime (e.g. 'gfx1103;sm_90')")
16+
17+
macro(enable_cuda_compilation name files)
18+
if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
19+
if (BUILD_SHARED_LIBS)
20+
message(FATAL_ERROR
21+
"BUILD_SHARED_LIBS is not supported for CUDA build of Fortran runtime"
22+
)
23+
endif()
24+
25+
enable_language(CUDA)
26+
27+
# TODO: figure out how to make target property CUDA_SEPARABLE_COMPILATION
28+
# work, and avoid setting CMAKE_CUDA_SEPARABLE_COMPILATION.
29+
set(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
30+
31+
# Treat all supported sources as CUDA files.
32+
set_source_files_properties(${files} PROPERTIES LANGUAGE CUDA)
33+
set(CUDA_COMPILE_OPTIONS)
34+
if ("${CMAKE_CUDA_COMPILER_ID}" MATCHES "Clang")
35+
# Allow varargs.
36+
set(CUDA_COMPILE_OPTIONS
37+
-Xclang -fcuda-allow-variadic-functions
38+
)
39+
endif()
40+
if ("${CMAKE_CUDA_COMPILER_ID}" MATCHES "NVIDIA")
41+
set(CUDA_COMPILE_OPTIONS
42+
--expt-relaxed-constexpr
43+
# Disable these warnings:
44+
# 'long double' is treated as 'double' in device code
45+
-Xcudafe --diag_suppress=20208
46+
-Xcudafe --display_error_number
47+
)
48+
endif()
49+
set_source_files_properties(${files} PROPERTIES COMPILE_OPTIONS
50+
"${CUDA_COMPILE_OPTIONS}"
51+
)
52+
53+
if (EXISTS "${FLANG_LIBCUDACXX_PATH}/include")
54+
# When using libcudacxx headers files, we have to use them
55+
# for all files of F18 runtime.
56+
include_directories(AFTER ${FLANG_LIBCUDACXX_PATH}/include)
57+
add_compile_definitions(RT_USE_LIBCUDACXX=1)
58+
endif()
59+
60+
# Add an OBJECT library consisting of CUDA PTX.
61+
llvm_add_library(${name}PTX OBJECT PARTIAL_SOURCES_INTENDED ${files})
62+
set_property(TARGET obj.${name}PTX PROPERTY CUDA_PTX_COMPILATION ON)
63+
if (FLANG_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS)
64+
target_compile_definitions(obj.${name}PTX
65+
PRIVATE FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
66+
)
67+
endif()
68+
endif()
69+
endmacro()
70+
71+
macro(enable_omp_offload_compilation files)
72+
if (NOT FLANG_EXPERIMENTAL_OMP_OFFLOAD_BUILD STREQUAL "off")
73+
# 'host_device' build only works with Clang compiler currently.
74+
# The build is done with the CMAKE_C/CXX_COMPILER, i.e. it does not use
75+
# the in-tree built Clang. We may have a mode that would use the in-tree
76+
# built Clang.
77+
#
78+
# 'nohost' is supposed to produce an LLVM Bitcode library,
79+
# and it has to be done with a C/C++ compiler producing LLVM Bitcode
80+
# compatible with the LLVM toolchain version distributed with the Flang
81+
# compiler.
82+
# In general, the in-tree built Clang should be used for 'nohost' build.
83+
# Note that 'nohost' build does not produce the host version of Flang
84+
# runtime library, so there will be two separate distributable objects.
85+
# 'nohost' build is a TODO.
86+
87+
if (NOT FLANG_EXPERIMENTAL_OMP_OFFLOAD_BUILD STREQUAL "host_device")
88+
message(FATAL_ERROR "Unsupported OpenMP offload build of Flang runtime")
89+
endif()
90+
if (BUILD_SHARED_LIBS)
91+
message(FATAL_ERROR
92+
"BUILD_SHARED_LIBS is not supported for OpenMP offload build of Fortran runtime"
93+
)
94+
endif()
95+
96+
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND
97+
"${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
98+
99+
set(all_amdgpu_architectures
100+
"gfx700;gfx701;gfx801;gfx803;gfx900;gfx902;gfx906"
101+
"gfx908;gfx90a;gfx90c;gfx942;gfx950;gfx1010;gfx1030"
102+
"gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036"
103+
"gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151"
104+
"gfx1152;gfx1153;gfx1200;gfx1201"
105+
)
106+
set(all_nvptx_architectures
107+
"sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62"
108+
"sm_70;sm_72;sm_75;sm_80;sm_86;sm_89;sm_90"
109+
)
110+
set(all_gpu_architectures
111+
"${all_amdgpu_architectures};${all_nvptx_architectures}"
112+
)
113+
# TODO: support auto detection on the build system.
114+
if (FLANG_OMP_DEVICE_ARCHITECTURES STREQUAL "all")
115+
set(FLANG_OMP_DEVICE_ARCHITECTURES ${all_gpu_architectures})
116+
endif()
117+
list(REMOVE_DUPLICATES FLANG_OMP_DEVICE_ARCHITECTURES)
118+
119+
string(REPLACE ";" "," compile_for_architectures
120+
"${FLANG_OMP_DEVICE_ARCHITECTURES}"
121+
)
122+
123+
set(OMP_COMPILE_OPTIONS
124+
-fopenmp
125+
-fvisibility=hidden
126+
-fopenmp-cuda-mode
127+
--offload-arch=${compile_for_architectures}
128+
# Force LTO for the device part.
129+
-foffload-lto
130+
)
131+
set_source_files_properties(${files} PROPERTIES COMPILE_OPTIONS
132+
"${OMP_COMPILE_OPTIONS}"
133+
)
134+
135+
# Enable "declare target" in the source code.
136+
set_source_files_properties(${files}
137+
PROPERTIES COMPILE_DEFINITIONS OMP_OFFLOAD_BUILD
138+
)
139+
else()
140+
message(FATAL_ERROR
141+
"Flang runtime build is not supported for these compilers:\n"
142+
"CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}\n"
143+
"CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}")
144+
endif()
145+
endif()
146+
endmacro()

flang/examples/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
if (FLANG_INCLUDE_RUNTIME)
2+
add_subdirectory(ExternalHelloWorld)
3+
endif ()
14
add_subdirectory(PrintFlangFunctionNames)
25
add_subdirectory(FlangOmpReport)
36
add_subdirectory(FeatureList)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This test is not run by default as it requires input.
2+
add_llvm_example(external-hello-world
3+
${FLANG_RT_SOURCE_DIR}/examples/ExternalHelloWorld/external-hello.cpp
4+
)
5+
6+
target_link_libraries(external-hello-world
7+
PRIVATE
8+
flang_rt.runtime
9+
)

0 commit comments

Comments
 (0)