kokkos-utils
0.0.7
Toggle main menu visibility
Loading...
Searching...
No Matches
test_View.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/printers/View.hpp
"
11
#include "
kokkos-utils/tests/scoped/ExecutionSpace.hpp
"
12
13
using
execution_space
= Kokkos::DefaultExecutionSpace;
14
26
27
namespace
Kokkos::utils::tests::printers
28
{
29
30
using namespace
Kokkos::utils::printers
;
31
32
struct
PrintersTest
:
public
::testing::Test,
33
public
scoped::ExecutionSpace
<execution_space>
34
{};
35
37
TEST_F
(
PrintersTest
, Kokkos_View_0D)
38
{
39
const
Kokkos::View<double, execution_space> my_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, this->exec,
"my nice 0D view"
));
40
Kokkos::deep_copy(this->exec, my_view, 5.52);
41
this->exec.fence();
42
43
std::ostringstream oss;
44
oss << my_view;
45
EXPECT_EQ(oss.str(),
"[5.52]"
);
46
}
47
48
template
<concepts::ViewOfRank<1> ViewType>
49
struct
DeepAssign1D
50
{
51
ViewType
view
;
52
53
template
<std::
int
egral T>
54
KOKKOS_FUNCTION
void
operator()
(
const
T)
const
55
{
56
view
(0) = 1.5;
57
view
(1) = 96.;
58
view
(2) = 8.6;
59
view
(3) = 456.;
60
view
(4) = 456.15;
61
}
62
};
63
65
TEST_F
(
PrintersTest
, Kokkos_View_1D)
66
{
67
const
Kokkos::View<double*, execution_space> my_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, this->exec,
"my nice 1D view"
), 5);
68
Kokkos::parallel_for(Kokkos::RangePolicy<execution_space>(this->exec, 0, 1),
DeepAssign1D
{my_view});
69
this->exec.fence();
70
71
std::ostringstream oss;
72
oss << my_view;
73
EXPECT_EQ(oss.str(),
"[1.5, 96, 8.6, 456, 456.15]"
);
74
}
75
76
template
<concepts::ViewOfRank<1> ViewType>
77
struct
DeepAssign1DFormatting
78
{
79
ViewType
view
;
80
81
template
<std::
int
egral T>
82
KOKKOS_FUNCTION
void
operator()
(
const
T)
const
83
{
84
view
(0) = 1.5;
85
view
(1) = 96.;
86
view
(2) = 8.6;
87
view
(3) = 456.;
88
view
(4) = 456.15e15;
89
}
90
};
91
93
TEST_F
(
PrintersTest
, Kokkos_View_1D_formatting)
94
{
95
const
Kokkos::View<double*, execution_space> my_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, this->exec,
"my nice 1D view"
), 5);
96
Kokkos::parallel_for(Kokkos::RangePolicy<execution_space>(this->exec, 0, 1),
DeepAssign1DFormatting
{my_view});
97
this->exec.fence();
98
99
std::ostringstream oss;
100
oss << std::scientific;
101
oss.precision(12);
102
oss << my_view;
103
EXPECT_EQ(oss.str(),
"[1.500000000000e+00, 9.600000000000e+01, 8.600000000000e+00, 4.560000000000e+02, 4.561500000000e+17]"
);
104
}
105
106
template
<concepts::ViewOfRank<2> ViewType>
107
struct
DeepAssign2D
108
{
109
ViewType
view
;
110
111
template
<std::
int
egral T>
112
KOKKOS_FUNCTION
void
operator()
(
const
T)
const
113
{
114
view
(0, 0) = 1.;
115
view
(0, 1) = 2.;
116
view
(1, 0) = 3.;
117
view
(1, 1) = 4.;
118
}
119
};
120
122
TEST_F
(
PrintersTest
, Kokkos_View_2D)
123
{
124
const
Kokkos::View<double**, execution_space> my_view(Kokkos::view_alloc(Kokkos::WithoutInitializing, this->exec,
"my nice 2D view"
), 2, 2);
125
Kokkos::parallel_for(Kokkos::RangePolicy<execution_space>(this->exec, 0, 1),
DeepAssign2D
{my_view});
126
this->exec.fence();
127
128
std::ostringstream oss;
129
oss << my_view;
130
EXPECT_EQ(oss.str(),
"[[1, 2], [3, 4]]"
);
131
}
132
133
}
// namespace Kokkos::utils::tests::printers
ExecutionSpace.hpp
Kokkos::utils::printers
Definition
View.hpp:10
Kokkos::utils::tests::printers
Definition
test_View.cpp:28
Kokkos::utils::tests::printers::TEST_F
TEST_F(PrintersTest, Kokkos_View_0D)
Definition
test_View.cpp:37
View.hpp
Kokkos::utils::tests::printers::DeepAssign1DFormatting
Definition
test_View.cpp:78
Kokkos::utils::tests::printers::DeepAssign1DFormatting::operator()
KOKKOS_FUNCTION void operator()(const T) const
Definition
test_View.cpp:82
Kokkos::utils::tests::printers::DeepAssign1DFormatting::view
ViewType view
Definition
test_View.cpp:79
Kokkos::utils::tests::printers::DeepAssign1D
Definition
test_View.cpp:50
Kokkos::utils::tests::printers::DeepAssign1D::view
ViewType view
Definition
test_View.cpp:51
Kokkos::utils::tests::printers::DeepAssign1D::operator()
KOKKOS_FUNCTION void operator()(const T) const
Definition
test_View.cpp:54
Kokkos::utils::tests::printers::DeepAssign2D
Definition
test_View.cpp:108
Kokkos::utils::tests::printers::DeepAssign2D::operator()
KOKKOS_FUNCTION void operator()(const T) const
Definition
test_View.cpp:112
Kokkos::utils::tests::printers::DeepAssign2D::view
ViewType view
Definition
test_View.cpp:109
Kokkos::utils::tests::printers::PrintersTest
Definition
test_View.cpp:34
Kokkos::utils::tests::scoped::ExecutionSpace
Create a new execution space instance with RAII semantics.
Definition
ExecutionSpace.hpp:17
execution_space
Kokkos::DefaultExecutionSpace execution_space
Definition
test_InsertOp.cpp:13
tests
printers
test_View.cpp
Generated on
for kokkos-utils by
1.18.0