kokkos-utils
0.0.7
Toggle main menu visibility
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
5
import
kokkos.core;
6
#else
7
#include "Kokkos_Core.hpp"
8
#endif
9
10
#include "
kokkos-utils/atomics/InsertOp.hpp
"
11
#include "
kokkos-utils/concepts/View.hpp
"
12
13
using
execution_space
= Kokkos::DefaultExecutionSpace;
14
25
26
namespace
Kokkos::utils::tests::atomics
27
{
28
29
template
<concepts::View view_t>
30
struct
InsertMinTest
31
{
32
view_t
data
;
33
int
trials
= 0;
34
utils::atomics::InsertMin
inserter
{};
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::
int
egral 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
56
TEST
(
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
InsertOp.hpp
View.hpp
Kokkos::utils::tests::atomics
Definition
test_InsertOp.cpp:27
Kokkos::utils::tests::atomics::TEST
TEST(atomics, InsertMin)
Definition
test_InsertOp.cpp:56
Kokkos::utils::atomics::InsertMin
Insert an element in a view at a specific index using Kokkos::atomic_min.
Definition
InsertOp.hpp:17
Kokkos::utils::atomics::InsertMin::op
KOKKOS_FUNCTION void op(const ViewType &values, const IndexType index, ValueType &&value) const
Definition
InsertOp.hpp:20
Kokkos::utils::tests::atomics::InsertMinTest
Definition
test_InsertOp.cpp:31
Kokkos::utils::tests::atomics::InsertMinTest::data
view_t data
Definition
test_InsertOp.cpp:32
Kokkos::utils::tests::atomics::InsertMinTest::apply
void apply(const Exec &exec) const
Definition
test_InsertOp.cpp:37
Kokkos::utils::tests::atomics::InsertMinTest::trials
int trials
Definition
test_InsertOp.cpp:33
Kokkos::utils::tests::atomics::InsertMinTest::inserter
utils::atomics::InsertMin inserter
Definition
test_InsertOp.cpp:34
Kokkos::utils::tests::atomics::InsertMinTest::operator()
KOKKOS_FUNCTION void operator()(const T trial) const
Definition
test_InsertOp.cpp:48
execution_space
Kokkos::DefaultExecutionSpace execution_space
Definition
test_InsertOp.cpp:13
tests
atomics
test_InsertOp.cpp
Generated on
for kokkos-utils by
1.18.0