Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_Gemv_Team_Internal.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_INTERNAL_HPP
17 #define KOKKOSBATCHED_GEMV_TEAM_INTERNAL_HPP
18
19 /// \author Kyungjoo Kim ([email protected])
20
21 #include "KokkosBatched_Util.hpp"
22
23 // #include "KokkosBlas1_set_impl.hpp"
24 // #include "KokkosBlas1_team_scal_impl.hpp"
25 // #include "KokkosBlas2_serial_gemv_inner_multiple_dot.hpp"
26
27 namespace KokkosBatched {
28
29 ///
30 /// Team Internal Impl
31 /// ====================
32 template <typename ArgAlgo>
33 struct TeamGemvInternal {
34 template <typename MemberType, typename ScalarType, typename layout, typename ValueType>
35 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int N, const int m, const int n,
36 const ScalarType alpha, const ValueType *KOKKOS_RESTRICT A, const int as0,
37 const int as1, const int as2, const ValueType *KOKKOS_RESTRICT x,
38 const int xs0, const int xs1, const ScalarType beta,
39 /**/ ValueType *KOKKOS_RESTRICT y, const int ys0, const int ys1);
40 };
41
42 template <>
43 template <typename MemberType, typename ScalarType, typename layout, typename ValueType>
44 KOKKOS_INLINE_FUNCTION int TeamGemvInternal<Algo::Gemv::Unblocked>::invoke(
45 const MemberType &member, const int N, const int m, const int n, const ScalarType alpha,
46 const ValueType *KOKKOS_RESTRICT A, const int as0, const int as1, const int as2, const ValueType *KOKKOS_RESTRICT X,
47 const int xs0, const int xs1, const ScalarType beta,
48 /**/ ValueType *KOKKOS_RESTRICT Y, const int ys0, const int ys1) {
49 const ScalarType one(1.0), zero(0.0);
50
51 // y_l = beta y_l + alpha A_l x_l for l in range(0, N)
52 // y_l (m), A_l(m x n), B_l(n)
53
54 if (beta == zero)
55 Kokkos::parallel_for(Kokkos::TeamThreadRange(member, 0, N * m), [&](const int &iTemp) {
56 int iRow, iMatrix;
57 getIndices<int, layout>(iTemp, m, N, iRow, iMatrix);
58 Y[ys0 * iMatrix + ys1 * iRow] = zero;
59 });
60 else if (beta != one)
61 Kokkos::parallel_for(Kokkos::TeamThreadRange(member, 0, N * m), [&](const int &iTemp) {
62 int iRow, iMatrix;
63 getIndices<int, layout>(iTemp, m, N, iRow, iMatrix);
64 Y[ys0 * iMatrix + ys1 * iRow] *= beta;
65 });
66
67 if (alpha != zero) {
68 if (m <= 0 || n <= 0) return 0;
69
70 if (beta != one) member.team_barrier();
71
72 Kokkos::parallel_for(Kokkos::TeamThreadRange(member, 0, N * m), [&](const int &iTemp) {
73 int iRow, iMatrix;
74 ValueType t(0);
75 getIndices<int, layout>(iTemp, m, N, iRow, iMatrix);
76 for (int i = 0; i < n; ++i) t += A[as0 * iMatrix + as1 * iRow + as2 * i] * X[xs0 * iMatrix + xs1 * i];
77 Y[ys0 * iMatrix + ys1 * iRow] += alpha * t;
78 });
79 }
80 return 0;
81 }
82 } // namespace KokkosBatched
83
84 #endif