forked from kokkos/stdBLAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
customization: vector_norm_2: kokkos tpl hook and example kokkos#96
- Loading branch information
Showing
3 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...mplementations/include/experimental/__p1673_bits/kokkos-kernels/blas1_vector_norm2_kk.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |