| 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_DOT_HPP |
| 17 |
#define KOKKOSBATCHED_DOT_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 DOT: |
| 27 |
/// |
| 28 |
/// Depending on the ArgTrans template, the dot product is |
| 29 |
/// row-based (ArgTrans == Trans::NoTranspose): |
| 30 |
/// |
| 31 |
/// dot_l <- (x_l:, y_l:) for all l = 1, ..., N |
| 32 |
/// where: |
| 33 |
/// * N is the second dimension of X. |
| 34 |
/// |
| 35 |
/// Or column-based: |
| 36 |
/// dot_l <- (x_:l, y_:l) for all l = 1, ..., n |
| 37 |
/// where: |
| 38 |
/// * n is the second dimension of X. |
| 39 |
/// |
| 40 |
/// \tparam ArgTrans: type of dot product (Trans::NoTranspose by default) |
| 41 |
/// \tparam XViewType: Input type for X, needs to be a 2D view |
| 42 |
/// \tparam YViewType: Input type for Y, needs to be a 2D view |
| 43 |
/// \tparam alphaViewType: Input type for alpha, needs to be a 1D view |
| 44 |
/// |
| 45 |
/// \param X [in]: Input vector X, a rank 2 view |
| 46 |
/// \param Y [in]: Input vector Y, a rank 2 view |
| 47 |
/// \param dot [out]: Computed dot product, a rank 1 view |
| 48 |
/// |
| 49 |
/// No nested parallel_for is used inside of the function. |
| 50 |
/// |
| 51 |
|
| 52 |
template <typename ArgTrans = Trans::NoTranspose> |
| 53 |
struct SerialDot { |
| 54 |
template <typename XViewType, typename YViewType, typename NormViewType> |
| 55 |
KOKKOS_INLINE_FUNCTION static int invoke(const XViewType &X, const YViewType &Y, const NormViewType &dot); |
| 56 |
}; |
| 57 |
|
| 58 |
/// \brief Team Batched DOT: |
| 59 |
/// |
| 60 |
/// Depending on the ArgTrans template, the dot product is |
| 61 |
/// row-based (ArgTrans == Trans::NoTranspose): |
| 62 |
/// |
| 63 |
/// dot_l <- (x_l:, y_l:) for all l = 1, ..., N |
| 64 |
/// where: |
| 65 |
/// * N is the second dimension of X. |
| 66 |
/// |
| 67 |
/// Or column-based: |
| 68 |
/// dot_l <- (x_:l, y_:l) for all l = 1, ..., n |
| 69 |
/// where: |
| 70 |
/// * n is the second dimension of X. |
| 71 |
/// |
| 72 |
/// \tparam ArgTrans: type of dot product (Trans::NoTranspose by default) |
| 73 |
/// \tparam XViewType: Input type for X, needs to be a 2D view |
| 74 |
/// \tparam YViewType: Input type for Y, needs to be a 2D view |
| 75 |
/// \tparam alphaViewType: Input type for alpha, needs to be a 1D view |
| 76 |
/// |
| 77 |
/// \param X [in]: Input vector X, a rank 2 view |
| 78 |
/// \param Y [in]: Input vector Y, a rank 2 view |
| 79 |
/// \param dot [out]: Computed dot product, a rank 1 view |
| 80 |
/// |
| 81 |
/// A nested parallel_for with TeamThreadRange is used. |
| 82 |
/// |
| 83 |
|
| 84 |
template <typename MemberType, typename ArgTrans = Trans::NoTranspose> |
| 85 |
struct TeamDot { |
| 86 |
template <typename XViewType, typename YViewType, typename NormViewType> |
| 87 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const XViewType &X, const YViewType &Y, |
| 88 |
const NormViewType &dot); |
| 89 |
}; |
| 90 |
|
| 91 |
/// \brief TeamVector Batched DOT: |
| 92 |
/// |
| 93 |
/// Depending on the ArgTrans template, the dot product is |
| 94 |
/// row-based (ArgTrans == Trans::NoTranspose): |
| 95 |
/// |
| 96 |
/// dot_l <- (x_l:, y_l:) for all l = 1, ..., N |
| 97 |
/// where: |
| 98 |
/// * N is the second dimension of X. |
| 99 |
/// |
| 100 |
/// Or column-based: |
| 101 |
/// dot_l <- (x_:l, y_:l) for all l = 1, ..., n |
| 102 |
/// where: |
| 103 |
/// * n is the second dimension of X. |
| 104 |
/// |
| 105 |
/// \tparam ArgTrans: type of dot product (Trans::NoTranspose by default) |
| 106 |
/// \tparam XViewType: Input type for X, needs to be a 2D view |
| 107 |
/// \tparam YViewType: Input type for Y, needs to be a 2D view |
| 108 |
/// \tparam alphaViewType: Input type for alpha, needs to be a 1D view |
| 109 |
/// |
| 110 |
/// \param X [in]: Input vector X, a rank 2 view |
| 111 |
/// \param Y [in]: Input vector Y, a rank 2 view |
| 112 |
/// \param dot [out]: Computed dot product, a rank 1 view |
| 113 |
/// |
| 114 |
/// Two nested parallel_for with both TeamThreadRange and ThreadVectorRange |
| 115 |
/// (or one with TeamVectorRange) are used inside. |
| 116 |
/// |
| 117 |
|
| 118 |
template <typename MemberType, typename ArgTrans = Trans::NoTranspose> |
| 119 |
struct TeamVectorDot { |
| 120 |
template <typename XViewType, typename YViewType, typename NormViewType> |
| 121 |
KOKKOS_INLINE_FUNCTION static int invoke(const MemberType &member, const XViewType &X, const YViewType &Y, |
| 122 |
const NormViewType &dot); |
| 123 |
}; |
| 124 |
|
| 125 |
} // namespace KokkosBatched |
| 126 |
|
| 127 |
#include "KokkosBatched_Dot_Internal.hpp" |
| 128 |
|
| 129 |
#endif |