Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions flang-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ endif()
# System Introspection #
########################

# The GPU targets require a few mandatory arguments to make the standard CMake
# check flags happy.
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib")
elseif ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
set(CMAKE_REQUIRED_FLAGS
"${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument")
endif()

include(CheckCXXSymbolExists)
include(CheckCXXSourceCompiles)
check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
Expand Down
25 changes: 18 additions & 7 deletions flang-rt/cmake/modules/AddFlangRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ function (add_flangrt_library name)
# Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
target_compile_features(${tgtname} PRIVATE cxx_std_17)

# When building the flang runtime if LTO is enabled the archive file
# contains LLVM IR rather than object code. Currently flang is not
# LTO aware so cannot link this file to compiled Fortran code.
if (FLANG_RT_HAS_FNO_LTO_FLAG)
target_compile_options(${tgtname} PRIVATE -fno-lto)
endif ()

# Use compiler-specific options to disable exceptions and RTTI.
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
target_compile_options(${tgtname} PRIVATE
Expand All @@ -226,6 +233,17 @@ function (add_flangrt_library name)
)
endif ()

# Add target specific options if necessary.
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn")
target_compile_options(${tgtname} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden>
)
elseif ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
target_compile_options(${tgtname} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden -Wno-unknown-cuda-version --cuda-feature=+ptx63>
)
endif ()

# Also for CUDA source when compiling with FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA
if (CMAKE_CUDA_COMPILER_ID MATCHES "NVIDIA")
# Assuming gcc as host compiler.
Expand Down Expand Up @@ -256,13 +274,6 @@ function (add_flangrt_library name)
target_compile_options(${tgtname} PUBLIC -U_LIBCPP_ENABLE_ASSERTIONS)
endif ()

# When building the flang runtime if LTO is enabled the archive file
# contains LLVM IR rather than object code. Currently flang is not
# LTO aware so cannot link this file to compiled Fortran code.
if (FLANG_RT_HAS_FNO_LTO_FLAG)
target_compile_options(${tgtname} PRIVATE -fno-lto)
endif ()

# Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI
# should only depend on msvcrt/ucrt. LLVM still emits libgcc/compiler-rt
# functions in some cases like 128-bit integer math (__udivti3, __modti3,
Expand Down
4 changes: 3 additions & 1 deletion flang-rt/cmake/modules/HandleLibs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ elseif (FLANG_RT_LIBCXX_PROVIDER STREQUAL "llvm")
endif ()

if (FLANG_RT_HAS_STDLIB_FLAG)
target_compile_options(flang-rt-libc-headers INTERFACE $<$<COMPILE_LANGUAGE:CXX,C>:-stdlib=libc++>)
target_compile_options(flang-rt-libc-headers INTERFACE
$<$<COMPILE_LANGUAGE:CXX,C>:$<COMPILE_ONLY:-stdlib=libc++>>
)
endif ()
endif ()
55 changes: 53 additions & 2 deletions flang-rt/lib/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ find_package(Backtrace)
set(HAVE_BACKTRACE ${Backtrace_FOUND})
set(BACKTRACE_HEADER ${Backtrace_HEADER})


# List of files that are buildable for all devices.
set(supported_sources
${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
Expand Down Expand Up @@ -88,6 +87,54 @@ set(host_sources
unit-map.cpp
)

# Sources that can be compiled directly for the GPU.
set(gpu_sources
Comment on lines +90 to +91
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid duplicating the list of sources? What makes theses gpu-compatible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly this is just the list of files that didn't error. There's a few different ones from the existing offloading builds, mostly due to the fact that we don't borrow the system's headers. I was thinking of a creative way to split these up but figured this was easiest.

Most of these fail due to missing headers, mostly POSIX related things because as much as we try pthreads and sema are not going to work on a GPU.

${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
${FLANG_SOURCE_DIR}/lib/Decimal/decimal-to-binary.cpp
ISO_Fortran_binding.cpp
allocator-registry.cpp
allocatable.cpp
array-constructor.cpp
assign.cpp
buffer.cpp
character.cpp
connection.cpp
copy.cpp
derived-api.cpp
derived.cpp
dot-product.cpp
edit-output.cpp
extrema.cpp
findloc.cpp
format.cpp
inquiry.cpp
internal-unit.cpp
io-error.cpp
iostat.cpp
matmul-transpose.cpp
matmul.cpp
memory.cpp
misc-intrinsic.cpp
non-tbp-dio.cpp
numeric.cpp
pointer.cpp
product.cpp
ragged.cpp
stat.cpp
sum.cpp
support.cpp
terminator.cpp
tools.cpp
transformational.cpp
type-code.cpp
type-info.cpp
utf.cpp
complex-powi.cpp
reduce.cpp
reduction.cpp
temporary-stack.cpp
)

file(GLOB_RECURSE public_headers
"${FLANG_RT_SOURCE_DIR}/include/flang_rt/*.h"
"${FLANG_SOURCE_DIR}/include/flang/Common/*.h"
Expand Down Expand Up @@ -124,7 +171,11 @@ else ()
set(f128_sources "")
endif ()

set(sources ${supported_sources} ${host_sources} ${f128_sources})
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^amdgcn|^nvptx")
set(sources ${gpu_sources})
else ()
set(sources ${supported_sources} ${host_sources} ${f128_sources})
endif ()


if (NOT WIN32)
Expand Down
44 changes: 25 additions & 19 deletions flang/cmake/modules/FlangCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,30 @@ if (FLANG_RUNTIME_F128_MATH_LIB)
add_compile_definitions(FLANG_RUNTIME_F128_MATH_LIB="${FLANG_RUNTIME_F128_MATH_LIB}")
endif()

# Check if 128-bit float computations can be done via long double
# Note that '-nostdinc++' might be implied when this code kicks in
# (see 'runtimes/CMakeLists.txt'), so we cannot use 'cfloat' C++ header
# file in the test below.
# Compile it as C.
check_c_source_compiles(
"#include <float.h>
#if LDBL_MANT_DIG != 113
#error LDBL_MANT_DIG != 113
#endif
int main() { return 0; }
"
HAVE_LDBL_MANT_DIG_113)

include(TestBigEndian)
test_big_endian(IS_BIGENDIAN)
if (IS_BIGENDIAN)
add_compile_definitions(FLANG_BIG_ENDIAN=1)
else ()
# The NVPTX target can't emit a binary due to the PTXAS dependency, just
# hard-code this.
if ("${LLVM_RUNTIMES_TARGET}" MATCHES "^nvptx")
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
else ()
# Check if 128-bit float computations can be done via long double
# Note that '-nostdinc++' might be implied when this code kicks in
# (see 'runtimes/CMakeLists.txt'), so we cannot use 'cfloat' C++ header
# file in the test below.
# Compile it as C.
check_c_source_compiles(
"#include <float.h>
#if LDBL_MANT_DIG != 113
#error LDBL_MANT_DIG != 113
#endif
int main() { return 0; }
"
HAVE_LDBL_MANT_DIG_113)

include(TestBigEndian)
test_big_endian(IS_BIGENDIAN)
if (IS_BIGENDIAN)
add_compile_definitions(FLANG_BIG_ENDIAN=1)
else ()
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
endif ()
endif ()