KokkosBlas::dot

Defined in header: KokkosBlas1_dot.hpp

template <class execution_space, class XVector, class YVector>
typename Kokkos::Details::InnerProductSpaceTraits<typename XVector::non_const_value_type>::dot_type
dot(const execution_space& space, const XVector& x, const YVector& y);

template <class XVector, class YVector>
typename Kokkos::Details::InnerProductSpaceTraits<typename XVector::non_const_value_type>::dot_type
dot(const XVector& x, const YVector& y);

template <class execution_space, class RV, class XMV, class YMV>
void dot(const execution_space& space, const RV& R, const XMV& X, const YMV& Y);

template <class RV, class XMV, class YMV>
void dot(const RV& R, const XMV& X, const YMV& Y);

Computes the inner product of vector(s) X with vector(s) Y.

  1. Iterate over the entries of X and multiply them (or their conjugate) by the corresponding entry in Y, accumulate the results and fence space

  2. Iterate over the entries of X and multiply them (or their conjugate) by the corresponding entry in Y, accumulate the results and fence the default instance of typename XVector::execution_space

  3. Iterate over the entries of X and multiply them (or their conjugate) by the corresponding entry in Y, accumulate the results in R using the resources specified by space

  4. Iterate over the entries of X and multiply them (or their conjugate) by the corresponding entry in Y, accumulate the results in R using the resources specified by the default instance of typename XVector::execution_space

The function will throw a runtime exception if any of the following conditions are not met
  • X.extent(0) == Y.extent(0)

  • X.extent(1) = 1 || Y.extent(1) || X.extent(1) == Y.extent(1)

  • R.extent(0) = max(X.extent(1), Y.extent(1))

The result (returned or stored value) is undefined if X has no entries.

Parameters

space:

execution space instance that specifies the resources and stream/queue used to execute this kernel

R:

computed inner products

X, Y:

vectors used to compute the inner products

Type Requirements

  • execution_space must be a Kokkos execution space

  • XVector must be a Kokkos View of rank 1 that satisfies

    • Kokkos::SpaceAccessibility<execution_space, typename XVector::memory_space>::accessible == true

  • YVector must be a Kokkos View of rank 1 that satisfies

    • Kokkos::SpaceAccessibility<execution_space, typename YVector::memory_space>::accessible == true

  • XMV must be a Kokkos View of rank 1 or 2 that satisfies

    • Kokkos::SpaceAccessibility<execution_space, typename XMV::memory_space>::accessible == true

  • YMV must be a Kokkos View of rank 1 or 2 that satisfies

    • Kokkos::SpaceAccessibility<execution_space, typename YMV::memory_space>::accessible == true

  • RV must be a Kokkos View of rank 0 or 1 that satisfies

    • Kokkos::SpaceAccessibility<execution_space, typename RV::memory_space>::accessible == true

    • std::is_same_v<typename RV::value_type, typename RV::non_const_value_type> == true

Example

#include <iostream>
#include <Kokkos_Core.hpp>
#include <KokkosBlas1_dot.hpp>

int main(int argc, char* argv[]) {
  Kokkos::initialize();
  {
    int N = 100;
    if (argc >= 2) {
      N = atoi(argv[1]);
    }

    Kokkos::View<double*> x("X", N);
    Kokkos::View<double*> y("Y", N);
    Kokkos::deep_copy(x, 3.0);
    Kokkos::deep_copy(y, 2.0);

    double x_y = KokkosBlas::dot(x, y);

    std::cout << "X_dot_Y: " << x_y << " Expected: " << 1.0 * N * (3.0 * 2.0)
              << " Diff: " << x_y - 1.0 * N * (3.0 * 2.0) << std::endl;
  }
  Kokkos::finalize();
}

output:

X_dot_Y: 600 Expected: 600 Diff: 0