kokkos-utils 0.0.7
Loading...
Searching...
No Matches
test_InsertOp.cpp
Go to the documentation of this file.
1#include "gtest/gtest.h"
2
3#include "Kokkos_Macros.hpp"
4#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
5import kokkos.core;
6#else
7#include "Kokkos_Core.hpp"
8#endif
9
12
13using execution_space = Kokkos::DefaultExecutionSpace;
14
25
27{
28
29template <concepts::View view_t>
31{
32 view_t data;
33 int trials = 0;
35
36 template <typename Exec>
37 void apply(const Exec& exec) const
38 {
39 Kokkos::parallel_for(
40 "atomics::InsertMin",
41 Kokkos::RangePolicy<execution_space>(exec, 0, trials),
42 *this
43 );
44 }
45
46 template <std::integral T>
47 KOKKOS_FUNCTION
48 void operator()(const T trial) const
49 {
50 inserter.op(data, 0, trials - trial - 2);
51 inserter.op(data, 1, 2);
52 }
53};
54
56TEST(atomics, InsertMin)
57{
58 using view_t = Kokkos::View<int*, execution_space>;
59
60 constexpr int trials = 150;
61
62 const execution_space exec {};
63
64 const view_t data(Kokkos::view_alloc(exec, "data"), 2);
65
66 InsertMinTest{.data = data, .trials = trials}.apply(exec);
67 exec.fence();
68
69 const auto mirror = Kokkos::create_mirror_view_and_copy(Kokkos::DefaultHostExecutionSpace{}, data);
70
71 ASSERT_EQ(mirror(0), -1);
72 ASSERT_EQ(mirror(1), 0);
73}
74
75} // namespace Kokkos::utils::tests::atomics
Insert an element in a view at a specific index using Kokkos::atomic_min.
Definition InsertOp.hpp:17
KOKKOS_FUNCTION void op(const ViewType &values, const IndexType index, ValueType &&value) const
Definition InsertOp.hpp:20
KOKKOS_FUNCTION void operator()(const T trial) const
Kokkos::DefaultExecutionSpace execution_space