Debian Codegraph @

packages/kokkos-kernels/perf_test/batched/sparse/CG/Functor_TestBatchedTeamVectorCG_1.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_1 {
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_1(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 auto d = Kokkos::subview(_D, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL);
48 auto x = Kokkos::subview(_X, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL);
49 auto b = Kokkos::subview(_B, Kokkos::make_pair(first_matrix, last_matrix), Kokkos::ALL);
50
51 using Operator = KokkosBatched::CrsMatrix<ValuesViewType, IntView>;
52
53 Operator A(d, _r, _c);
54
55 KokkosBatched::TeamVectorCG<MemberType>::template invoke<Operator, VectorViewType>(member, A, b, x, _handle);
56 }
57
58 inline double run() {
59 std::string name("KokkosBatched::Test::TeamCG");
60 Kokkos::Timer timer;
61 Kokkos::Profiling::pushRegion(name.c_str());
62
63 _handle.set_memory_strategy(1);
64
65 _handle.tmp_view = typename KrylovHandleType::TemporaryViewType("", _X.extent(0), 4 * _X.extent(1));
66
67 Kokkos::TeamPolicy<DeviceType> auto_policy(_handle.get_number_of_teams(), Kokkos::AUTO(), Kokkos::AUTO());
68 Kokkos::TeamPolicy<DeviceType> tuned_policy(_handle.get_number_of_teams(), _team_size, _vector_length);
69 Kokkos::TeamPolicy<DeviceType> policy;
70
71 if (_team_size < 1)
72 policy = auto_policy;
73 else
74 policy = tuned_policy;
75
76 size_t bytes_0 = ValuesViewType::shmem_size(_N_team, 5);
77 policy.set_scratch_size(0, Kokkos::PerTeam(bytes_0));
78
79 timer.reset();
80 Kokkos::parallel_for(name.c_str(), policy, *this);
81 exec_space().fence();
82 double sec = timer.seconds();
83 Kokkos::Profiling::popRegion();
84
85 return sec;
86 }
87 };