kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
test_InsertOp.cpp
Go to the documentation of this file.
1#include "gtest/gtest.h"
2
3#include "Kokkos_Core.hpp"
4
7
8using execution_space = Kokkos::DefaultExecutionSpace;
9
20
22{
23
24template <concepts::View view_t>
26{
27 view_t data;
28 int trials = 0;
30
31 template <typename Exec>
32 void apply(const Exec& exec) const
33 {
34 Kokkos::parallel_for(
35 "atomics::InsertMin",
36 Kokkos::RangePolicy<execution_space>(exec, 0, trials),
37 *this
38 );
39 }
40
41 template <std::integral T>
42 KOKKOS_FUNCTION
43 void operator()(const T trial) const
44 {
45 inserter.op(data, 0, trials - trial - 2);
46 inserter.op(data, 1, 2);
47 }
48};
49
51TEST(atomics, InsertMin)
52{
53 using view_t = Kokkos::View<int*, execution_space>;
54
55 constexpr int trials = 150;
56
57 const execution_space exec {};
58
59 const view_t data(Kokkos::view_alloc(exec, "data"), 2);
60
61 InsertMinTest{.data = data, .trials = trials}.apply(exec);
62 exec.fence();
63
64 const auto mirror = Kokkos::create_mirror_view_and_copy(Kokkos::DefaultHostExecutionSpace{}, data);
65
66 ASSERT_EQ(mirror(0), -1);
67 ASSERT_EQ(mirror(1), 0);
68}
69
70} // 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 operator()(const T trial) const
Kokkos::DefaultExecutionSpace execution_space