Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_Iamax_Serial_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
17 #ifndef KOKKOSBATCHED_IAMAX_SERIAL_INTERNAL_HPP_
18 #define KOKKOSBATCHED_IAMAX_SERIAL_INTERNAL_HPP_
19
20 /// \author Yuuichi Asahi ([email protected])
21
22 #include <Kokkos_Core.hpp>
23 #include "KokkosBatched_Util.hpp"
24
25 namespace KokkosBatched {
26 namespace Impl {
27
28 ///
29 /// Serial Internal Impl
30 /// ========================
31
32 struct SerialIamaxInternal {
33 template <typename IndexType, typename ValueType>
34 KOKKOS_INLINE_FUNCTION static IndexType invoke(const int n, const ValueType *KOKKOS_RESTRICT x, const int xs0);
35 };
36
37 template <typename IndexType, typename ValueType>
38 KOKKOS_INLINE_FUNCTION IndexType SerialIamaxInternal::invoke(const int n, const ValueType *KOKKOS_RESTRICT x,
39 const int xs0) {
40 using ats = typename Kokkos::ArithTraits<ValueType>;
41 using RealType = typename ats::mag_type;
42
43 RealType amax = Kokkos::abs(x[0 * xs0]);
44 IndexType imax = 0;
45
46 for (IndexType i = 1; i < static_cast<IndexType>(n); ++i) {
47 const RealType abs_x_i = Kokkos::abs(x[i * xs0]);
48 if (abs_x_i > amax) {
49 amax = abs_x_i;
50 imax = i;
51 }
52 }
53
54 return imax;
55 };
56
57 } // namespace Impl
58 } // namespace KokkosBatched
59
60 #endif // KOKKOSBATCHED_IAMAX_SERIAL_INTERNAL_HPP_