-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_nested_for.cpp
89 lines (73 loc) · 3.15 KB
/
benchmark_nested_for.cpp
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
#include <Kokkos_Core.hpp>
#include <benchmark/benchmark.h>
#include <brak/wrapper_array.hpp>
#include <brak/wrapper_subview.hpp>
void benchmark_set_wrapper_subview(benchmark::State &state) {
Kokkos::View<int ***, Kokkos::HostSpace> data{"data", 30, 30, 30};
Kokkos::View<int ***, Kokkos::HostSpace> dataTemp{"data", 30, 30, 30};
brak::WrapperSubview dataWrapper{data};
brak::WrapperSubview dataTempWrapper{dataTemp};
dataWrapper[14][14][14] = 1;
while (state.KeepRunning()) {
for (unsigned i = 1; i < data.extent(0) - 1; i++)
for (unsigned j = 1; j < data.extent(1) - 1; j++)
for (unsigned k = 1; k < data.extent(2) - 1; k++) {
dataTempWrapper[i][j][k] =
2 * dataWrapper[i][j][k] +
(dataWrapper[i - 1][j][k] + dataWrapper[i + 1][j][k] +
dataWrapper[i][j - 1][k] + dataWrapper[i][j + 1][k] +
dataWrapper[i][j][k - 1] + dataWrapper[i][j][k + 1]);
}
for (unsigned i = 0; i < data.extent(0); i++)
for (unsigned j = 0; j < data.extent(1); j++)
for (unsigned k = 0; k < data.extent(2); k++) {
dataWrapper[i][j][k] = dataTempWrapper[i][j][k];
}
}
}
BENCHMARK(benchmark_set_wrapper_subview);
void benchmark_set_wrapper_array(benchmark::State &state) {
Kokkos::View<int ***, Kokkos::HostSpace> data{"data", 30, 30, 30};
Kokkos::View<int ***, Kokkos::HostSpace> dataTemp{"data", 30, 30, 30};
brak::WrapperArray dataWrapper{data};
brak::WrapperArray dataTempWrapper{dataTemp};
dataWrapper[14][14][14] = 1;
while (state.KeepRunning()) {
for (unsigned i = 1; i < data.extent(0) - 1; i++)
for (unsigned j = 1; j < data.extent(1) - 1; j++)
for (unsigned k = 1; k < data.extent(2) - 1; k++) {
dataTempWrapper[i][j][k] =
2 * dataWrapper[i][j][k] +
(dataWrapper[i - 1][j][k] + dataWrapper[i + 1][j][k] +
dataWrapper[i][j - 1][k] + dataWrapper[i][j + 1][k] +
dataWrapper[i][j][k - 1] + dataWrapper[i][j][k + 1]);
}
for (unsigned i = 0; i < data.extent(0); i++)
for (unsigned j = 0; j < data.extent(1); j++)
for (unsigned k = 0; k < data.extent(2); k++) {
dataWrapper[i][j][k] = dataTempWrapper[i][j][k];
}
}
}
BENCHMARK(benchmark_set_wrapper_array);
void benchmark_set_view(benchmark::State &state) {
Kokkos::View<int ***, Kokkos::HostSpace> data{"data", 30, 30, 30};
Kokkos::View<int ***, Kokkos::HostSpace> dataTemp{"data", 30, 30, 30};
data(14, 14, 14) = 1;
while (state.KeepRunning()) {
for (unsigned i = 1; i < data.extent(0) - 1; i++)
for (unsigned j = 1; j < data.extent(1) - 1; j++)
for (unsigned k = 1; k < data.extent(2) - 1; k++) {
dataTemp(i, j, k) =
2 * data(i, j, k) +
(data(i - 1, j, k) + data(i + 1, j, k) + data(i, j - 1, k) +
data(i, j + 1, k) + data(i, j, k - 1) + data(i, j, k + 1));
}
for (unsigned i = 0; i < data.extent(0); i++)
for (unsigned j = 0; j < data.extent(1); j++)
for (unsigned k = 0; k < data.extent(2); k++) {
data(i, j, k) = dataTemp(i, j, k);
}
}
}
BENCHMARK(benchmark_set_view);