Skip to content

Commit

Permalink
Amesos2: try avoiding shallow-copy of a local-view
Browse files Browse the repository at this point in the history
  • Loading branch information
iyamazaki committed Jun 10, 2021
1 parent 3b37714 commit 8b4b0b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
24 changes: 24 additions & 0 deletions packages/amesos2/src/Amesos2_Kokkos_View_Copy_Assign.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ implement_copy_or_assign_same_mem_check_types(bool bInitialize, dst_t & dst, con
bAssigned = true;
}


// deep-copy version (no checking)
// bInitialize:
// If bInitialize is false, then the data needs to be allocated but not initialized.
// If we are about to solve into x we don't care about setting the original values.
// In this case, we are allocating so we first make the memory via update_dst_size.
// Then we only copy from the source if bInitialize is true.
// bAssigned:
// bAssigned tells the caller if the data was simply assigned, so it is set false in this case.
template<class dst_t, class src_t> // actual implementation
void deep_copy_only(bool bInitialize, dst_t & dst, const src_t & src, bool & bAssigned) {
update_dst_size(dst, src); // allocates if necessary
if(bInitialize) { // bInitialize false would be for solver getting x, where the actual values are not needed
Kokkos::deep_copy(dst, src); // full copy
}
bAssigned = false;
}

template<class dst_t, class src_t> // actual implementation
void deep_copy_only(dst_t & dst, const src_t & src) {
bool bAssigned;
deep_copy_only(true, dst, src, bAssigned);
}

// now handle type mismatch for same memory space - now types are different
// bInitialize:
// If bInitialize is false, then the data needs to be allocated but not initialized.
Expand Down
6 changes: 4 additions & 2 deletions packages/amesos2/src/Amesos2_TpetraMultiVecAdapter_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ namespace Amesos2 {
if ( num_vecs == 1 && this->getComm()->getRank() == 0 && this->getComm()->getSize() == 1 ) {
if(mv_->isConstantStride()) {
bool bAssigned;
deep_copy_or_assign_view(bInitialize, kokkos_view, mv_->getLocalViewDevice(Tpetra::Access::ReadOnly), bAssigned);
//deep_copy_or_assign_view(bInitialize, kokkos_view, mv_->getLocalViewDevice(Tpetra::Access::ReadOnly), bAssigned);
deep_copy_only(bInitialize, kokkos_view, mv_->getLocalViewDevice(Tpetra::Access::ReadOnly), bAssigned);
return bAssigned; // if bAssigned is true we are accessing the mv data directly without a copy
}
else {
Expand Down Expand Up @@ -525,7 +526,8 @@ namespace Amesos2 {

// If this is the optimized path then kokkos_new_data will be the dst
auto mv_view_to_modify_2d = mv_->getLocalViewDevice(Tpetra::Access::OverwriteAll);
deep_copy_or_assign_view(mv_view_to_modify_2d, kokkos_new_data);
//deep_copy_or_assign_view(mv_view_to_modify_2d, kokkos_new_data);
deep_copy_only(mv_view_to_modify_2d, kokkos_new_data);
}
else {

Expand Down

0 comments on commit 8b4b0b4

Please sign in to comment.