Debian Codegraph @

packages/kokkos-kernels/perf_test/batched/sparse/CG/Functor_TestBatchedTeamVectorCG_2.hpp

raw
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>
19 struct Functor_TestBatchedTeamVectorCG_2 {
20 const ValuesViewType _D;
21 const IntView _r;
22 const IntView _c;
23 const VectorViewType _X;
24 const VectorViewType _B;
25 const int _N_team, _team_size, _vector_length;
26 KrylovHandleType _handle;
27
28 KOKKOS_INLINE_FUNCTION
29 Functor_TestBatchedTeamVectorCG_2(const ValuesViewType &D, const IntView &r, const IntView &c,
30 const VectorViewType &X, const VectorViewType &B, const int N_team,
31 const int team_size, const int vector_length, KrylovHandleType &handle)
32 : _D(D),
33 _r(r),
34 _c(c),
35 _X(X),
36 _B(B),
37 _N_team(N_team),
38 _team_size(team_size),
39 _vector_length(vector_length),
40 _handle(handle) {}
41
42 template <typename MemberType>
43 KOKKOS_INLINE_FUNCTION void operator()(const MemberType &member) const {
44 const int first_matrix = _handle.first_index(member.league_rank());
45 const int last_matrix = _handle.last_index(member.league_rank());
46
47 using TeamVectorCopy1D = KokkosBatched::TeamVectorCopy<MemberType, KokkosBatched::Trans::NoTranspose, 1>;
48
49 auto d = Kokkos::subview(_D, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL);
50 auto x = Kokkos::subview(_X, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL);
51 auto b = Kokkos::subview(_B, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL);
52
53 using ScratchPadIntViewType = Kokkos::View<typename IntView::non_const_value_type *, typename IntView::array_layout,
54 typename IntView::execution_space::scratch_memory_space>;
55
56 using Operator = KokkosBatched::CrsMatrix<ValuesViewType, ScratchPadIntViewType>;
57
58 ScratchPadIntViewType tmp_1D_int(member.team_scratch(0), _r.extent(0) + _c.extent(0));
59
60 auto r = Kokkos::subview(tmp_1D_int, Kokkos::make_pair(0, (int)_r.extent(0)));
61 auto c = Kokkos::subview(tmp_1D_int, Kokkos::make_pair((int)_r.extent(0), (int)tmp_1D_int.extent(0)));
62
63 TeamVectorCopy1D::invoke(member, _r, r);
64 TeamVectorCopy1D::invoke(member, _c, c);
65 Operator A(d, r, c);
66
67 KokkosBatched::TeamVectorCG<MemberType>::template invoke<Operator, VectorViewType>(member, A, b, x, _handle);
68 }
69
70 inline double run() {
71 std::string name("KokkosBatched::Test::TeamCG");
72 Kokkos::Timer timer;
73 Kokkos::Profiling::pushRegion(name.c_str());
74
75 _handle.set_memory_strategy(1);
76
77 _handle.tmp_view = typename KrylovHandleType::TemporaryViewType("", _X.extent(0), 4 * _X.extent(1));
78
79 Kokkos::TeamPolicy<DeviceType> auto_policy(_handle.get_number_of_teams(), Kokkos::AUTO(), Kokkos::AUTO());
80 Kokkos::TeamPolicy<DeviceType> tuned_policy(_handle.get_number_of_teams(), _team_size, _vector_length);
81 Kokkos::TeamPolicy<DeviceType> policy;
82
83 if (_team_size < 1)
84 policy = auto_policy;
85 else
86 policy = tuned_policy;
87
88 size_t bytes_row_ptr = IntView::shmem_size(_r.extent(0));
89 size_t bytes_col_idc = IntView::shmem_size(_c.extent(0));
90 size_t bytes_int = bytes_row_ptr + bytes_col_idc;
91 size_t bytes_0 = ValuesViewType::shmem_size(_N_team, 5);
92
93 policy.set_scratch_size(0, Kokkos::PerTeam(bytes_int + bytes_0));
94
95 timer.reset();
96 Kokkos::parallel_for(name.c_str(), policy, *this);
97 exec_space().fence();
98 double sec = timer.seconds();
99 Kokkos::Profiling::popRegion();
100
101 return sec;
102 }
103 };