| 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_ADD_RADIAL_INTERNAL_HPP |
| 17 |
#define KOKKOSBATCHED_ADD_RADIAL_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 SerialAddRadialInternal { |
| 29 |
template <typename ScalarType, typename ValueType> |
| 30 |
KOKKOS_INLINE_FUNCTION static int invoke(const int m, const ScalarType tiny, |
| 31 |
/* */ ValueType *KOKKOS_RESTRICT A, const int as) { |
| 32 |
const auto abs_tiny = tiny > 0 ? tiny : -tiny; |
| 33 |
const auto minus_abs_tiny = -abs_tiny; |
| 34 |
|
| 35 |
#if defined(KOKKOS_ENABLE_PRAGMA_UNROLL) |
| 36 |
#pragma unroll |
| 37 |
#endif |
| 38 |
for (int i = 0; i < m; ++i) { |
| 39 |
// const auto a_real = RealPart(A[i*as]); |
| 40 |
const auto a_real = Kokkos::ArithTraits<ValueType>::real(A[i * as]); |
| 41 |
A[i * as] += ValueType(minus_abs_tiny) * ValueType(a_real < 0); |
| 42 |
A[i * as] += ValueType(abs_tiny) * ValueType(a_real >= 0); |
| 43 |
} |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
/// |
| 50 |
/// Team Internal Impl |
| 51 |
/// ================== |
| 52 |
struct TeamAddRadialInternal { |
| 53 |
template <typename MemberType, typename ScalarType, typename ValueType> |
| 54 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const int m, const ScalarType tiny, |
| 55 |
/* */ ValueType *KOKKOS_RESTRICT A, const int as) { |
| 56 |
const auto abs_tiny = tiny > 0 ? tiny : -tiny; |
| 57 |
const auto minus_abs_tiny = -abs_tiny; |
| 58 |
|
| 59 |
Kokkos::parallel_for(Kokkos::TeamThreadRange(member, m), [&](const int &i) { |
| 60 |
// const auto a_real = RealPart(A[i*as]); |
| 61 |
const auto a_real = Kokkos::ArithTraits<ValueType>::real(A[i * as]); |
| 62 |
A[i * as] += ValueType(minus_abs_tiny) * ValueType(a_real < 0); |
| 63 |
A[i * as] += ValueType(abs_tiny) * ValueType(a_real >= 0); |
| 64 |
}); |
| 65 |
|
| 66 |
return 0; |
| 67 |
} |
| 68 |
}; |
| 69 |
|
| 70 |
} // end namespace KokkosBatched |
| 71 |
|
| 72 |
#endif |