Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_Gemm_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_GEMM_TEAM_IMPL_HPP
17 #define KOKKOSBATCHED_GEMM_TEAM_IMPL_HPP
18
19 /// \author Kyungjoo Kim ([email protected])
20
21 #include "KokkosBatched_Util.hpp"
22 #include "KokkosBatched_Gemm_Team_Internal.hpp"
23
24 namespace KokkosBatched {
25
26 ///
27 /// Team Impl
28 /// =========
29
30 ///
31 /// Implemented:
32 /// NT/NT, T/NT, NT/T, T/T
33 ///
34 /// Not yet implemented (ConjTranspose)
35 /// CT/NT, NT/CT, CT/CT
36 ///
37
38 ///
39 /// NT/NT
40 ///
41
42 template <typename MemberType>
43 struct TeamGemm<MemberType, Trans::NoTranspose, Trans::NoTranspose, Algo::Gemm::Unblocked> {
44 template <typename ScalarType, typename AViewType, typename BViewType, typename CViewType>
45 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
46 const BViewType &B, const ScalarType beta, const CViewType &C) {
47 // C = beta C + alpha A B
48 // C (m x n), A(m x k), B(k x n)
49 return TeamGemmInternal<Algo::Gemm::Unblocked>::invoke(member, C.extent(0), C.extent(1), A.extent(1), alpha,
50 A.data(), A.stride_0(), A.stride_1(), B.data(), B.stride_0(),
51 B.stride_1(), beta, C.data(), C.stride_0(), C.stride_1());
52 }
53 };
54
55 template <typename MemberType>
56 struct TeamGemm<MemberType, Trans::NoTranspose, Trans::NoTranspose, Algo::Gemm::Blocked> {
57 template <typename ScalarType, typename AViewType, typename BViewType, typename CViewType>
58 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
59 const BViewType &B, const ScalarType beta, const CViewType &C) {
60 // C = beta C + alpha A B
61 // C (m x n), A(m x k), B(k x n)
62 return TeamGemmInternal<Algo::Gemm::Blocked>::invoke(member, C.extent(0), C.extent(1), A.extent(1), alpha, A.data(),
63 A.stride_0(), A.stride_1(), B.data(), B.stride_0(),
64 B.stride_1(), beta, C.data(), C.stride_0(), C.stride_1());
65 }
66 };
67
68 ///
69 /// T/NT
70 ///
71
72 template <typename MemberType>
73 struct TeamGemm<MemberType, Trans::Transpose, Trans::NoTranspose, Algo::Gemm::Unblocked> {
74 template <typename ScalarType, typename AViewType, typename BViewType, typename CViewType>
75 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
76 const BViewType &B, const ScalarType beta, const CViewType &C) {
77 // C = beta C + alpha A B
78 // C (m x n), A(m x k), B(k x n)
79 return TeamGemmInternal<Algo::Gemm::Unblocked>::invoke(member, C.extent(0), C.extent(1), A.extent(0), alpha,
80 A.data(), A.stride_1(), A.stride_0(), B.data(), B.stride_0(),
81 B.stride_1(), beta, C.data(), C.stride_0(), C.stride_1());
82 }
83 };
84
85 template <typename MemberType>
86 struct TeamGemm<MemberType, Trans::Transpose, Trans::NoTranspose, Algo::Gemm::Blocked> {
87 template <typename ScalarType, typename AViewType, typename BViewType, typename CViewType>
88 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
89 const BViewType &B, const ScalarType beta, const CViewType &C) {
90 // C = beta C + alpha A B
91 // C (m x n), A(m x k), B(k x n)
92 return TeamGemmInternal<Algo::Gemm::Blocked>::invoke(member, C.extent(0), C.extent(1), A.extent(0), alpha, A.data(),
93 A.stride_1(), A.stride_0(), B.data(), B.stride_0(),
94 B.stride_1(), beta, C.data(), C.stride_0(), C.stride_1());
95 }
96 };
97
98 ///
99 /// NT/T
100 ///
101
102 template <typename MemberType>
103 struct TeamGemm<MemberType, Trans::NoTranspose, Trans::Transpose, Algo::Gemm::Unblocked> {
104 template <typename ScalarType, typename AViewType, typename BViewType, typename CViewType>
105 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
106 const BViewType &B, const ScalarType beta, const CViewType &C) {
107 // C = beta C + alpha A B
108 // C (m x n), A(m x k), B(k x n)
109 return TeamGemmInternal<Algo::Gemm::Unblocked>::invoke(member, C.extent(0), C.extent(1), A.extent(1), alpha,
110 A.data(), A.stride_0(), A.stride_1(), B.data(), B.stride_1(),
111 B.stride_0(), beta, C.data(), C.stride_0(), C.stride_1());
112 }
113 };
114
115 template <typename MemberType>
116 struct TeamGemm<MemberType, Trans::NoTranspose, Trans::Transpose, Algo::Gemm::Blocked> {
117 template <typename ScalarType, typename AViewType, typename BViewType, typename CViewType>
118 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
119 const BViewType &B, const ScalarType beta, const CViewType &C) {
120 // C = beta C + alpha A B
121 // C (m x n), A(m x k), B(k x n)
122 return TeamGemmInternal<Algo::Gemm::Blocked>::invoke(member, C.extent(0), C.extent(1), A.extent(1), alpha, A.data(),
123 A.stride_0(), A.stride_1(), B.data(), B.stride_1(),
124 B.stride_0(), beta, C.data(), C.stride_0(), C.stride_1());
125 }
126 };
127
128 ///
129 /// T/T
130 ///
131
132 template <typename MemberType>
133 struct TeamGemm<MemberType, Trans::Transpose, Trans::Transpose, Algo::Gemm::Unblocked> {
134 template <typename ScalarType, typename AViewType, typename BViewType, typename CViewType>
135 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
136 const BViewType &B, const ScalarType beta, const CViewType &C) {
137 // C = beta C + alpha A B
138 // C (m x n), A(m x k), B(k x n)
139 return TeamGemmInternal<Algo::Gemm::Unblocked>::invoke(member, C.extent(0), C.extent(1), A.extent(0), alpha,
140 A.data(), A.stride_1(), A.stride_0(), B.data(), B.stride_1(),
141 B.stride_0(), beta, C.data(), C.stride_0(), C.stride_1());
142 }
143 };
144
145 template <typename MemberType>
146 struct TeamGemm<MemberType, Trans::Transpose, Trans::Transpose, Algo::Gemm::Blocked> {
147 template <typename ScalarType, typename AViewType, typename BViewType, typename CViewType>
148 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const ScalarType alpha, const AViewType &A,
149 const BViewType &B, const ScalarType beta, const CViewType &C) {
150 // C = beta C + alpha A B
151 // C (m x n), A(m x k), B(k x n)
152 return TeamGemmInternal<Algo::Gemm::Blocked>::invoke(member, C.extent(0), C.extent(1), A.extent(0), alpha, A.data(),
153 A.stride_1(), A.stride_0(), B.data(), B.stride_1(),
154 B.stride_0(), beta, C.data(), C.stride_0(), C.stride_1());
155 }
156 };
157
158 } // namespace KokkosBatched
159
160 #endif