diff --git a/flang/include/flang/Common/idioms.h b/flang/include/flang/Common/idioms.h index 231fbd8601a2a..99f383ec75b99 100644 --- a/flang/include/flang/Common/idioms.h +++ b/flang/include/flang/Common/idioms.h @@ -24,6 +24,7 @@ #endif #include "enum-class.h" +#include "variant.h" #include "visit.h" #include #include @@ -33,7 +34,6 @@ #include #include #include -#include #if __GNUC__ == 7 // Avoid a deduction bug in GNU 7.x headers by forcing the answer. diff --git a/flang/include/flang/Common/template.h b/flang/include/flang/Common/template.h index 2ab3b8bce1df9..51d09fb42ce36 100644 --- a/flang/include/flang/Common/template.h +++ b/flang/include/flang/Common/template.h @@ -9,12 +9,12 @@ #ifndef FORTRAN_COMMON_TEMPLATE_H_ #define FORTRAN_COMMON_TEMPLATE_H_ +#include "variant.h" #include "flang/Common/idioms.h" #include #include #include #include -#include #include // Utility templates for metaprogramming and for composing the diff --git a/flang/include/flang/Common/unwrap.h b/flang/include/flang/Common/unwrap.h index edb343d77b537..84582174e4b30 100644 --- a/flang/include/flang/Common/unwrap.h +++ b/flang/include/flang/Common/unwrap.h @@ -12,11 +12,11 @@ #include "indirection.h" #include "reference-counted.h" #include "reference.h" +#include "variant.h" #include "visit.h" #include #include #include -#include // Given a nest of variants, optionals, &/or pointers, Unwrap<>() isolates // a packaged value of a specific type if it is present and returns a pointer diff --git a/flang/include/flang/Common/variant.h b/flang/include/flang/Common/variant.h new file mode 100644 index 0000000000000..1af85876afac0 --- /dev/null +++ b/flang/include/flang/Common/variant.h @@ -0,0 +1,30 @@ +//===-- include/flang/Common/variant.h --------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// A single way to expose C++ variant class in files that can be used +// in F18 runtime build. With inclusion of this file std::variant +// and the related names become available, though, they may correspond +// to alternative definitions (e.g. from cuda::std namespace). + +#ifndef FORTRAN_COMMON_VARIANT_H +#define FORTRAN_COMMON_VARIANT_H + +#if RT_USE_LIBCUDACXX +#include +namespace std { +using cuda::std::get; +using cuda::std::monostate; +using cuda::std::variant; +using cuda::std::variant_size_v; +using cuda::std::visit; +} // namespace std +#else // !RT_USE_LIBCUDACXX +#include +#endif // !RT_USE_LIBCUDACXX + +#endif // FORTRAN_COMMON_VARIANT_H diff --git a/flang/include/flang/Common/visit.h b/flang/include/flang/Common/visit.h index 54f8ca70b313c..4d0897301e01d 100644 --- a/flang/include/flang/Common/visit.h +++ b/flang/include/flang/Common/visit.h @@ -21,9 +21,9 @@ #ifndef FORTRAN_COMMON_VISIT_H_ #define FORTRAN_COMMON_VISIT_H_ +#include "variant.h" #include "flang/Common/api-attrs.h" #include -#include namespace Fortran::common { namespace log2visit { diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt index facd14432b3ee..c0e4cff698e3c 100644 --- a/flang/runtime/CMakeLists.txt +++ b/flang/runtime/CMakeLists.txt @@ -174,6 +174,7 @@ set(sources option(FLANG_EXPERIMENTAL_CUDA_RUNTIME "Compile Fortran runtime as CUDA sources (experimental)" OFF ) +set(FLANG_LIBCUDACXX_PATH "" CACHE PATH "Path to libcu++ package installation") # List of files that are buildable for all devices. set(supported_files @@ -260,6 +261,13 @@ if (FLANG_EXPERIMENTAL_CUDA_RUNTIME) set_source_files_properties(${supported_files} PROPERTIES COMPILE_OPTIONS "${CUDA_COMPILE_OPTIONS}" ) + + if (EXISTS "${FLANG_LIBCUDACXX_PATH}/include") + # When using libcudacxx headers files, we have to use them + # for all files of F18 runtime. + include_directories(AFTER ${FLANG_LIBCUDACXX_PATH}/include) + add_compile_definitions(RT_USE_LIBCUDACXX=1) + endif() endif() set(FLANG_EXPERIMENTAL_OMP_OFFLOAD_BUILD "off" CACHE STRING diff --git a/flang/runtime/io-stmt.h b/flang/runtime/io-stmt.h index e0dafa9c763c4..8b5752311de5c 100644 --- a/flang/runtime/io-stmt.h +++ b/flang/runtime/io-stmt.h @@ -21,9 +21,9 @@ #include "flang/Common/visit.h" #include "flang/Runtime/descriptor.h" #include "flang/Runtime/io-api.h" +#include #include #include -#include namespace Fortran::runtime::io { diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp index b5aa307eade81..6c648d3bd8346 100644 --- a/flang/runtime/unit.cpp +++ b/flang/runtime/unit.cpp @@ -482,10 +482,7 @@ bool ExternalFileUnit::SetDirectRec( void ExternalFileUnit::EndIoStatement() { io_.reset(); - RT_DIAG_PUSH - RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN u_.emplace(); - RT_DIAG_POP lock_.Drop(); } @@ -752,10 +749,7 @@ std::int32_t ExternalFileUnit::ReadHeaderOrFooter(std::int64_t frameOffset) { void ChildIo::EndIoStatement() { io_.reset(); - RT_DIAG_PUSH - RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN u_.emplace(); - RT_DIAG_POP } Iostat ChildIo::CheckFormattingAndDirection( diff --git a/flang/runtime/unit.h b/flang/runtime/unit.h index 8b7db5cbc90b4..a6ee5971a1652 100644 --- a/flang/runtime/unit.h +++ b/flang/runtime/unit.h @@ -25,7 +25,7 @@ #include "flang/Runtime/memory.h" #include #include -#include +#include namespace Fortran::runtime::io { @@ -152,10 +152,7 @@ class ExternalFileUnit : public ConnectionState, #else lock_.Take(); #endif - RT_DIAG_PUSH - RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN A &state{u_.emplace(std::forward(xs)...)}; - RT_DIAG_POP if constexpr (!std::is_same_v) { state.mutableModes() = ConnectionState::modes; } @@ -265,10 +262,7 @@ class ChildIo { template RT_API_ATTRS IoStatementState &BeginIoStatement(X &&...xs) { - RT_DIAG_PUSH - RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN A &state{u_.emplace(std::forward(xs)...)}; - RT_DIAG_POP io_.emplace(state); return *io_; }