-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Pull Request #9739 from rppawlo/Trilinos/phalanx-const-nonconst
Automatically Merged using Trilinos Pull Request AutoTester PR Title: Phalanx: add conversion utility PR Author: rppawlo
- Loading branch information
Showing
3 changed files
with
74 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/phalanx/src/Phalanx_GetNonConstDynRankViewFromConstMDField.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef PHALANX_GET_NON_CONST_DYN_RANK_VIEW_FROM_CONST_MDFIELD_HPP | ||
#define PHALANX_GET_NON_CONST_DYN_RANK_VIEW_FROM_CONST_MDFIELD_HPP | ||
|
||
#include "Phalanx_MDField.hpp" | ||
#include "Kokkos_DynRankView.hpp" | ||
#include "Teuchos_Assert.hpp" | ||
|
||
namespace PHX { | ||
|
||
template<typename Scalar,typename...Props> | ||
Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged> | ||
getNonConstDynRankViewFromConstMDField(const PHX::MDField<const Scalar,Props...>& f) { | ||
|
||
using drv_type = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>; | ||
using nonconst_data_type = typename Sacado::ScalarType< typename drv_type::value_type >::type*; | ||
const int rank = f.rank(); | ||
Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged> tmp; | ||
|
||
#ifdef PHX_DEBUG | ||
TEUCHOS_ASSERT( (rank > 0) && (rank < 6) ); | ||
#endif | ||
|
||
if (Sacado::IsFad<Scalar>::value) { | ||
const int num_derivatives = Kokkos::dimension_scalar(f.get_static_view()); | ||
if (rank==1) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0),num_derivatives); | ||
else if (rank==2) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0),f.extent(1),num_derivatives); | ||
else if (rank==3) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0),f.extent(1),f.extent(2),num_derivatives); | ||
else if (rank==4) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0),f.extent(1),f.extent(2),f.extent(3),num_derivatives); | ||
else if (rank==5) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0),f.extent(1),f.extent(2),f.extent(3),f.extent(4),num_derivatives); | ||
} | ||
else { | ||
if (rank==1) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0)); | ||
else if (rank==2) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0),f.extent(1)); | ||
else if (rank==3) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0),f.extent(1),f.extent(2)); | ||
else if (rank==4) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0),f.extent(1),f.extent(2),f.extent(3)); | ||
else if (rank==5) | ||
tmp = Kokkos::DynRankView<Scalar,typename PHX::DevLayout<Scalar>::type,Kokkos::MemoryUnmanaged>(const_cast<nonconst_data_type>(f.get_static_view().data()),f.extent(0),f.extent(1),f.extent(2),f.extent(3),f.extent(4)); | ||
} | ||
|
||
return tmp; | ||
} | ||
|
||
} // namespace PHX | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters