KokkosBlas::mult¶
Defined in header: KokkosBlas1_mult.hpp
template <class execution_space, class YMV, class AV, class XMV>
void mult(const execution_space& space, typename YMV::const_value_type& beta, const YMV& Y,
typename AV::const_value_type& alpha, const AV& A, const XMV& X);
template <class YMV, class AV, class XMV>
void mult(typename YMV::const_value_type& beta, const YMV& Y, typename AV::const_value_type& alpha, const AV& A,
const XMV& X);
computes an element wise multiplication of A and X scaled by alpha, then accumulate into Y scaled by beta.
Perform the entry wise multipliaction and addition using
spaceinstance.Perform the entry wise multipliaction and addition using the default instance of
typename XMV::execution_space.
The function will throw a runtime exception if
1. the vectors do not have same length: Y.extent(0) != A.extent(0) || Y.extent(0) != X.extent(0),
2. the number of vectors in X and Y does not match: Y.extent(2) != X.extent(1) for the rank-2 case.
Parameters¶
- space:
execution space instance
- beta:
scaling factor for Y
- Y:
output vector(s)
- alpha:
scaling factor for the A, X product
- A:
input vector to multiply element wise with X
- X:
input vector(s)
Type Requirements¶
execution_space must be a Kokkos execution space
YMV must be a Kokkos View of rank 1 or 2, that satisfies
Kokkos::SpaceAccessibility<execution_space, typename XMV::memory_space>::accessiblestd::is_same_v<typename YMV::value_type, typename YMV::non_const_value_type>
AV must be a Kokkos View of rank 1
XMV must be a Kokkos View of rank 1 or 2, that satisfies
Kokkos::SpaceAccessibility<execution_space, typename XMV::memory_space>::accessibleXMV::rank == YMV::rank
Example¶
1#include <iostream>
2#include <Kokkos_Core.hpp>
3#include <KokkosBlas1_mult.hpp>
4
5int main(void) {
6 Kokkos::initialize();
7 {
8 Kokkos::View<double*> a("a", 5), x("x", 5), y("y", 5);
9 auto h_y = Kokkos::create_mirror_view(y);
10 h_y(0) = 3.0;
11 h_y(1) = 2.0;
12 h_y(2) = 3.0;
13 h_y(3) = -2.0;
14 h_y(4) = 4.0;
15 auto h_a = Kokkos::create_mirror_view(a);
16 h_a(0) = -3.0;
17 h_a(1) = -1.0;
18 h_a(2) = 2.0;
19 h_a(3) = -2.0;
20 h_a(4) = -3.0;
21 auto h_x = Kokkos::create_mirror_view(x);
22 h_x(0) = 0.0;
23 h_x(1) = -1.0;
24 h_x(2) = -2.0;
25 h_x(3) = 3.0;
26 h_x(4) = -4.0;
27 Kokkos::deep_copy(y, h_y);
28 Kokkos::deep_copy(a, h_a);
29 Kokkos::deep_copy(x, h_x);
30
31 std::cout << "orignal values:\n"
32 << " beta: 2.0, alpha: -1.0\n"
33 << " y: {" << h_y(0) << ", " << h_y(1) << ", " << h_y(2) << ", " << h_y(3) << ", " << h_y(4) << "}\n"
34 << " a: {" << h_a(0) << ", " << h_a(1) << ", " << h_a(2) << ", " << h_a(3) << ", " << h_a(4) << "}\n"
35 << " x: {" << h_x(0) << ", " << h_x(1) << ", " << h_x(2) << ", " << h_x(3) << ", " << h_x(4) << "}\n"
36 << std::endl;
37
38 KokkosBlas::mult(2.0, y, -1.0, a, x);
39
40 Kokkos::deep_copy(h_y, y);
41 std::cout << "final values:\n"
42 << " y: {" << h_y(0) << ", " << h_y(1) << ", " << h_y(2) << ", " << h_y(3) << ", " << h_y(4) << "}"
43 << std::endl;
44 }
45 Kokkos::finalize();
46}
output:
orignal values:
beta: 2.0, alpha: -1.0
y: {3, 2, 3, -2, 4}
a: {-3, -1, 2, -2, -3}
x: {0, -1, -2, 3, -4}
final values:
y: {6, 3, 10, 2, -4}