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