Skip to content

Commit

Permalink
scale: minor change for readability, use size_t in test
Browse files Browse the repository at this point in the history
  • Loading branch information
fnrizzi committed Oct 21, 2021
1 parent 59912f5 commit 21fbd5e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
12 changes: 7 additions & 5 deletions examples/kokkos-based/simple_scale_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <iostream>


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

std::size_t N = 40;
Kokkos::initialize(argc,argv);
{
Kokkos::View<double*> a_view("A",N);
Expand All @@ -14,15 +16,15 @@ int main(int argc, char* argv[]) {
// Requires CTAD working, GCC 11.1 works but some others are buggy
// std::experimental::mdspan a(a_ptr,N);
std::experimental::mdspan<double,std::experimental::extents<std::experimental::dynamic_extent>> a(a_ptr,N);
for(int i=0; i<a.extent(0); i++) a(i) = i;
for(std::size_t i=0; i<a.extent(0); i++) a(i) = i;

// This forwards to KokkosKernels (https://github.com/kokkos/kokkos-kernels
std::experimental::linalg::scale(KokkosKernelsSTD::kokkos_exec<>(),2.0,a);
// This forwards to KokkosKernels if LINALG_ENABLE_KOKKOS_DEFAULT is ON
std::experimental::linalg::scale(std::execution::par,2.0,a);
// This goes to the base implementation
std::experimental::linalg::scale(std::execution::seq,2.0,a);
for(int i=0; i<a.extent(0); i++) printf("%i %lf\n",i,a(i));
for(std::size_t i=0; i<a.extent(0); i++) printf("%i %lf\n",i,a(i));
}
Kokkos::finalize();
}
11 changes: 6 additions & 5 deletions include/experimental/__p1673_bits/blas1_scale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ void scale(
std::experimental::mdspan<ElementType, std::experimental::extents<ext ...>, Layout, Accessor> x)
{
// Call custom overload if available else call std implementation
if constexpr(is_custom_scale_avail<
decltype(execpolicy_mapper(exec)),
decltype(alpha),
decltype(x)
>::value) {

constexpr bool use_custom = is_custom_scale_avail<
decltype(execpolicy_mapper(exec)), decltype(alpha), decltype(x)
>::value;

if constexpr(use_custom) {
scale(execpolicy_mapper(exec), alpha, x);
} else {
linalg_scale(std::experimental::linalg::impl::inline_exec_t(), alpha, x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct default_exec_t {};
}


#if defined(LINALG_ENABLE_KOKKOS) && defined(LINALG_ENABLE_KOKKOS_DEFAULT)
#if defined(LINALG_ENABLE_KOKKOS) || defined(LINALG_ENABLE_KOKKOS_DEFAULT)
#include <experimental/__p1673_bits/kokkos-kernels/exec_policy_wrapper_kk.hpp>
#endif

Expand Down

0 comments on commit 21fbd5e

Please sign in to comment.