| 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_XPAY_HPP |
| 17 |
#define KOKKOSBATCHED_XPAY_HPP |
| 18 |
|
| 19 |
/// \author Kim Liegeois ([email protected]) |
| 20 |
|
| 21 |
#include "KokkosBatched_Util.hpp" |
| 22 |
#include "KokkosBatched_Vector.hpp" |
| 23 |
|
| 24 |
namespace KokkosBatched { |
| 25 |
|
| 26 |
/// \brief Serial Batched XPAY: |
| 27 |
/// y_l <- x_l + alpha_l * y_l for all l = 1, ..., N |
| 28 |
/// where: |
| 29 |
/// * N is the number of vectors, |
| 30 |
/// * x_1, ..., x_N are the N input vectors, |
| 31 |
/// * y_1, ..., y_N are the N output vectors, |
| 32 |
/// * alpha_1, ..., alpha_N are N scaling factors for y_1, ..., y_N. |
| 33 |
/// |
| 34 |
/// \tparam XViewType: Input type for X, needs to be a 2D view |
| 35 |
/// \tparam YViewType: Input type for Y, needs to be a 2D view |
| 36 |
/// \tparam alphaViewType: Input type for alpha, needs to be a 1D view |
| 37 |
/// |
| 38 |
/// \param alpha [in]: input coefficient for Y, a rank 1 view |
| 39 |
/// \param X [in]: Input vector X, a rank 2 view |
| 40 |
/// \param Y [in/out]: Output vector Y, a rank 2 view |
| 41 |
/// |
| 42 |
/// No nested parallel_for is used inside of the function. |
| 43 |
/// |
| 44 |
|
| 45 |
struct SerialXpay { |
| 46 |
template <typename ViewType, typename alphaViewType> |
| 47 |
KOKKOS_INLINE_FUNCTION static int invoke(const alphaViewType &alpha, const ViewType &X, const ViewType &Y); |
| 48 |
}; |
| 49 |
|
| 50 |
/// \brief Team Batched XPAY: |
| 51 |
/// y_l <- x_l + alpha_l * y_l for all l = 1, ..., N |
| 52 |
/// where: |
| 53 |
/// * N is the number of vectors, |
| 54 |
/// * x_1, ..., x_N are the N input vectors, |
| 55 |
/// * y_1, ..., y_N are the N output vectors, |
| 56 |
/// * alpha_1, ..., alpha_N are N scaling factors for y_1, ..., y_N. |
| 57 |
/// |
| 58 |
/// \tparam XViewType: Input type for X, needs to be a 2D view |
| 59 |
/// \tparam YViewType: Input type for Y, needs to be a 2D view |
| 60 |
/// \tparam alphaViewType: Input type for alpha, needs to be a 1D view |
| 61 |
/// |
| 62 |
/// \param member [in]: TeamPolicy member |
| 63 |
/// \param alpha [in]: input coefficient for Y, a rank 1 view |
| 64 |
/// \param X [in]: Input vector X, a rank 2 view |
| 65 |
/// \param Y [in/out]: Output vector Y, a rank 2 view |
| 66 |
/// |
| 67 |
/// A nested parallel_for with TeamThreadRange is used. |
| 68 |
/// |
| 69 |
|
| 70 |
template <typename MemberType> |
| 71 |
struct TeamXpay { |
| 72 |
template <typename ViewType, typename alphaViewType> |
| 73 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const alphaViewType &alpha, const ViewType &X, |
| 74 |
const ViewType &Y); |
| 75 |
}; |
| 76 |
|
| 77 |
/// \brief TeamVector Batched XPAY: |
| 78 |
/// y_l <- x_l + alpha_l * y_l for all l = 1, ..., N |
| 79 |
/// where: |
| 80 |
/// * N is the number of vectors, |
| 81 |
/// * x_1, ..., x_N are the N input vectors, |
| 82 |
/// * y_1, ..., y_N are the N output vectors, |
| 83 |
/// * alpha_1, ..., alpha_N are N scaling factors for y_1, ..., y_N. |
| 84 |
/// |
| 85 |
/// \tparam XViewType: Input type for X, needs to be a 2D view |
| 86 |
/// \tparam YViewType: Input type for Y, needs to be a 2D view |
| 87 |
/// \tparam alphaViewType: Input type for alpha, needs to be a 1D view |
| 88 |
/// |
| 89 |
/// \param member [in]: TeamPolicy member |
| 90 |
/// \param alpha [in]: input coefficient for Y, a rank 1 view |
| 91 |
/// \param X [in]: Input vector X, a rank 2 view |
| 92 |
/// \param Y [in/out]: Output vector Y, a rank 2 view |
| 93 |
/// |
| 94 |
/// Two nested parallel_for with both TeamThreadRange and ThreadVectorRange |
| 95 |
/// (or one with TeamVectorRange) are used inside. |
| 96 |
/// |
| 97 |
|
| 98 |
template <typename MemberType> |
| 99 |
struct TeamVectorXpay { |
| 100 |
template <typename ViewType, typename alphaViewType> |
| 101 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const alphaViewType &alpha, const ViewType &X, |
| 102 |
const ViewType &Y); |
| 103 |
}; |
| 104 |
|
| 105 |
} // namespace KokkosBatched |
| 106 |
|
| 107 |
#include "KokkosBatched_Xpay_Impl.hpp" |
| 108 |
|
| 109 |
#endif |