Skip to content

Commit

Permalink
working on tohost
Browse files Browse the repository at this point in the history
  • Loading branch information
MMRROOO committed Feb 14, 2024
1 parent c5d55d5 commit b2b00b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions MParT/Utilities/ArrayConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ namespace mpart{
@param[in] inview A kokkos array in device memory.
@return A kokkos array in host memory. Note that the layout (row-major or col-major) might be different than the default on the Host. The layout will match the device's default layout.
*/
template<typename DeviceMemoryType, typename ScalarType>
typename Kokkos::View<ScalarType,Kokkos::HostSpace>::HostMirror ToHost(Kokkos::View<ScalarType,DeviceMemoryType> const& inview){
typename Kokkos::View<ScalarType,DeviceMemoryType>::HostMirror outview = Kokkos::create_mirror_view(inview);
template<typename ScalarType, typename DeviceMemorySpace>
typename Kokkos::View<ScalarType, Kokkos::HostSpace>::HostMirror ToHost(Kokkos::View<ScalarType, DeviceMemorySpace> const& inview){
typename Kokkos::View<ScalarType, Kokkos::HostSpace>::HostMirror outview = Kokkos::create_mirror_view(inview);
Kokkos::deep_copy (outview, inview);
return outview;
}

template<typename DeviceMemoryType, typename ScalarType>
template<typename DeviceMemoryType,typename ScalarType>
StridedMatrix<ScalarType, Kokkos::HostSpace> ToHost(StridedMatrix<ScalarType,DeviceMemoryType> const& inview){
typename StridedMatrix<ScalarType,DeviceMemoryType>::HostMirror outview = Kokkos::create_mirror_view(inview);
Kokkos::deep_copy (outview, inview);
Expand Down
10 changes: 5 additions & 5 deletions tests/Test_LinearAlgebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ TEST_CASE( "Testing LU Factorization on Device", "LinearAlgebra_LUDevice" ) {
}
SECTION("Solve LU out of place") {
PartialPivLU<mpart::DeviceSpace> Alu_d(constA_d);
auto C_d = Alu.solve(B_d);
auto C_d = Alu_d.solve(B_d);
auto C_h = ToHost(C_d);
for(unsigned int j=0; j<C_h.extent(1); ++j){
for(unsigned int i=0; i<C_h.extent(0); ++i){
Expand All @@ -417,9 +417,9 @@ TEST_CASE( "Testing Cholesky Factorization", "LinearAlgebra_Cholesky" ) {

Kokkos::View<const double**, Kokkos::LayoutLeft, Kokkos::HostSpace> constA_h = A;
auto constA_d = ToDevice<mpart::DeviceSpace>(constA_h);
auto B_d = ToDevice<mpart::DeviceSpace>(B);
auto B_d = ToDevice<mpart::DeviceSpace>(B_h);
auto eigA = ConstKokkosToMat(constA_h);
auto eigB = KokkosToMat(B);
auto eigB = KokkosToMat(B_h);
Eigen::MatrixXd eigX = eigA.llt().solve(eigB);
Eigen::MatrixXd eigY = eigA.llt().matrixL().solve(eigB);

Expand Down Expand Up @@ -452,7 +452,7 @@ TEST_CASE( "Testing Cholesky Factorization", "LinearAlgebra_Cholesky" ) {
}
SECTION("Solve Cholesky out of place") {
Cholesky<Kokkos::HostSpace> Achol_d(constA_d);
auto C_d = Achol.solve(B_d);
auto C_d = Achol_d.solve(B_d);
auto C_h = ToHost(C_d);
for(unsigned int j=0; j<C_h.extent(1); ++j){
for(unsigned int i=0; i<C_h.extent(0); ++i){
Expand All @@ -465,4 +465,4 @@ TEST_CASE( "Testing Cholesky Factorization", "LinearAlgebra_Cholesky" ) {
CHECK(Achol_d.determinant() == Approx(eigA.determinant()).epsilon(1e-14).margin(1e-14));
}
}
#endif
#endif

0 comments on commit b2b00b0

Please sign in to comment.