KokkosBlas::update

Defined in header: KokkosBlas1_update.hpp

template <class execution_space, class XMV, class YMV, class ZMV>
void update(const execution_space& space, const typename XMV::non_const_value_type& alpha, const XMV& X,
            const typename YMV::non_const_value_type& beta, const YMV& Y,
            const typename ZMV::non_const_value_type& gamma, const ZMV& Z);

template <class XMV, class YMV, class ZMV>
void update(const typename XMV::non_const_value_type& alpha, const XMV& X,
            const typename YMV::non_const_value_type& beta, const YMV& Y,
            const typename ZMV::non_const_value_type& gamma, const ZMV& Z);

updates the values of Z using the scales sum of the values of the vector(s) X, Y and Z itself.

\[Z = \alpha X + \beta Y + \gamma Z\]
  1. Adds the vectors X, Y and Z, scaled by \(\alpha\), \(\beta\) and \(\gamma\) resp., together into Z.

  2. Computes the sum of the entries in X using the default instance of typename ZMV::execution_space and returns them.

The functions will throw at runtime unless the first and second extents of X, Y and Z are equal.

Parameters

space:

execution space instance

alpha:

scaling factor for the values of X

X:

input vector(s)

beta:

scaling factor for the values of Y

Y:

input vector(s)

gamma:

scaling factor for the values of Z

Z:

output vector(s)

Type Requirements

  • execution_space must be a Kokkos execution space

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

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

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

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

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

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

    • !std::is_cont_v<typename ZMV::value_type>

    • ZMV::rank == XMV::rank && ZMV::rank == YMV::rank

Example

 1#include <iostream>
 2#include <Kokkos_Core.hpp>
 3#include <KokkosBlas1_update.hpp>
 4
 5int main(void) {
 6  Kokkos::initialize();
 7  {
 8    Kokkos::View<double*> x("x", 5), y("y", 5), z("z", 5);
 9    auto h_x = Kokkos::create_mirror_view(x);
10    h_x(0)   = 0.0;
11    h_x(1)   = -1.0;
12    h_x(2)   = -2.0;
13    h_x(3)   = 3.0;
14    h_x(4)   = -4.0;
15    auto h_y = Kokkos::create_mirror_view(y);
16    h_y(0)   = 3.0;
17    h_y(1)   = 2.0;
18    h_y(2)   = 3.0;
19    h_y(3)   = -2.0;
20    h_y(4)   = 4.0;
21    auto h_z = Kokkos::create_mirror_view(z);
22    h_z(0)   = -3.0;
23    h_z(1)   = -1.0;
24    h_z(2)   = 2.0;
25    h_z(3)   = -2.0;
26    h_z(4)   = -3.0;
27    Kokkos::deep_copy(x, h_x);
28    Kokkos::deep_copy(y, h_y);
29    Kokkos::deep_copy(z, h_z);
30
31    std::cout << "orignal values:\n"
32              << "   alpha: -1.0,  beta: 2.0,  gamma: \n"
33              << "   x: {" << h_x(0) << ", " << h_x(1) << ", " << h_x(2) << ", " << h_x(3) << ", " << h_x(4) << "}\n"
34              << "   y: {" << h_y(0) << ", " << h_y(1) << ", " << h_y(2) << ", " << h_y(3) << ", " << h_y(4) << "}\n"
35              << "   z: {" << h_z(0) << ", " << h_z(1) << ", " << h_z(2) << ", " << h_z(3) << ", " << h_z(4) << "}\n"
36              << std::endl;
37
38    KokkosBlas::update(-1.0, x, 2.0, y, 1.0, z);
39
40    Kokkos::deep_copy(h_z, z);
41    std::cout << "final values:\n"
42              << "   z: {" << h_z(0) << ", " << h_z(1) << ", " << h_z(2) << ", " << h_z(3) << ", " << h_z(4) << "}"
43              << std::endl;
44  }
45  Kokkos::finalize();
46}

output:

orignal values:
  alpha: -1.0,  beta: 2.0,  gamma:
  x: {0, -1, -2, 3, -4}
  y: {3, 2, 3, -2, 4}
  z: {-3, -1, 2, -2, -3}

final values:
  z: {3, 4, 10, -9, 9}