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.
idx_abs_max: add customization point kokkos#96
Note the different behavior with kokkos-kernels, tracked in issue kokkos#114.
- Loading branch information
Showing
6 changed files
with
116 additions
and
4 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
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,42 @@ | ||
#include <experimental/linalg> | ||
#include <iostream> | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
std::cout << "idx_abs_max example: calling kokkos-kernels" << std::endl; | ||
|
||
std::size_t N = 10; | ||
Kokkos::initialize(argc,argv); | ||
{ | ||
using value_type = double; | ||
|
||
Kokkos::View<value_type*> a_view("A",N); | ||
value_type* a_ptr = a_view.data(); | ||
|
||
// Requires CTAD working, GCC 11.1 works but some others are buggy | ||
// std::experimental::mdspan a(a_ptr,N); | ||
using extents_type = std::experimental::extents<std::experimental::dynamic_extent>; | ||
std::experimental::mdspan<value_type, extents_type> a(a_ptr,N); | ||
a(0) = 0.5; | ||
a(1) = 0.2; | ||
a(2) = 0.1; | ||
a(3) = 0.4; | ||
a(4) = -0.8; | ||
a(5) = -1.7; | ||
a(6) = -0.3; | ||
a(7) = 0.5; | ||
a(8) = -1.7; | ||
a(9) = -0.9; | ||
|
||
namespace stdla = std::experimental::linalg; | ||
|
||
// This goes to the base implementation | ||
const auto idx = stdla::idx_abs_max(std::execution::seq, a); | ||
printf("Seq result = %i\n", idx); | ||
|
||
// This forwards to KokkosKernels (https://github.com/kokkos/kokkos-kernels | ||
const auto idx_kk = stdla::idx_abs_max(KokkosKernelsSTD::kokkos_exec<>(), a); | ||
printf("Kokkos result = %i\n", idx_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
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
24 changes: 24 additions & 0 deletions
24
...implementations/include/experimental/__p1673_bits/kokkos-kernels/blas1_idx_abs_max_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,24 @@ | ||
|
||
#ifndef LINALG_TPLIMPLEMENTATIONS_INCLUDE_EXPERIMENTAL_P1673_BITS_KOKKOSKERNELS_IDX_ABS_MAX_HPP_ | ||
#define LINALG_TPLIMPLEMENTATIONS_INCLUDE_EXPERIMENTAL_P1673_BITS_KOKKOSKERNELS_IDX_ABS_MAX_HPP_ | ||
|
||
#include <KokkosBlas1_iamax.hpp> | ||
|
||
namespace KokkosKernelsSTD { | ||
|
||
template<class ExecSpace, | ||
class ElementType, | ||
std::experimental::extents<>::size_type ext0, | ||
class Layout, | ||
class Accessor> | ||
auto idx_abs_max(kokkos_exec<ExecSpace>, | ||
std::experimental::mdspan<ElementType, std::experimental::extents<ext0>, Layout, Accessor> v) | ||
{ | ||
// note that -1 here, this is related to: | ||
// https://github.com/kokkos/stdBLAS/issues/114 | ||
|
||
return KokkosBlas::iamax(Impl::mdspan_to_view(v))-1; | ||
} | ||
|
||
} | ||
#endif |
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