Debian Codegraph @

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