Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_SetIdentity_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_SET_IDENTITY_INTERNAL_HPP
17 #define KOKKOSBATCHED_SET_IDENTITY_INTERNAL_HPP
18
19 /// \author Kyungjoo Kim ([email protected])
20
21 #include "KokkosBatched_Util.hpp"
22
23 namespace KokkosBatched {
24
25 ///
26 /// Serial Internal Impl
27 /// ====================
28 struct SerialSetIdentityInternal {
29 template <typename ValueType>
30 KOKKOS_INLINE_FUNCTION static int invoke(const int m, const int n,
31 /* */ ValueType *KOKKOS_RESTRICT A, const int as0, const int as1) {
32 const ValueType one(1), zero(0);
33 for (int j = 0; j < n; ++j) {
34 #if defined(KOKKOS_ENABLE_PRAGMA_UNROLL)
35 #pragma unroll
36 #endif
37 for (int i = 0; i < m; ++i) {
38 A[i * as0 + j * as1] = i == j ? one : zero;
39 }
40 }
41
42 return 0;
43 }
44 };
45
46 ///
47 /// Team Internal Impl
48 /// ==================
49 struct TeamSetIdentityInternal {
50 template <typename MemberType, typename ValueType>
51 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int m, const int n,
52 /* */ ValueType *KOKKOS_RESTRICT A, const int as0, const int as1) {
53 const ValueType one(1), zero(0);
54 Kokkos::parallel_for(Kokkos::TeamThreadRange(member, m), [&](const int &i) {
55 #if defined(KOKKOS_ENABLE_PRAGMA_UNROLL)
56 #pragma unroll
57 #endif
58 for (int j = 0; j < n; ++j) A[i * as0 + j * as1] = i == j ? one : zero;
59 });
60
61 return 0;
62 }
63 };
64
65 ///
66 /// TeamVector Internal Impl
67 /// ========================
68 struct TeamVectorSetIdentityInternal {
69 template <typename MemberType, typename ValueType>
70 KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int m, const int n,
71 /* */ ValueType *KOKKOS_RESTRICT A, const int as0, const int as1) {
72 const ValueType one(1), zero(0);
73 Kokkos::parallel_for(Kokkos::TeamThreadRange(member, m), [&](const int &i) {
74 Kokkos::parallel_for(Kokkos::ThreadVectorRange(member, n),
75 [&](const int &j) { A[i * as0 + j * as1] = i == j ? one : zero; });
76 });
77
78 return 0;
79 }
80 };
81
82 } // end namespace KokkosBatched
83
84 #endif