Skip to content

Commit de28a32

Browse files
committed
Merge remote-tracking branch 'meinersbur/users/meinersbur/flang_runtime' into HEAD
2 parents 0eb5bdf + e267014 commit de28a32

File tree

16 files changed

+112
-72
lines changed

16 files changed

+112
-72
lines changed

flang-rt/CMakeLists.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,22 @@ if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSIO
7373
endif()
7474

7575
if (LLVM_TREE_AVAILABLE)
76+
# In a bootstrap build emit the libraries into a default search path in the
77+
# build directory of the just-built compiler. This allows using the
78+
# just-built compiler without specifying paths to runtime libraries.
79+
#
7680
# Despite Clang in the name, get_clang_resource_dir does not depend on Clang
7781
# being added to the build. Flang uses the same resource dir as clang.
7882
include(GetClangResourceDir)
7983
get_clang_resource_dir(FLANG_RT_BUILD_LIB_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/.." SUBDIR "lib${LLVM_LIBDIR_SUFFIX}")
8084
get_clang_resource_dir(FLANG_RT_INSTALL_LIB_DIR SUBDIR "lib${LLVM_LIBDIR_SUFFIX}") # No prefix, CMake's install command finds the install prefix itself
8185
else ()
82-
set(FLANG_RT_BUILD_LIB_DIR "${LLVM_LIBRARY_OUTPUT_INTDIR}")
86+
# In a runtimes build never write into LLVM's build dir. It might be reused
87+
# for mutliple Flang-RT builds (e.g. Debug/Release). Instead create our own
88+
# library directory.
89+
#
90+
# TODO: Support multi-config generators
91+
set(FLANG_RT_BUILD_LIB_DIR "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
8392
set(FLANG_RT_INSTALL_LIB_DIR "lib${LLVM_LIBDIR_SUFFIX}")
8493
endif ()
8594

@@ -102,19 +111,23 @@ endif ()
102111
option(FLANG_RT_INCLUDE_TESTS "Generate build targets for the flang-rt unit and regression-tests." "${LLVM_INCLUDE_TESTS}")
103112

104113

105-
set(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT "" CACHE STRING "Compile flang-rt with GPU support (CUDA or OpenMP)")
114+
set(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT "" CACHE STRING "Compile Flang-RT with GPU support (CUDA or OpenMP)")
106115
set_property(CACHE FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT PROPERTY STRINGS
107116
""
108117
CUDA
109118
OpenMP
110119
)
111120
if (NOT FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT)
121+
# Support for GPUs disabled
112122
elseif (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
123+
# Support for CUDA
113124
set(FLANG_RT_LIBCUDACXX_PATH "" CACHE PATH "Path to libcu++ package installation")
114125
option(FLANG_RT_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS "Do not compile global variables' definitions when producing PTX library" OFF)
115126
elseif (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP")
116-
set(FLANG_RT_DEVICE_ARCHITECTURES "all" CACHE STRING
117-
"List of OpenMP device architectures to be used to compile the Fortran runtime (e.g. 'gfx1103;sm_90')")
127+
# Support for OpenMP offloading
128+
set(FLANG_RT_DEVICE_ARCHITECTURES "all" CACHE STRING
129+
"List of OpenMP device architectures to be used to compile the Fortran runtime (e.g. 'gfx1103;sm_90')"
130+
)
118131
else ()
119132
message(FATAL_ERROR "Invalid value '${FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT}' for FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT; must be empty, 'CUDA', or 'OpenMP'")
120133
endif ()

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ function (add_flangrt_library name)
6565
set_target_properties(${name} PROPERTIES FOLDER "Fortran Runtime/Libraries")
6666
endif ()
6767

68+
# Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
6869
target_compile_features(${name} PRIVATE cxx_std_17)
70+
71+
# Use compiler-specific options to disable exceptions and RTTI.
6972
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
7073
target_compile_options(${name} PRIVATE
7174
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables>
@@ -74,6 +77,23 @@ function (add_flangrt_library name)
7477
target_compile_options(${name} PRIVATE
7578
$<$<COMPILE_LANGUAGE:CXX>:/EHs-c- /GR->
7679
)
80+
elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL")
81+
target_compile_options(${name} PRIVATE
82+
$<$<COMPILE_LANGUAGE:CXX>:-qnoeh -qnortti>
83+
)
84+
endif ()
85+
86+
# Also for CUDA source when compiling with FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA
87+
if (CMAKE_CUDA_COMPILER_ID MATCHES "NVIDIA")
88+
# Assuming gcc as host compiler.
89+
target_compile_options(${name} PRIVATE
90+
$<$<COMPILE_LANGUAGE:CUDA>:--no-exceptions -Xcompiler -fno-rtti -Xcompiler -fno-unwind-tables -Xcompiler -fno-asynchronous-unwind-tables>
91+
)
92+
else ()
93+
# Assuming a clang-compatible CUDA compiler.
94+
target_compile_options(${name} PRIVATE
95+
$<$<COMPILE_LANGUAGE:CUDA>:-fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables>
96+
)
7797
endif ()
7898

7999
# Flang-rt's public headers

flang-rt/cmake/modules/AddFlangRTOffload.cmake

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,27 @@ macro(enable_cuda_compilation name files)
4242
"${CUDA_COMPILE_OPTIONS}"
4343
)
4444

45-
if (EXISTS "${FLANG_RT_LIBCUDACXX_PATH}/include")
46-
# When using libcudacxx headers files, we have to use them
47-
# for all files of F18 runtime.
48-
include_directories(AFTER ${FLANG_RT_LIBCUDACXX_PATH}/include)
49-
add_compile_definitions(RT_USE_LIBCUDACXX=1)
50-
endif()
45+
# Create a .a library consisting of CUDA PTX.
46+
# This is different from a regular static library. The CUDA_PTX_COMPILATION
47+
# property can only be applied to object libraries and create *.ptx files
48+
# instead of *.o files. The .a will consist of those *.ptx files only.
49+
add_flangrt_library(obj.${name}PTX OBJECT ${files})
50+
set_property(TARGET obj.${name}PTX PROPERTY CUDA_PTX_COMPILATION ON)
51+
add_flangrt_library(${name}PTX STATIC "$<TARGET_OBJECTS:obj.${name}PTX>")
5152

52-
# Add an OBJECT library consisting of CUDA PTX.
53-
add_flangrt_library(${name}PTX OBJECT ${files})
54-
set_property(TARGET ${name}PTX PROPERTY CUDA_PTX_COMPILATION ON)
53+
# Apply configuration options
5554
if (FLANG_RT_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS)
56-
target_compile_definitions(${name}PTX
55+
target_compile_definitions(obj.${name}PTX
5756
PRIVATE FLANG_RT_NO_GLOBAL_VAR_DEFS
5857
)
5958
endif()
59+
60+
# When using libcudacxx headers files, we have to use them
61+
# for all files of Flang-RT.
62+
if (EXISTS "${FLANG_RT_LIBCUDACXX_PATH}/include")
63+
target_include_directories(obj.${name}PTX AFTER PRIVATE "${FLANG_RT_LIBCUDACXX_PATH}/include")
64+
target_compile_definitions(obj.${name}PTX PRIVATE RT_USE_LIBCUDACXX=1)
65+
endif ()
6066
endif()
6167
endmacro()
6268

flang-rt/lib/CufRuntime/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#
77
#===------------------------------------------------------------------------===#
88

9+
# Phony build target that does not include the CUDA version.
10+
add_custom_target(CufRuntime)
11+
912
# libCufRuntime depends on a certain version of CUDA. To be able to have
1013
# multiple build of this library with different CUDA version, the version is
1114
# added to the library name.
@@ -20,6 +23,7 @@ add_flangrt_library(${CUFRT_LIBNAME}
2023
memory.cpp
2124
registration.cpp
2225
)
26+
add_dependencies(CufRuntime ${CUFRT_LIBNAME})
2327
target_include_directories(${CUFRT_LIBNAME} PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
2428

2529
if (BUILD_SHARED_LIBS)

flang-rt/lib/CufRuntime/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "flang/Runtime/CUDA/kernel.h"
10-
#include "../terminator.h"
10+
#include "../flang_rt/terminator.h"
1111
#include "flang/Runtime/CUDA/common.h"
1212

1313
#include "cuda_runtime.h"

flang-rt/lib/CufRuntime/registration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "flang/Runtime/CUDA/registration.h"
10-
#include "../terminator.h"
10+
#include "../flang_rt/terminator.h"
1111
#include "flang/Runtime/CUDA/common.h"
1212

1313
#include "cuda_runtime.h"

flang-rt/test/Driver/ctofortran.f90

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
! UNSUPPORTED: system-windows
2+
23
! RUN: split-file %s %t
3-
! RUN: chmod +x %t/runtest.sh
4-
! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang | FileCheck %s
4+
! RUN: %clang -c %t/cfile.c -o %t/cfile.o
5+
! RUN: %flang -L"%libdir" %deplibs %t/ffile.f90 %t/cfile.o -o %t/ctofortran
6+
! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%libdir" %t/ctofortran | FileCheck %s
57

68
!--- ffile.f90
79
program fmain
@@ -65,24 +67,3 @@ end subroutine foo
6567
foo(desc);
6668
return;
6769
}
68-
!--- runtest.sh
69-
#!/bin/bash
70-
TMPDIR=$1
71-
FFILE=$2
72-
CFILE=$3
73-
FLANG=$4
74-
shift 4
75-
FLAGS="$*"
76-
BINDIR=`dirname $FLANG`
77-
LIBDIR=$BINDIR/../lib
78-
CCOMP=$BINDIR/clang
79-
if [ -x $CCOMP ]
80-
then
81-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBDIR
82-
$CCOMP $FLAGS -c $CFILE -o $TMPDIR/cfile.o
83-
$FLANG $FLAGS $FFILE $TMPDIR/cfile.o -o $TMPDIR/ctofortran
84-
$TMPDIR/ctofortran # should print "PASS"
85-
else
86-
# No clang compiler, just pass by default
87-
echo "PASS"
88-
fi

flang-rt/test/Driver/exec.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
! Verify that flang can correctly build executables.
22

3-
! RUN: %flang %s -o %t
4-
! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%llvmshlibdir" %t | FileCheck %s
3+
! RUN: %flang -L"%libdir" %s %deplibs -o %t
4+
! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%libdir" %t | FileCheck %s
55
! RUN: rm -f %t
66

77
! CHECK: Hello, World!

flang-rt/test/NonGtestUnit/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# test_exec_root: The root path where tests should be run.
1818
# lit writes a '.lit_test_times.txt' file into this directory.
19-
config.test_exec_root = config.flangrt_binary_test_dir
19+
config.test_exec_root = config.flang_rt_binary_test_dir
2020

2121
# testFormat: The test format to use to interpret tests.
2222
config.test_format = lit.formats.ExecutableTest()

flang-rt/test/NonGtestUnit/lit.site.cfg.py.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import os
44

55
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
6-
config.flangrt_source_dir = "@FLANG_RT_SOURCE_DIR@"
6+
config.flang_rt_source_dir = "@FLANG_RT_SOURCE_DIR@"
77
config.flangrt_binary_dir = "@FLANG_RT_BINARY_DIR@"
8-
config.flangrt_binary_test_dir = os.path.dirname(__file__)
8+
config.flang_rt_binary_test_dir = os.path.dirname(__file__)
99

1010
import lit.llvm
1111
lit.llvm.initialize(lit_config, config)
1212

1313
# Let the main config do the real work.
14-
lit_config.load_config(config, os.path.join(config.flangrt_source_dir, 'test', 'NonGtestUnit', 'lit.cfg.py'))
14+
lit_config.load_config(config, os.path.join(config.flang_rt_source_dir, 'test', 'NonGtestUnit', 'lit.cfg.py'))

0 commit comments

Comments
 (0)