Skip to content

Commit

Permalink
Merge Pull Request #13188 from rppawlo/Trilinos/fix-for-kokkos-serial…
Browse files Browse the repository at this point in the history
…-changes

Automatically Merged using Trilinos Pull Request AutoTester
PR Title: b'Phalanx: Fix for kokkos serial changes'
PR Author: rppawlo
  • Loading branch information
trilinos-autotester authored Jun 28, 2024
2 parents e4a0d17 + 46dd983 commit 795e2d1
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
62 changes: 58 additions & 4 deletions packages/phalanx/src/Phalanx_KokkosViewOfViews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace PHX {
is_initialized_ = true;
}

/// Set an inner device view on the outer view. Indices are the outer view indices.
/// Set an inner device view on the outer view. Indices are the outer view indices.
template<typename... Indices>
void setView(InnerViewType v,Indices... i)
{
Expand Down Expand Up @@ -488,7 +488,16 @@ namespace PHX {
}
};

// Rank 1 outer view
/** \brief Returns a rank-1 view of views where both the outer and inner views are on host. Values are deep_copied from input v_of_v.
IMPORTANT: The user must manually call free on the inner views
of the returned object with the
PHX::freeInnerViewsOfHostHostViewOfViews() before deleting the
host-host view of view. Failure to do so will result in
deadlock. The outer view dtor calls a parallel_for and the inner
view dtor calls another parallel_for. Nested parallel_fors are
blocked by a mutex even on Serial backend now!
*/
template<typename InnerViewDataType,typename... InnerProps,typename... OuterProps>
auto createHostHostViewOfViews(const Kokkos::View<Kokkos::View<InnerViewDataType,InnerProps...>*,OuterProps...>& v_of_v) {
// Host outer view pointing to device inner views
Expand All @@ -510,7 +519,16 @@ namespace PHX {
return host_host;
}

// Rank 2 outer view
/** \brief Returns a rank-2 view of views where both the outer and inner views are on host. Values are deep_copied from input v_of_v.
IMPORTANT: The user must manually call free on the inner views
of the returned object with the
PHX::freeInnerViewsOfHostHostViewOfViews() before deleting the
host-host view of view. Failure to do so will result in
deadlock. The outer view dtor calls a parallel_for and the inner
view dtor calls another parallel_for. Nested parallel_fors are
blocked by a mutex even on Serial backend now!
*/
template<typename InnerViewDataType,typename... InnerProps,typename... OuterProps>
auto createHostHostViewOfViews(const Kokkos::View<Kokkos::View<InnerViewDataType,InnerProps...>**,OuterProps...>& v_of_v) {
// Host outer view pointing to device inner views
Expand All @@ -534,7 +552,16 @@ namespace PHX {
return host_host;
}

// Rank 3 outer view
/** \brief Returns a rank-3 view of views where both the outer and inner views are on host. Values are deep_copied from input v_of_v.
IMPORTANT: The user must manually call free on the inner views
of the returned object with the
PHX::freeInnerViewsOfHostHostViewOfViews() before deleting the
host-host view of view. Failure to do so will result in
deadlock. The outer view dtor calls a parallel_for and the inner
view dtor calls another parallel_for. Nested parallel_fors are
blocked by a mutex even on Serial backend now!
*/
template<typename InnerViewDataType,typename... InnerProps,typename... OuterProps>
auto createHostHostViewOfViews(const Kokkos::View<Kokkos::View<InnerViewDataType,InnerProps...>***,OuterProps...>& v_of_v) {
// Host outer view pointing to device inner views
Expand All @@ -561,6 +588,33 @@ namespace PHX {
return host_host;
}

template<typename InnerViewDataType,typename... InnerProps,typename... OuterProps>
auto freeInnerViewsOfHostHostViewOfViews(Kokkos::View<Kokkos::View<InnerViewDataType,InnerProps...>*,OuterProps...>& v_of_v) {
for (std::size_t i=0; i < v_of_v.extent(0); ++i) {
v_of_v(i) = Kokkos::View<InnerViewDataType,InnerProps...>();
}
}

template<typename InnerViewDataType,typename... InnerProps,typename... OuterProps>
auto freeInnerViewsOfHostHostViewOfViews(Kokkos::View<Kokkos::View<InnerViewDataType,InnerProps...>**,OuterProps...>& v_of_v) {
for (std::size_t i=0; i < v_of_v.extent(0); ++i) {
for (std::size_t j=0; j < v_of_v.extent(1); ++j) {
v_of_v(i,j) = Kokkos::View<InnerViewDataType,InnerProps...>();
}
}
}

template<typename InnerViewDataType,typename... InnerProps,typename... OuterProps>
auto freeInnerViewsOfHostHostViewOfViews(Kokkos::View<Kokkos::View<InnerViewDataType,InnerProps...>***,OuterProps...>& v_of_v) {
for (std::size_t i=0; i < v_of_v.extent(0); ++i) {
for (std::size_t j=0; j < v_of_v.extent(1); ++j) {
for (std::size_t k=0; k < v_of_v.extent(2); ++k) {
v_of_v(i,j,k) = Kokkos::View<InnerViewDataType,InnerProps...>();
}
}
}
}

} // namespace PHX

#endif
9 changes: 9 additions & 0 deletions packages/phalanx/test/ViewOfViews/tPhalanxViewOfViews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ TEUCHOS_UNIT_TEST(PhalanxViewOfViews,CreateHostHost) {
TEST_FLOATING_EQUALITY(vov_host(2)(cell),4.0,tol);
TEST_FLOATING_EQUALITY(vov_host(3)(cell),10.0,tol);
}

// NOTE: you must call this on the host-host version to avoid deadlock!
PHX::freeInnerViewsOfHostHostViewOfViews(vov_host);
}

// Rank 2 outer view
Expand All @@ -616,6 +619,9 @@ TEUCHOS_UNIT_TEST(PhalanxViewOfViews,CreateHostHost) {
TEST_FLOATING_EQUALITY(vov_host(1,0)(cell),4.0,tol);
TEST_FLOATING_EQUALITY(vov_host(1,1)(cell),11.0,tol);
}

// NOTE: you must call this on the host-host version to avoid deadlock!
PHX::freeInnerViewsOfHostHostViewOfViews(vov_host);
}

// Rank 3 outer view
Expand All @@ -642,6 +648,9 @@ TEUCHOS_UNIT_TEST(PhalanxViewOfViews,CreateHostHost) {
TEST_FLOATING_EQUALITY(vov_host(2,2,2)(cell),4.0,tol);
TEST_FLOATING_EQUALITY(vov_host(0,1,2)(cell),12.0,tol);
}

// NOTE: you must call this on the host-host version to avoid deadlock!
PHX::freeInnerViewsOfHostHostViewOfViews(vov_host);
}

}
Expand Down

0 comments on commit 795e2d1

Please sign in to comment.