From 9a81eeec73c14c429850113a5547203ed86d6cce Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Tue, 21 Jan 2025 00:45:38 +0900 Subject: [PATCH] unuse getrf in the getrs analytical test Signed-off-by: Yuuichi Asahi --- .../unit_test/Test_Batched_SerialGetrs.hpp | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/batched/dense/unit_test/Test_Batched_SerialGetrs.hpp b/batched/dense/unit_test/Test_Batched_SerialGetrs.hpp index da499139b5..22f4ff58a2 100644 --- a/batched/dense/unit_test/Test_Batched_SerialGetrs.hpp +++ b/batched/dense/unit_test/Test_Batched_SerialGetrs.hpp @@ -33,7 +33,7 @@ struct ParamTag { using trans = T; }; -template +template struct Functor_BatchedSerialGetrf { using execution_space = typename DeviceType::execution_space; AViewType m_a; @@ -47,7 +47,7 @@ struct Functor_BatchedSerialGetrf { auto aa = Kokkos::subview(m_a, k, Kokkos::ALL(), Kokkos::ALL()); auto ipiv = Kokkos::subview(m_ipiv, k, Kokkos::ALL()); - KokkosBatched::SerialGetrf::invoke(aa, ipiv); + KokkosBatched::SerialGetrf::invoke(aa, ipiv); } inline void run() { @@ -137,6 +137,10 @@ struct Functor_BatchedSerialGemv { /// This corresponds to the following system of equations: /// x0 + x1 = 2 /// x0 - x1 = 0 +/// We confirm this with the factorized matrix LU and pivot given by +/// LU: [[1, 1], +/// [1, -2]] +/// piv: [0, 1] /// /// \param N [in] Batch size of RHS (banded matrix can also be batched matrix) /// \param k [in] Number of superdiagonals or subdiagonals of matrix A @@ -150,17 +154,19 @@ void impl_test_batched_getrs_analytical(const int N) { using PivView2DType = Kokkos::View; const int BlkSize = 2; - View3DType A("A", N, BlkSize, BlkSize), ref("Ref", N, BlkSize, BlkSize); - View3DType lu("lu", N, BlkSize, BlkSize); // Factorized - View2DType x("x", N, BlkSize), y("y", N, BlkSize), x_ref("x_ref", N, BlkSize); // Solutions + View3DType LU("LU", N, BlkSize, BlkSize); // Factorized matrix of A + View2DType x("x", N, BlkSize), x_ref("x_ref", N, BlkSize); // Solutions PivView2DType ipiv("ipiv", N, BlkSize); - auto h_A = Kokkos::create_mirror_view(A); + auto h_LU = Kokkos::create_mirror_view(LU); + auto h_ipiv = Kokkos::create_mirror_view(ipiv); auto h_x = Kokkos::create_mirror_view(x); auto h_x_ref = Kokkos::create_mirror_view(x_ref); - Kokkos::deep_copy(h_A, 1.0); + Kokkos::deep_copy(h_LU, 1.0); for (int ib = 0; ib < N; ib++) { - h_A(ib, 1, 1) = -1.0; + h_LU(ib, 1, 1) = -2.0; + h_ipiv(ib, 0) = 0; + h_ipiv(ib, 1) = 1; h_x(ib, 0) = 2; h_x(ib, 1) = 0; @@ -168,17 +174,13 @@ void impl_test_batched_getrs_analytical(const int N) { h_x_ref(ib, 1) = 1; } - Kokkos::fence(); - - Kokkos::deep_copy(A, h_A); + Kokkos::deep_copy(LU, h_LU); + Kokkos::deep_copy(ipiv, h_ipiv); Kokkos::deep_copy(x, h_x); - // getrf to factorize matrix A = P * L * U - Functor_BatchedSerialGetrf(A, ipiv).run(); - // getrs (Note, LU is a factorized matrix of A) auto info = Functor_BatchedSerialGetrs( - A, ipiv, x) + LU, ipiv, x) .run(); Kokkos::fence(); @@ -226,7 +228,7 @@ void impl_test_batched_getrs(const int N, const int BlkSize) { Kokkos::deep_copy(b, x); // getrf to factorize matrix A = P * L * U - Functor_BatchedSerialGetrf(LU, ipiv).run(); + Functor_BatchedSerialGetrf(LU, ipiv).run(); // getrs (Note, LU is a factorized matrix of A) auto info = Functor_BatchedSerialGetrs( @@ -317,19 +319,19 @@ TEST_F(TestCategory, test_batched_getrs_t_double) { #endif #if defined(KOKKOSKERNELS_INST_COMPLEX_FLOAT) -TEST_F(TestCategory, test_batched_getrs_nt_cfloat) { +TEST_F(TestCategory, test_batched_getrs_nt_fcomplex) { using param_tag_type = ::Test::Getrs::ParamTag; using algo_tag_type = typename Algo::Getrs::Unblocked; test_batched_getrs, param_tag_type, algo_tag_type>(); } -TEST_F(TestCategory, test_batched_getrs_t_cfloat) { +TEST_F(TestCategory, test_batched_getrs_t_fcomplex) { using param_tag_type = ::Test::Getrs::ParamTag; using algo_tag_type = typename Algo::Getrs::Unblocked; test_batched_getrs, param_tag_type, algo_tag_type>(); } -TEST_F(TestCategory, test_batched_getrs_c_cfloat) { +TEST_F(TestCategory, test_batched_getrs_c_fcomplex) { using param_tag_type = ::Test::Getrs::ParamTag; using algo_tag_type = typename Algo::Getrs::Unblocked; @@ -338,19 +340,19 @@ TEST_F(TestCategory, test_batched_getrs_c_cfloat) { #endif #if defined(KOKKOSKERNELS_INST_COMPLEX_DOUBLE) -TEST_F(TestCategory, test_batched_getrs_nt_dfloat) { +TEST_F(TestCategory, test_batched_getrs_nt_dcomplex) { using param_tag_type = ::Test::Getrs::ParamTag; using algo_tag_type = typename Algo::Getrs::Unblocked; test_batched_getrs, param_tag_type, algo_tag_type>(); } -TEST_F(TestCategory, test_batched_getrs_t_dfloat) { +TEST_F(TestCategory, test_batched_getrs_t_dcomplex) { using param_tag_type = ::Test::Getrs::ParamTag; using algo_tag_type = typename Algo::Getrs::Unblocked; test_batched_getrs, param_tag_type, algo_tag_type>(); } -TEST_F(TestCategory, test_batched_getrs_c_dfloat) { +TEST_F(TestCategory, test_batched_getrs_c_dcomplex) { using param_tag_type = ::Test::Getrs::ParamTag; using algo_tag_type = typename Algo::Getrs::Unblocked;