From: Daniel Arndt Date: Mon, 5 Aug 2024 20:04:46 +0000 (-0400) Subject: Use aliases for TpetraTypes::[Dual]View[Unmanaged] X-Git-Tag: v9.6.0-rc2~2^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fb2ad44d5053206d2f82badc2593686b9cf7f10;p=dealii.git Use aliases for TpetraTypes::[Dual]View[Unmanaged] --- diff --git a/examples/step-86/step-86.cc b/examples/step-86/step-86.cc index cc54612330..3c94ac0b4f 100644 --- a/examples/step-86/step-86.cc +++ b/examples/step-86/step-86.cc @@ -591,7 +591,7 @@ namespace Step86 // the constrained dofs corresponding to hanging nodes (i.e., those for // which the lines of the `current_constraints` contain at least one other // entry), and to the difference between the input vector and the actual - // solution on those constraints that correspond to boundary conditions.  + // solution on those constraints that correspond to boundary conditions. for (const auto &c : current_constraints.get_lines()) if (locally_owned_dofs.is_element(c.index)) { diff --git a/include/deal.II/lac/trilinos_tpetra_precondition.templates.h b/include/deal.II/lac/trilinos_tpetra_precondition.templates.h index fc4a9c1250..ee5ebf4193 100644 --- a/include/deal.II/lac/trilinos_tpetra_precondition.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_precondition.templates.h @@ -151,12 +151,18 @@ namespace LinearAlgebra // 1. Make host view with underlying dealii::Vector data. // (This is always a n x 1 matrix since multivector expects that.) - TpetraTypes::HostViewTypeUnmanaged host_src(src.data(), - src.size(), - 1); - TpetraTypes::HostViewTypeUnmanaged host_dst(dst.data(), - dst.size(), - 1); + + // Tpetra uses Kokkos::complex<> internally for std::complex<> + using value_type = typename TpetraTypes::HostViewType::value_type; + static_assert((numbers::NumberTraits::is_complex && + sizeof(value_type) == sizeof(Number)) || + (!numbers::NumberTraits::is_complex && + std::is_same_v)); + + TpetraTypes::HostViewType host_src( + reinterpret_cast(src.data()), src.size(), 1); + TpetraTypes::HostViewType host_dst( + reinterpret_cast(dst.data()), dst.size(), 1); // 2. Create device mirror (if Device == Host, no alloc ) auto dev_src = Kokkos::create_mirror_view_and_copy( @@ -166,10 +172,10 @@ namespace LinearAlgebra typename MemorySpace::kokkos_space::execution_space(), host_dst); // 3. Create dual views from the previous ones - TpetraTypes::DualViewTypeUnmanaged dual_src( - dev_src, host_src); - TpetraTypes::DualViewTypeUnmanaged dual_dst( - dev_dst, host_dst); + TpetraTypes::DualViewType dual_src(dev_src, + host_src); + TpetraTypes::DualViewType dual_dst(dev_dst, + host_dst); // 4. Create Tpetra Vector from TpetraTypes::VectorType tpetra_dst( @@ -201,12 +207,18 @@ namespace LinearAlgebra // 1. Make host view with underlying dealii::Vector data. // (This is always a n x 1 matrix since multivector expects that.) - TpetraTypes::HostViewTypeUnmanaged host_src(src.data(), - src.size(), - 1); - TpetraTypes::HostViewTypeUnmanaged host_dst(dst.data(), - dst.size(), - 1); + + // Tpetra uses Kokkos::complex<> internally for std::complex<> + using value_type = typename TpetraTypes::HostViewType::value_type; + static_assert((numbers::NumberTraits::is_complex && + sizeof(value_type) == sizeof(Number)) || + (!numbers::NumberTraits::is_complex && + std::is_same_v)); + + TpetraTypes::HostViewType host_src( + reinterpret_cast(src.data()), src.size(), 1); + TpetraTypes::HostViewType host_dst( + reinterpret_cast(dst.data()), dst.size(), 1); // 2. Create device mirror (if Device == Host, no alloc ) auto dev_src = Kokkos::create_mirror_view_and_copy( @@ -216,10 +228,10 @@ namespace LinearAlgebra typename MemorySpace::kokkos_space::execution_space(), host_dst); // 3. Create dual views from the previous ones - TpetraTypes::DualViewTypeUnmanaged dual_src( - dev_src, host_src); - TpetraTypes::DualViewTypeUnmanaged dual_dst( - dev_dst, host_dst); + TpetraTypes::DualViewType dual_src(dev_src, + host_src); + TpetraTypes::DualViewType dual_dst(dev_dst, + host_dst); // 4. Create Tpetra Vector from TpetraTypes::VectorType tpetra_dst( diff --git a/include/deal.II/lac/trilinos_tpetra_types.h b/include/deal.II/lac/trilinos_tpetra_types.h index 4cd49089a9..fb5242ad37 100644 --- a/include/deal.II/lac/trilinos_tpetra_types.h +++ b/include/deal.II/lac/trilinos_tpetra_types.h @@ -21,6 +21,8 @@ #ifdef DEAL_II_TRILINOS_WITH_TPETRA +# include + # include # include @@ -145,36 +147,23 @@ namespace LinearAlgebra /** - * @brief Typedef for the Kokkos::View type of unmanaged host memory. - * - * Unmanaged means that the view is not allocating data itself, but only - * uses an external pointer. Consequently, the memory is not freed upon - * destruction of the view. + * @brief Typedef for the Kokkos::View type. * This is needed for shallow copies of deal.II LA structures * to Trilinos LA structures. * */ template - using HostViewTypeUnmanaged = Kokkos::View; + using HostViewType = + typename VectorType::host_view_type; /** - * @brief Typedef for the Kokkos::View type of unmanaged memory. - * - * Unmanaged means that the view is not allocating data itself, but only - * uses an external pointer. Consequently, the memory is not freed upon - * destruction of the view. + * @brief Typedef for the Kokkos::DualView type. * This is needed for shallow copies of deal.II LA structures * to Trilinos LA structures. */ template - using DualViewTypeUnmanaged = - Kokkos::DualView; + using DualViewType = + typename VectorType::dual_view_type; # ifdef DEAL_II_TRILINOS_WITH_IFPACK2