Skip to content

BLAS 1::update

Nathan Ellingwood edited this page Jun 24, 2020 · 1 revision

KokkosBlas::update()

Header File: KokkosBlas1_update.hpp

Usage: KokkosBlas::update(alpha,X,beta,Y,gamma,Z);

Vector addition:

z[i] = gamma * z[i] + alpha * x[i] + beta * y[i]

or

z[i,j] = gamma * z[i,j] + alpha * x[i,j] + beta * y[i,j]

Interface

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)

Parameters:

  • YMV: A rank-1 or rank-2 Kokkos::View
  • XMV: A rank-1 or rank-2 Kokkos::View
  • ZMV: A rank-1 or rank-2 Kokkos::View

Requirements:

  • ZMV::value_type == ZMV::non_const_value_type i.e. Z must be a non-const View
  • Y.rank == X.rank == Z.rank
  • Y.rank == 1 or Y.rank == 2
  • Y.extent(0) == X.extent(0)
  • Y.extent(1) == X.extent(1)
  • Z.extent(0) == X.extent(0)
  • Z.extent(1) == X.extent(1)

Example

#include<Kokkos_Core.hpp>
#include<KokkosBlas1_update.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::View<double*> z("Z",N);
     Kokkos::deep_copy(x,6.0);
     Kokkos::deep_copy(y,2.0);
     Kokkos::deep_copy(z,4.0);

     const double alpha = 1.5;
     const double beta  = 0.0;
     const double gamma = 1.2;

     KokkosBlas::update(alpha,x,beta,y,gamma,z);
     // Result per ith entry is z[i] <- gamma*z[i] + alpha*x[i] + beta*y[i]

     // Check results
     const double solution = gamma*4.0 + alpha*6.0 + beta*2.0;
     int error_count = 0;
     Kokkos::parallel_reduce("Error check", N, KOKKOS_LAMBDA(int i, int &update) {
         if (y(i) != solution) update += 1;
       }, error_count);

     if (error_count > 0)
       printf("Errors: %d\n", error_count);

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