Skip to content

BLAS 1::axpy

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

KokkosBlas::axpy()

Header File: KokkosBlas1_axpby.hpp

Usage: KokkosBlas::axpy(alpha,x,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) respectively. Resulting value is assigned to y(i) (or y(i,j)).

Interface

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

Parameters:

  • AlphaType: A scalar or a rank-1 Kokkos::View if Y and X are of rank-2.
  • OutputVector: A rank-1 or rank-2 Kokkos::View with non-const data type.
  • InputVector: A rank-1 or rank-2 Kokkos::View

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 type.

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;

   KokkosBlas::axpy(alpha,x,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*(2.0+1.5*3.0),sum-1.0*N);

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