Skip to content

BLAS 1::dot

Christian Trott edited this page Jan 22, 2018 · 4 revisions

KokkosBlas::dot()

Header File: KokkosBlas1_dot.hpp

Usage: result = KokkosBlas::dot(x,y); KokkosBlas::dot(r,x,y);

Multiplies each value of x(i) [x(i,j)] with y(i) or [y(i,j)] and computes the total.

Interface A

template<class VectorX, class VectorY>
InnerProductSpaceTraits<VectorX::non_const_value_type>::dot_type
dot (const VectorX& X, const VectorY& Y);

Parameters:

  • VectorX: A rank-1 Kokkos::View
  • VectorY: A rank-1 Kokkos::View

Requirements:

  • Y.rank == 1 or X.rank == 1
  • Y.extent(0) == X.extent(0)

Interface B

template<class ReturnVector, class VectorX, class VectorY>
void dot (const ReturnVector& R, const VectorX& X, const VectorY& Y);

Parameters:

  • ReturnVector: A rank-0 or rank-1 Kokkos::View
  • VectorX: A rank-1 or rank-2 Kokkos::View
  • VectorY: A rank-1 or rank-2 Kokkos::View

Requirements:

  • X.rank == Y.rank
  • X.rank == R.rank + 1
  • Y.extent(0) == X.extent(0)
  • Y.extent(1) == X.extent(1)
  • R.extent(0) == X.extent(1)
  • ReturnVector::non_const_value_type == ReturnVector::value_type

Example

#include<Kokkos_Core.hpp>
#include<KokkosBlas1_dot.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 x_y = KokkosBlas::dot(x,y);

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

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