From 5c51585d5baed28b4c25660e1819e7b9eba8572a Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 10:26:26 -0400 Subject: [PATCH 01/11] Add nvcc support to SphericalHarmonics --- .../SphericalHarmonics/TagsTypeAliases.hpp | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/NumericalAlgorithms/SphericalHarmonics/TagsTypeAliases.hpp b/src/NumericalAlgorithms/SphericalHarmonics/TagsTypeAliases.hpp index 7b15115c2926..5fe565c81133 100644 --- a/src/NumericalAlgorithms/SphericalHarmonics/TagsTypeAliases.hpp +++ b/src/NumericalAlgorithms/SphericalHarmonics/TagsTypeAliases.hpp @@ -13,21 +13,20 @@ class DataVector; namespace ylm::Tags { /// Defines type aliases used in Strahlkorper-related Tags. namespace aliases { -template +template using Jacobian = Tensor, - index_list, - SpatialIndex<2, UpLo::Lo, ::Frame::Spherical>>>; -template + index_list, + SpatialIndex<2, UpLo::Lo, ::Frame::Spherical>>>; +template using InvJacobian = Tensor, - index_list>, - SpatialIndex<3, UpLo::Lo, Frame>>>; -template -using InvHessian = - Tensor, - index_list>, - SpatialIndex<3, UpLo::Lo, Frame>, - SpatialIndex<3, UpLo::Lo, Frame>>>; + index_list>, + SpatialIndex<3, UpLo::Lo, Fr>>>; +template +using InvHessian = Tensor< + DataVector, tmpl::integral_list, + index_list>, + SpatialIndex<3, UpLo::Lo, Fr>, SpatialIndex<3, UpLo::Lo, Fr>>>; } // namespace aliases } // namespace ylm::Tags From 2fa47cce5db3796c379681c3be6a9c1971948860 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 10:26:55 -0400 Subject: [PATCH 02/11] Add nvcc support to FiniteDifference library --- src/NumericalAlgorithms/FiniteDifference/Reconstruct.tpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/NumericalAlgorithms/FiniteDifference/Reconstruct.tpp b/src/NumericalAlgorithms/FiniteDifference/Reconstruct.tpp index a481be7ca1d6..448538375861 100644 --- a/src/NumericalAlgorithms/FiniteDifference/Reconstruct.tpp +++ b/src/NumericalAlgorithms/FiniteDifference/Reconstruct.tpp @@ -19,15 +19,15 @@ namespace fd::reconstruction { namespace detail { -template auto generate_index_for_u_to_reconstruct_impl( const std::array& indices, std::index_sequence) -> ::Index { - return ::Index{(DimToReplace != Is ? indices[Is] : Index)...}; + return ::Index{(DimToReplace != Is ? indices[Is] : IndexToSet)...}; } -template auto generate_upper_volume_index_for_u_to_reconstruct_impl( const std::array& indices, @@ -36,7 +36,7 @@ auto generate_upper_volume_index_for_u_to_reconstruct_impl( return ::Index{ (DimToReplace != Is ? indices[Is] - : (volume_extents[Is] - (NumberOfNeighborCells - Index)))...}; + : (volume_extents[Is] - (NumberOfNeighborCells - IndexToSet)))...}; } template Date: Tue, 13 Aug 2024 10:27:12 -0400 Subject: [PATCH 03/11] Add nvcc support to FunctionsOfTime library --- src/Domain/FunctionsOfTime/PiecewisePolynomial.cpp | 5 +++++ .../FunctionsOfTime/QuaternionFunctionOfTime.cpp | 5 +++++ src/Domain/FunctionsOfTime/ThreadsafeList.hpp | 2 +- src/Domain/FunctionsOfTime/ThreadsafeList.tpp | 12 +++++++++--- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Domain/FunctionsOfTime/PiecewisePolynomial.cpp b/src/Domain/FunctionsOfTime/PiecewisePolynomial.cpp index 5b893f1efec6..44ec4af1fe75 100644 --- a/src/Domain/FunctionsOfTime/PiecewisePolynomial.cpp +++ b/src/Domain/FunctionsOfTime/PiecewisePolynomial.cpp @@ -225,6 +225,11 @@ void PiecewisePolynomial::pup(PUP::er& p) { namespace { template struct LegacyStoredInfo { + LegacyStoredInfo() = default; + LegacyStoredInfo(double in_time, + std::array in_stored_quantities) + : time(in_time), stored_quantities(in_stored_quantities) {} + double time{std::numeric_limits::signaling_NaN()}; std::array stored_quantities; diff --git a/src/Domain/FunctionsOfTime/QuaternionFunctionOfTime.cpp b/src/Domain/FunctionsOfTime/QuaternionFunctionOfTime.cpp index 1f65badfd625..a9a91ccd9ef6 100644 --- a/src/Domain/FunctionsOfTime/QuaternionFunctionOfTime.cpp +++ b/src/Domain/FunctionsOfTime/QuaternionFunctionOfTime.cpp @@ -116,6 +116,11 @@ void QuaternionFunctionOfTime::pup(PUP::er& p) { namespace { struct LegacyStoredInfo { + LegacyStoredInfo() = default; + LegacyStoredInfo(double in_time, + std::array in_stored_quantities) + : time(in_time), stored_quantities(in_stored_quantities) {} + double time{std::numeric_limits::signaling_NaN()}; std::array stored_quantities; diff --git a/src/Domain/FunctionsOfTime/ThreadsafeList.hpp b/src/Domain/FunctionsOfTime/ThreadsafeList.hpp index c1f2a9125073..20d781bee3b2 100644 --- a/src/Domain/FunctionsOfTime/ThreadsafeList.hpp +++ b/src/Domain/FunctionsOfTime/ThreadsafeList.hpp @@ -130,7 +130,7 @@ class ThreadsafeList { class iterator { public: using iterator_category = std::input_iterator_tag; - using value_type = decltype(ThreadsafeList{}(double{})); + using value_type = IntervalInfo; using reference = value_type; using pointer = std::optional; using difference_type = std::ptrdiff_t; diff --git a/src/Domain/FunctionsOfTime/ThreadsafeList.tpp b/src/Domain/FunctionsOfTime/ThreadsafeList.tpp index fab22cdcd212..5693d533db17 100644 --- a/src/Domain/FunctionsOfTime/ThreadsafeList.tpp +++ b/src/Domain/FunctionsOfTime/ThreadsafeList.tpp @@ -19,9 +19,15 @@ namespace domain::FunctionsOfTime::FunctionOfTimeHelpers { namespace ThreadsafeList_detail { template struct Interval { - double expiration; - T data; - std::unique_ptr previous; + Interval() = default; + Interval(double in_expiration, T in_data, + std::unique_ptr in_previous) + : expiration(in_expiration), + data(std::move(in_data)), + previous(std::move(in_previous)) {} + double expiration{}; + T data{}; + std::unique_ptr previous{}; void pup(PUP::er& p); }; From f6f0c5b1ac64415601bd1a7cb07ee62025471f46 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 10:28:40 -0400 Subject: [PATCH 04/11] Add nvcc support to Domain library --- src/Domain/BlockLogicalCoordinates.cpp | 22 +++++++++++----------- src/Domain/BlockLogicalCoordinates.hpp | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Domain/BlockLogicalCoordinates.cpp b/src/Domain/BlockLogicalCoordinates.cpp index d0d04aeee683..091b665fe2e8 100644 --- a/src/Domain/BlockLogicalCoordinates.cpp +++ b/src/Domain/BlockLogicalCoordinates.cpp @@ -17,14 +17,14 @@ #include "Utilities/ErrorHandling/Error.hpp" #include "Utilities/GenerateInstantiations.hpp" -template +template std::optional> block_logical_coordinates_single_point( - const tnsr::I& input_point, const Block& block, + const tnsr::I& input_point, const Block& block, const double time, const domain::FunctionsOfTimeMap& functions_of_time) { std::optional> logical_point{}; if (block.is_time_dependent()) { - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { // Point is in the inertial frame, so we need to map to the grid // frame and then the logical frame. const auto moving_inv = block.moving_mesh_grid_to_inertial_map().inverse( @@ -35,7 +35,7 @@ block_logical_coordinates_single_point( // logical to grid map is time-independent. logical_point = block.moving_mesh_logical_to_grid_map().inverse(moving_inv.value()); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { // Point is in the distorted frame, so we need to map to the grid // frame and then the logical frame. if (not block.has_distorted_frame()) { @@ -78,7 +78,7 @@ block_logical_coordinates_single_point( // frames in the block, so make sure Frame is // ::Frame::Grid. (The Inertial and Distorted cases were // handled above.) - static_assert(std::is_same_v, + static_assert(std::is_same_v, "Cannot convert from given frame to Grid frame"); // Point is in the grid frame, just map to logical frame. @@ -86,7 +86,7 @@ block_logical_coordinates_single_point( block.moving_mesh_logical_to_grid_map().inverse(input_point); } } else { // not block.is_time_dependent() - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { logical_point = block.stationary_map().inverse(input_point); } else { // If the map is time-independent, then the grid, distorted, and @@ -94,8 +94,8 @@ block_logical_coordinates_single_point( // or distorted frames, convert to the inertial frame // (this conversion is just a type conversion). // Otherwise throw a static_assert. - static_assert(std::is_same_v or - std::is_same_v, + static_assert(std::is_same_v or + std::is_same_v, "Cannot convert from given frame to Inertial frame"); tnsr::I x_inertial(0.0); for (size_t d = 0; d < Dim; ++d) { @@ -133,14 +133,14 @@ block_logical_coordinates_single_point( return logical_point; } -template +template std::vector> block_logical_coordinates( - const Domain& domain, const tnsr::I& x, + const Domain& domain, const tnsr::I& x, const double time, const domain::FunctionsOfTimeMap& functions_of_time) { const size_t num_pts = get<0>(x).size(); std::vector> block_coord_holders(num_pts); for (size_t s = 0; s < num_pts; ++s) { - tnsr::I x_frame(0.0); + tnsr::I x_frame(0.0); for (size_t d = 0; d < Dim; ++d) { x_frame.get(d) = x.get(d)[s]; } diff --git a/src/Domain/BlockLogicalCoordinates.hpp b/src/Domain/BlockLogicalCoordinates.hpp index 715b69975e4e..b322f218ae2c 100644 --- a/src/Domain/BlockLogicalCoordinates.hpp +++ b/src/Domain/BlockLogicalCoordinates.hpp @@ -62,17 +62,17 @@ using BlockLogicalCoords = std::optional< /// typical use cases. This means that `block_logical_coordinates` /// does not assume that grid and distorted frames are equal in /// `Block`s that lack a distorted frame. -template +template auto block_logical_coordinates( - const Domain& domain, const tnsr::I& x, + const Domain& domain, const tnsr::I& x, double time = std::numeric_limits::signaling_NaN(), const domain::FunctionsOfTimeMap& functions_of_time = {}) -> std::vector>; -template +template std::optional> block_logical_coordinates_single_point( - const tnsr::I& input_point, const Block& block, + const tnsr::I& input_point, const Block& block, double time = std::numeric_limits::signaling_NaN(), const domain::FunctionsOfTimeMap& functions_of_time = {}); /// @} From 26b2b3880a43e25206d5da55b98ca4edb4d51bac Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 11:51:27 -0400 Subject: [PATCH 05/11] Use Kokkos launcher in our library link wrapper --- cmake/SpectreAddLibraries.cmake | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmake/SpectreAddLibraries.cmake b/cmake/SpectreAddLibraries.cmake index 1bd37f8830fd..0b8d1064b33e 100644 --- a/cmake/SpectreAddLibraries.cmake +++ b/cmake/SpectreAddLibraries.cmake @@ -39,14 +39,23 @@ function(ADD_SPECTRE_LIBRARY LIBRARY_NAME) PUBLIC ${SPECTRE_ALLOCATOR_LIBRARY} SpectreAllocator - ) + ) + set(SPECTRE_KOKKOS_LAUNCHER "") + if(SPECTRE_KOKKOS) + # We need to make sure we don't drop the Kokkos link wrapper + get_target_property( + SPECTRE_KOKKOS_LAUNCHER + ${LIBRARY_NAME} + RULE_LAUNCH_LINK) + endif() set_target_properties( ${LIBRARY_NAME} PROPERTIES - RULE_LAUNCH_LINK "${CMAKE_BINARY_DIR}/tmp/WrapLibraryLinker.sh" + RULE_LAUNCH_LINK + "${CMAKE_BINARY_DIR}/tmp/WrapLibraryLinker.sh ${SPECTRE_KOKKOS_LAUNCHER}" LINK_DEPENDS "${CMAKE_BINARY_DIR}/tmp/WrapLibraryLinker.sh" - ) + ) endif (NOT ${LIBRARY_TYPE} STREQUAL INTERFACE_LIBRARY) if (NOT "${LIBRARY_NAME}" MATCHES "^SpectrePch" AND NOT ${LIBRARY_IS_IMPORTED} From 1f1ff4292cb1c65a58cdd580c2a5945c557fdf39 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 11:52:57 -0400 Subject: [PATCH 06/11] Use Kokkos launcher in our executable link wrapper --- cmake/AddSpectreExecutable.cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmake/AddSpectreExecutable.cmake b/cmake/AddSpectreExecutable.cmake index f376bf625142..9340889ed9f6 100644 --- a/cmake/AddSpectreExecutable.cmake +++ b/cmake/AddSpectreExecutable.cmake @@ -26,11 +26,21 @@ function(add_spectre_executable TARGET_NAME) PUBLIC ${SPECTRE_ALLOCATOR_LIBRARY} SpectreAllocator - ) + ) + + set(SPECTRE_KOKKOS_LAUNCHER "") + if(SPECTRE_KOKKOS) + # We need to make sure we don't drop the Kokkos link wrapper + get_target_property( + SPECTRE_KOKKOS_LAUNCHER + ${TARGET_NAME} + RULE_LAUNCH_LINK) + endif() set_target_properties( ${TARGET_NAME} PROPERTIES - RULE_LAUNCH_LINK "${CMAKE_BINARY_DIR}/tmp/WrapExecutableLinker.sh" + RULE_LAUNCH_LINK + "${CMAKE_BINARY_DIR}/tmp/WrapExecutableLinker.sh ${SPECTRE_KOKKOS_LAUNCHER}" LINK_DEPENDS "${CMAKE_BINARY_DIR}/tmp/WrapExecutableLinker.sh" # Expose readable symbol names in backtrace (adds flags like -rdynamic) ENABLE_EXPORTS ON From 5fd22c374a869632a6835e4bcf79d3669f00e30a Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 11:54:57 -0400 Subject: [PATCH 07/11] Handle GCC warnings with nvcc The clang setup is not yet working. --- cmake/SetupKokkos.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/SetupKokkos.cmake b/cmake/SetupKokkos.cmake index a1b9f8b742a4..d9c46c1493af 100644 --- a/cmake/SetupKokkos.cmake +++ b/cmake/SetupKokkos.cmake @@ -27,7 +27,9 @@ if(SPECTRE_KOKKOS) find_package(Kokkos REQUIRED) - if (TARGET Kokkos::kokkos AND Kokkos_ENABLE_CUDA) + if (TARGET Kokkos::kokkos + AND Kokkos_ENABLE_CUDA + AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set_property(TARGET Kokkos::kokkos APPEND PROPERTY INTERFACE_COMPILE_OPTIONS From 96528a5d8b70de1133ce2bdb73d4eb34730894b7 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 11:55:17 -0400 Subject: [PATCH 08/11] Have Blaze compile with GPU support --- tools/BlazeExceptions.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/BlazeExceptions.hpp b/tools/BlazeExceptions.hpp index 024ee4c14227..298a2c5b4586 100644 --- a/tools/BlazeExceptions.hpp +++ b/tools/BlazeExceptions.hpp @@ -3,6 +3,12 @@ #include +#ifdef __CUDA_ARCH__ +// When building for Nvidia GPUs we need to disable the use of vector +// intrinsics. +#define BLAZE_USE_VECTORIZATION 0 +#endif + #ifndef SPECTRE_BLAZE_EXCEPTIONS_HPP #define SPECTRE_BLAZE_EXCEPTIONS_HPP From 557db237392cbf32a62bae6c98fa1f0c12a8fb61 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 11:55:31 -0400 Subject: [PATCH 09/11] Make PCH depend on Kokkos --- cmake/SetupPch.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/SetupPch.cmake b/cmake/SetupPch.cmake index 78f4aab7fce4..3dc74d4d54de 100644 --- a/cmake/SetupPch.cmake +++ b/cmake/SetupPch.cmake @@ -49,6 +49,7 @@ target_link_libraries( Charmxx::pup HDF5::HDF5 SpectreFlags + SpectreKokkos ) # Targets can reuse the PCH generated for this library. They must also link From 32da4394eb7a1958ac0d2636c469a1d17547b685 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 12:05:29 -0400 Subject: [PATCH 10/11] Support nvcc in IO library --- src/IO/H5/Cce.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/IO/H5/Cce.cpp b/src/IO/H5/Cce.cpp index f41be14a456c..008fd4176a7e 100644 --- a/src/IO/H5/Cce.cpp +++ b/src/IO/H5/Cce.cpp @@ -141,6 +141,10 @@ Cce::~Cce() { // internals of CHECK_H5), so older compilers that we support may not have // fixed this bug. for (const auto& name_and_dataset : bondi_datasets_) { +#ifdef __CUDACC__ + // nvcc warns that 'name' is unused + [[maybe_unused]] +#endif const auto& name = name_and_dataset.first; const auto& dataset = name_and_dataset.second; CHECK_H5(H5Dclose(dataset.id), "Failed to close dataset " << name); From 0399d1a85f1fe22c445dc95390fa379a82fa7fb9 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Tue, 13 Aug 2024 14:54:27 -0400 Subject: [PATCH 11/11] Add nvcc to Importers library --- src/IO/Importers/Actions/ReadVolumeData.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/IO/Importers/Actions/ReadVolumeData.hpp b/src/IO/Importers/Actions/ReadVolumeData.hpp index 40aa4dac4b1a..138bca489105 100644 --- a/src/IO/Importers/Actions/ReadVolumeData.hpp +++ b/src/IO/Importers/Actions/ReadVolumeData.hpp @@ -21,6 +21,7 @@ #include "Domain/Structure/ElementId.hpp" #include "IO/H5/AccessType.hpp" #include "IO/H5/File.hpp" +#include "IO/H5/TensorData.hpp" #include "IO/H5/VolumeData.hpp" #include "IO/Importers/ObservationSelector.hpp" #include "IO/Importers/Tags.hpp"