| 1 |
//@HEADER |
| 2 |
// ************************************************************************ |
| 3 |
// |
| 4 |
// Kokkos v. 4.0 |
| 5 |
// Copyright (2022) National Technology & Engineering |
| 6 |
// Solutions of Sandia, LLC (NTESS). |
| 7 |
// |
| 8 |
// Under the terms of Contract DE-NA0003525 with NTESS, |
| 9 |
// the U.S. Government retains certain rights in this software. |
| 10 |
// |
| 11 |
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
// See https://kokkos.org/LICENSE for license information. |
| 13 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 |
// |
| 15 |
//@HEADER |
| 16 |
|
| 17 |
template <typename DeviceType, typename ValuesViewType, typename IntView, typename VectorViewType, |
| 18 |
typename KrylovHandleType, bool UsePrec> |
| 19 |
struct Functor_TestBatchedTeamVectorGMRES_1 { |
| 20 |
const ValuesViewType _D; |
| 21 |
const ValuesViewType _diag; |
| 22 |
const IntView _r; |
| 23 |
const IntView _c; |
| 24 |
const VectorViewType _X; |
| 25 |
const VectorViewType _B; |
| 26 |
const int _N_team, _team_size, _vector_length; |
| 27 |
const int _N_iteration; |
| 28 |
const double _tol; |
| 29 |
const int _ortho_strategy; |
| 30 |
const int _arnoldi_level; |
| 31 |
const int _other_level; |
| 32 |
KrylovHandleType _handle; |
| 33 |
|
| 34 |
KOKKOS_INLINE_FUNCTION |
| 35 |
Functor_TestBatchedTeamVectorGMRES_1(const ValuesViewType &D, const IntView &r, const IntView &c, |
| 36 |
const VectorViewType &X, const VectorViewType &B, const int N_team, |
| 37 |
const int team_size, const int vector_length, const int N_iteration, |
| 38 |
const double tol, const int ortho_strategy, const int arnoldi_level, |
| 39 |
const int other_level, KrylovHandleType &handle) |
| 40 |
: _D(D), |
| 41 |
_r(r), |
| 42 |
_c(c), |
| 43 |
_X(X), |
| 44 |
_B(B), |
| 45 |
_N_team(N_team), |
| 46 |
_team_size(team_size), |
| 47 |
_vector_length(vector_length), |
| 48 |
_N_iteration(N_iteration), |
| 49 |
_tol(tol), |
| 50 |
_ortho_strategy(ortho_strategy), |
| 51 |
_arnoldi_level(arnoldi_level), |
| 52 |
_other_level(other_level), |
| 53 |
_handle(handle) {} |
| 54 |
|
| 55 |
KOKKOS_INLINE_FUNCTION |
| 56 |
Functor_TestBatchedTeamVectorGMRES_1(const ValuesViewType &D, const ValuesViewType &diag, const IntView &r, |
| 57 |
const IntView &c, const VectorViewType &X, const VectorViewType &B, |
| 58 |
const int N_team, const int team_size, const int vector_length, |
| 59 |
const int N_iteration, const double tol, int ortho_strategy, |
| 60 |
const int arnoldi_level, const int other_level, KrylovHandleType &handle) |
| 61 |
: _D(D), |
| 62 |
_diag(diag), |
| 63 |
_r(r), |
| 64 |
_c(c), |
| 65 |
_X(X), |
| 66 |
_B(B), |
| 67 |
_N_team(N_team), |
| 68 |
_team_size(team_size), |
| 69 |
_vector_length(vector_length), |
| 70 |
_N_iteration(N_iteration), |
| 71 |
_tol(tol), |
| 72 |
_ortho_strategy(ortho_strategy), |
| 73 |
_arnoldi_level(arnoldi_level), |
| 74 |
_other_level(other_level), |
| 75 |
_handle(handle) {} |
| 76 |
|
| 77 |
template <typename MemberType> |
| 78 |
KOKKOS_INLINE_FUNCTION void operator()(const MemberType &member) const { |
| 79 |
const int first_matrix = _handle.first_index(member.league_rank()); |
| 80 |
const int last_matrix = _handle.last_index(member.league_rank()); |
| 81 |
|
| 82 |
auto d = Kokkos::subview(_D, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL); |
| 83 |
auto x = Kokkos::subview(_X, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL); |
| 84 |
auto b = Kokkos::subview(_B, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL); |
| 85 |
|
| 86 |
using Operator = KokkosBatched::CrsMatrix<ValuesViewType, IntView>; |
| 87 |
|
| 88 |
Operator A(d, _r, _c); |
| 89 |
|
| 90 |
if (UsePrec) { |
| 91 |
auto diag = Kokkos::subview(_diag, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL); |
| 92 |
using PrecOperator = KokkosBatched::JacobiPrec<VectorViewType>; |
| 93 |
|
| 94 |
PrecOperator P(diag); |
| 95 |
P.setComputedInverse(); |
| 96 |
|
| 97 |
KokkosBatched::TeamVectorGMRES<MemberType>::template invoke<Operator, VectorViewType, PrecOperator, |
| 98 |
KrylovHandleType>(member, A, b, x, P, _handle); |
| 99 |
} else { |
| 100 |
KokkosBatched::TeamVectorGMRES<MemberType>::template invoke<Operator, VectorViewType>(member, A, b, x, _handle); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
inline double run() { |
| 105 |
std::string name("KokkosBatched::Test::TeamVectorGMRES"); |
| 106 |
Kokkos::Timer timer; |
| 107 |
Kokkos::Profiling::pushRegion(name.c_str()); |
| 108 |
|
| 109 |
int maximum_iteration = _handle.get_max_iteration(); |
| 110 |
|
| 111 |
_handle.set_memory_strategy(1); |
| 112 |
|
| 113 |
_handle.tmp_view = |
| 114 |
typename KrylovHandleType::TemporaryViewType("", _X.extent(0), _X.extent(1) + maximum_iteration + 3); |
| 115 |
|
| 116 |
Kokkos::TeamPolicy<DeviceType> auto_policy(_handle.get_number_of_teams(), Kokkos::AUTO(), Kokkos::AUTO()); |
| 117 |
Kokkos::TeamPolicy<DeviceType> tuned_policy(_handle.get_number_of_teams(), _team_size, _vector_length); |
| 118 |
Kokkos::TeamPolicy<DeviceType> policy; |
| 119 |
|
| 120 |
if (_team_size < 1) |
| 121 |
policy = auto_policy; |
| 122 |
else |
| 123 |
policy = tuned_policy; |
| 124 |
|
| 125 |
exec_space().fence(); |
| 126 |
timer.reset(); |
| 127 |
Kokkos::parallel_for(name.c_str(), policy, *this); |
| 128 |
exec_space().fence(); |
| 129 |
double sec = timer.seconds(); |
| 130 |
Kokkos::Profiling::popRegion(); |
| 131 |
|
| 132 |
return sec; |
| 133 |
} |
| 134 |
}; |