Skip to content

Commit

Permalink
dot: customization point to Kokkos-kernels and example
Browse files Browse the repository at this point in the history
  • Loading branch information
fnrizzi committed Oct 26, 2021
1 parent 086077e commit b2faf60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
30 changes: 30 additions & 0 deletions examples/kokkos-based/dot_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

std::size_t N = 50;
Expand All @@ -21,11 +22,28 @@ int main(int argc, char* argv[])
mdspan_type a(a_ptr,N);
mdspan_type b(b_ptr,N);
for(std::size_t i=0; i<a.extent(0); i++){
=======
std::cout << "running dot example calling custom kokkos" << std::endl;
int N = 50;
Kokkos::initialize(argc,argv);
{
Kokkos::View<double*> a_view("A",N);
Kokkos::View<double*> b_view("B",N);
double* a_ptr = a_view.data();
double* b_ptr = b_view.data();

using dyn_1d_ext_type = std::experimental::extents<std::experimental::dynamic_extent>;
using mdspan_type = std::experimental::mdspan<double, dyn_1d_ext_type>;
mdspan_type a(a_ptr,N);
mdspan_type b(b_ptr,N);
for(int i=0; i<a.extent(0); i++){
>>>>>>> dot: customization point to Kokkos-kernels and example
a(i) = i;
b(i) = i;
}

namespace stdla = std::experimental::linalg;
<<<<<<< HEAD
const value_type init_value(2.0);

// This goes to the base implementation
Expand All @@ -35,6 +53,18 @@ int main(int argc, char* argv[])
// This forwards to KokkosKernels
const auto res_kk = stdla::dot(KokkosKernelsSTD::kokkos_exec<>(), a, b, init_value);
printf("Kokkos result = %lf\n", res_kk);
=======
const double init_value = 2.0;

// This goes to the base implementation
const auto res_seq = stdla::dot(std::execution::seq, a, b, init_value);

// This forwards to KokkosKernels
auto res_kk = stdla::dot(KokkosKernelsSTD::kokkos_exec<>(), a, b, init_value);

printf("Kokkos result = %lf\n", res_kk);
printf("Seq result = %lf\n", res_seq);
>>>>>>> dot: customization point to Kokkos-kernels and example
}
Kokkos::finalize();
}
21 changes: 0 additions & 21 deletions include/experimental/__p1673_bits/blas1_dot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,12 @@ struct is_custom_dot_avail<

} // end anonymous namespace

<<<<<<< HEAD
=======

// ------------
// PUBLIC API:
// ------------

// dot, with init value
>>>>>>> dot: customization point to Kokkos-kernels and example
template<class ExecutionPolicy,
class ElementType1,
extents<>::size_type ext1,
Expand All @@ -103,12 +100,9 @@ Scalar dot(
std::experimental::mdspan<ElementType2, std::experimental::extents<ext2>, Layout2, Accessor2> v2,
Scalar init)
{
<<<<<<< HEAD
static_assert(v1.static_extent(0) == dynamic_extent ||
v2.static_extent(0) == dynamic_extent ||
v1.static_extent(0) == v2.static_extent(0));
=======
>>>>>>> dot: customization point to Kokkos-kernels and example

constexpr bool use_custom = is_custom_dot_avail<
decltype(execpolicy_mapper(exec)), decltype(v1), decltype(v2), Scalar
Expand Down Expand Up @@ -141,10 +135,6 @@ Scalar dot(std::experimental::mdspan<ElementType1, std::experimental::extents<ex
return dot(std::experimental::linalg::impl::default_exec_t(), v1, v2, init);
}

<<<<<<< HEAD
=======
// Conjugated dot, with init value
>>>>>>> dot: customization point to Kokkos-kernels and example
template<class ElementType1,
extents<>::size_type ext1,
class Layout1,
Expand Down Expand Up @@ -201,8 +191,6 @@ namespace dot_detail {
-> decltype(x(0) * y(0));
} // namespace dot_detail


// dot, without init value
template<class ElementType1,
extents<>::size_type ext1,
class Layout1,
Expand Down Expand Up @@ -239,10 +227,6 @@ auto dot(
return dot(exec, v1, v2, return_t{});
}

<<<<<<< HEAD
=======
// Conjugated dot, without init value
>>>>>>> dot: customization point to Kokkos-kernels and example
template<class ElementType1,
extents<>::size_type ext1,
class Layout1,
Expand All @@ -256,15 +240,10 @@ auto dotc(
std::experimental::mdspan<ElementType2, std::experimental::extents<ext2>, Layout2, Accessor2> v2)
-> decltype(dot_detail::dot_return_type_deducer(conjugated(v1), v2))
{
<<<<<<< HEAD
using return_t = decltype(dot_detail::dot_return_type_deducer(conjugated(v1), v2));
=======
using return_t = decltype(dot_detail::dot_return_type_deducer(v1, v2));
>>>>>>> dot: customization point to Kokkos-kernels and example
return dotc(v1, v2, return_t{});
}


template<class ExecutionPolicy,
class ElementType1,
extents<>::size_type ext1,
Expand Down

0 comments on commit b2faf60

Please sign in to comment.