Skip to content

Commit

Permalink
customization: vector_norm_2: kokkos tpl hook and example kokkos#96
Browse files Browse the repository at this point in the history
  • Loading branch information
fnrizzi committed Oct 27, 2021
1 parent f7d2a3b commit 917d668
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
34 changes: 34 additions & 0 deletions examples/kokkos-based/vector_norm2_kokkos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

#include <experimental/linalg>
#include <iostream>

int main(int argc, char* argv[])
{
std::cout << "vector_norm2 example: calling kokkos-kernels" << std::endl;

std::size_t N = 20;
Kokkos::initialize(argc,argv);
{
using value_type = double;
Kokkos::View<value_type*> x_view("x",N);
value_type* x_ptr = x_view.data();

using dyn_1d_ext_type = std::experimental::extents<std::experimental::dynamic_extent>;
using mdspan_type = std::experimental::mdspan<value_type, dyn_1d_ext_type>;
mdspan_type x(x_ptr,N);
for(std::size_t i=0; i<x.extent(0); i++){
x(i) = (value_type) i;
}

namespace stdla = std::experimental::linalg;
const value_type init_value(2);

const auto res = stdla::vector_norm2(x, init_value);
printf("Default result = %lf\n", res);

const auto res_kk = stdla::vector_norm2(KokkosKernelsSTD::kokkos_exec<>(), x, init_value);
printf("Kokkos result = %lf\n", res_kk);

}
Kokkos::finalize();
}
4 changes: 1 addition & 3 deletions include/experimental/__p1673_bits/blas1_vector_norm2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ struct is_custom_vector_norm2_avail<
>
{
static constexpr bool value =
!std::is_same<Exec,
std::experimental::linalg::impl::inline_exec_t
>::value;
!std::is_same<Exec, std::experimental::linalg::impl::inline_exec_t>::value;
};
} // end anonymous namespace

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#ifndef LINALG_TPLIMPLEMENTATIONS_INCLUDE_EXPERIMENTAL_P1673_BITS_KOKKOSKERNELS_VEC_NORM2_HPP_
#define LINALG_TPLIMPLEMENTATIONS_INCLUDE_EXPERIMENTAL_P1673_BITS_KOKKOSKERNELS_VEC_NORM2_HPP_

namespace KokkosKernelsSTD {

template<class ExecSpace,
class ElementType,
std::experimental::extents<>::size_type ext0,
class Layout,
class Accessor,
class Scalar>
Scalar vector_norm2(kokkos_exec<ExecSpace>,
std::experimental::mdspan<ElementType, std::experimental::extents<ext0>, Layout, Accessor> v,
Scalar init)
{
return init + KokkosBlas::nrm2(Impl::mdspan_to_view(v));
}

}
#endif

0 comments on commit 917d668

Please sign in to comment.