Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_Gemv_Team_Impl.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 #ifndef KOKKOSBATCHED_GEMV_TEAM_IMPL_HPP
17 #define KOKKOSBATCHED_GEMV_TEAM_IMPL_HPP
18
19 /// \author Kyungjoo Kim ([email protected])
20
21 #include "KokkosBatched_Util.hpp"
22 #include "KokkosBatched_Gemv_Team_Internal.hpp"
23 #include "KokkosBlas2_team_gemv.hpp"
24 #include <Kokkos_DynRankView.hpp>
25
26 namespace KokkosBatched {
27
28 ///
29 /// Team Impl
30 /// =========
31
32 ///
33 /// Implemented:
34 /// NT, T
35 ///
36 /// Not yet implemented
37 /// CT
38
39 ///
40 /// NT
41 ///
42
43 template <typename MemberType>
44 struct TeamGemv<MemberType, Trans::NoTranspose, Algo::Gemv::Unblocked> {
45 template <typename ScalarType, typename AViewType, typename xViewType, typename yViewType>
46 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
47 const xViewType &x, const ScalarType beta, const yViewType &y) {
48 if constexpr (Kokkos::is_dyn_rank_view<AViewType>::value) {
49 assert(A.rank_dynamic() == 3 &&
50 "Batched TeamGemv requires rank-3 A matrix (use "
51 "KokkosBlas::TeamGemv for regular rank-2 matrix)");
52 } else {
53 static_assert(AViewType::rank == 3,
54 "Batched TeamGemv requires rank-3 A matrix (use "
55 "KokkosBlas::TeamGemv for regular rank-2 matrix)");
56 }
57
58 if (A.extent(0) == 1) {
59 KokkosBlas::TeamGemv<MemberType, Trans::NoTranspose, Algo::Gemv::Unblocked>::invoke(
60 member, alpha, Kokkos::subview(A, 0, Kokkos::ALL, Kokkos::ALL), Kokkos::subview(x, 0, Kokkos::ALL), beta,
61 Kokkos::subview(y, 0, Kokkos::ALL));
62 return 0;
63 }
64 return TeamGemvInternal<Algo::Gemv::Unblocked>::template invoke<
65 MemberType, ScalarType, typename AViewType::array_layout, typename AViewType::non_const_value_type>(
66 member, A.extent(0), A.extent(1), A.extent(2), alpha, A.data(), A.stride_0(), A.stride_1(), A.stride_2(),
67 x.data(), x.stride_0(), x.stride_1(), beta, y.data(), y.stride_0(), y.stride_1());
68 }
69 };
70
71 template <typename MemberType>
72 struct TeamGemv<MemberType, Trans::NoTranspose, Algo::Gemv::Blocked> {
73 template <typename ScalarType, typename AViewType, typename xViewType, typename yViewType>
74 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType & /*member*/, const ScalarType /*alpha*/,
75 const AViewType & /*A*/, const xViewType & /*x*/, const ScalarType /*beta*/,
76 const yViewType & /*y*/) {
77 /* if constexpr (Kokkos::is_dyn_rank_view<AViewType>::value) {
78 assert(A.rank_dynamic() == 3 &&
79 "Batched TeamGemv requires rank-3 A matrix (use "
80 "KokkosBlas::TeamGemv for regular rank-2 matrix)");
81 } else {
82 static_assert(AViewType::rank == 3,
83 "Batched TeamGemv requires rank-3 A matrix (use "
84 "KokkosBlas::TeamGemv for regular rank-2 matrix)");
85 } */
86 Kokkos::abort(
87 "KokkosBlas::TeamGemv<Algo::Gemv::Blocked> for rank-3 matrix is NOT "
88 "implemented");
89 }
90 };
91
92 ///
93 /// T
94 ///
95
96 template <typename MemberType>
97 struct TeamGemv<MemberType, Trans::Transpose, Algo::Gemv::Unblocked> {
98 template <typename ScalarType, typename AViewType, typename xViewType, typename yViewType>
99 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
100 const xViewType &x, const ScalarType beta, const yViewType &y) {
101 if constexpr (Kokkos::is_dyn_rank_view<AViewType>::value) {
102 assert(A.rank_dynamic() == 3 &&
103 "Batched TeamGemv requires rank-3 A matrix (use "
104 "KokkosBlas::TeamGemv for regular rank-2 matrix)");
105 } else {
106 static_assert(AViewType::rank == 3,
107 "Batched TeamGemv requires rank-3 A matrix (use "
108 "KokkosBlas::TeamGemv for regular rank-2 matrix)");
109 }
110 if (A.extent(0) == 1) {
111 KokkosBlas::TeamGemv<MemberType, Trans::Transpose, Algo::Gemv::Unblocked>::invoke(
112 member, alpha, Kokkos::subview(A, 0, Kokkos::ALL, Kokkos::ALL), Kokkos::subview(x, 0, Kokkos::ALL), beta,
113 Kokkos::subview(y, 0, Kokkos::ALL));
114 return 0;
115 }
116 return TeamGemvInternal<Algo::Gemv::Unblocked>::template invoke<
117 MemberType, ScalarType, typename AViewType::array_layout, typename AViewType::non_const_value_type>(
118 member, A.extent(0), A.extent(2), A.extent(1), alpha, A.data(), A.stride_0(), A.stride_2(), A.stride_1(),
119 x.data(), x.stride_0(), x.stride_1(), beta, y.data(), y.stride_0(), y.stride_1());
120 }
121 };
122
123 template <typename MemberType>
124 struct TeamGemv<MemberType, Trans::Transpose, Algo::Gemv::Blocked> {
125 template <typename ScalarType, typename AViewType, typename xViewType, typename yViewType>
126 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType & /*member*/, const ScalarType /*alpha*/,
127 const AViewType & /*A*/, const xViewType & /*x*/, const ScalarType /*beta*/,
128 const yViewType & /*y*/) {
129 /* if constexpr (Kokkos::is_dyn_rank_view<AViewType>::value) {
130 assert(A.rank_dynamic() == 3 &&
131 "Batched TeamGemv requires rank-3 A matrix (use "
132 "KokkosBlas::TeamGemv for regular rank-2 matrix)");
133 } else {
134 static_assert(AViewType::rank == 3,
135 "Batched TeamGemv requires rank-3 A matrix (use "
136 "KokkosBlas::TeamGemv for regular rank-2 matrix)");
137 } */
138 Kokkos::abort(
139 "KokkosBlas::TeamGemv<Algo::Gemv::Blocked> for rank-3 matrix is NOT "
140 "implemented");
141 }
142 };
143
144 } // namespace KokkosBatched
145
146 #endif