-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_suite.h
114 lines (102 loc) · 2.65 KB
/
test_suite.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <Kokkos_Core.hpp>
#include <iostream>
using range2d_policy = Kokkos::MDRangePolicy<Kokkos::Rank<2>>;
template <typename T, int N, int M>
struct test_suite
{
using view_t = Kokkos::View<T***>;
view_t A = view_t ("A", N, N, M);
view_t B = view_t ("B", N, N, M);
view_t C = view_t ("C", N, N, M);
void init_views()
{
auto tmp_A = A;
auto tmp_B = B;
auto tmp_C = C;
Kokkos::parallel_for("init_views", range2d_policy ({0, 0}, {N, N}), KOKKOS_LAMBDA (const int i, const int j) {
for (int k=0; k<M; k++)
{
tmp_A(i,j,k) = 1;
tmp_B(i,j,k) = i/1000 - 0.5;
tmp_C(i,j,k) = j/1000;
}
});
}
void add()
{
auto tmp_B = B;
auto tmp_C = C;
Kokkos::parallel_for("add", range2d_policy ({0, 0}, {N, N}), KOKKOS_LAMBDA (const int i, const int j) {
for (int k=0; k<M; k++)
{
tmp_C(i, j, k) = tmp_B(i, j, k) + tmp_C(i, j, k);
}
});
}
void sub()
{
auto tmp_A = A;
auto tmp_B = B;
Kokkos::parallel_for("sub", range2d_policy ({0, 0}, {N, N}), KOKKOS_LAMBDA (const int i, const int j) {
for (int k=0; k<M; k++)
{
tmp_A(i, j, k) = tmp_B(i, j, k) - tmp_A(i, j, k);
}
});
}
void mult()
{
auto tmp_B = B;
auto tmp_C = C;
Kokkos::parallel_for("mult", range2d_policy ({0, 0}, {N, N}), KOKKOS_LAMBDA (const int i, const int j) {
for (int k=0; k<M; k++)
{
tmp_C(i, j, k) = tmp_C(i, j, k) * tmp_B(i, j, k);
}
});
}
void div()
{
auto tmp_B = B;
auto tmp_C = C;
Kokkos::parallel_for("div", range2d_policy ({0, 0}, {N, N}), KOKKOS_LAMBDA (const int i, const int j) {
for (int k=0; k<M; k++)
{
tmp_B(i, j, k) = tmp_B(i, j, k) / tmp_C(i, j, k);
}
});
}
void exp()
{
auto tmp_A = A;
auto tmp_C = C;
Kokkos::parallel_for("exp", range2d_policy ({0, 0}, {N, N}), KOKKOS_LAMBDA (const int i, const int j) {
for (int k=0; k<M; k++)
{
tmp_A(i, j, k) = Kokkos::Experimental::exp( tmp_C(i, j, k) );
}
});
}
void sin()
{
auto tmp_A = A;
auto tmp_C = C;
Kokkos::parallel_for("sin", range2d_policy ({0, 0}, {N, N}), KOKKOS_LAMBDA (const int i, const int j) {
for (int k=0; k<M; k++)
{
tmp_A(i, j, k) = Kokkos::Experimental::sin( tmp_C(i, j, k) );
}
});
}
void expsin()
{
auto tmp_A = A;
auto tmp_C = C;
Kokkos::parallel_for("expsin", range2d_policy ({0, 0}, {N, N}), KOKKOS_LAMBDA (const int i, const int j) {
for (int k=0; k<M; k++)
{
tmp_A(i, j, k) = Kokkos::Experimental::exp( Kokkos::Experimental::sin( tmp_C(i, j, k)) );
}
});
}
};