Debian Codegraph @

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