Skip to content

BLAS 1::axpby

Jennifer Loe edited this page May 8, 2020 · 4 revisions

KokkosBlas::axpby()

Header File: KokkosBlas1_axpby.hpp

Usage: KokkosBlas::axpby(alpha,x,beta,y);

Multiplies each value of x(i) or x(i,j) with alpha (or alpha(j)) and adds it to y(i) or y(i,j) after scaling the y-value by beta (or beta(j)) respectively. Resulting value is assigned to y(i) (or y(i,j)).

Interface

template<class AlphaType, class InputVector, class BetaType, class OutputVector>
void axpby (const AlphaType& alpha, const InputVector& X, const BetaType& beta, const OutputVector& Y);

Parameters:

  • AlphaType: A scalar or a rank-1 Kokkos::View
  • InputVector: A rank-1 or rank-2 Kokkos::View
  • BetaType: A scalar or a rank-1 Kokkos::View.
  • OutputVector: A rank-1 or rank-2 Kokkos::View with non-const data type.

Requirements:

  • OutputVector::value_type == OutputVector::non_const_value_type
  • Y.rank == X.rank
  • Y.rank == 1 or Y.rank == 2
  • Y.extent(0) == X.extent(0)
  • Y.extent(1) == X.extent(1)
  • If Y.rank == 1 then AlphaType is a scalar.

Example

#include<Kokkos_Core.hpp>
#include<KokkosBlas1_axpby.hpp>

int main(int argc, char* argv[]) {
   Kokkos::initialize();

   int 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 alpha = 1.5;
   double beta = 1.3;

   KokkosBlas::axpby(alpha,x,beta,y);

   double sum = 0.0;
   Kokkos::parallel_reduce("CheckValue", N, KOKKOS_LAMBDA (const int& i, double& lsum) {
     lsum += y(i);
   },sum);

   printf("Sum: %lf Expected: %lf Diff: %e\n",sum,1.0*N*(1.3*2.0 + 1.5*3.0),sum-1.0*N);

   Kokkos::finalize();
}
Clone this wiki locally