Skip to content

Commit c7bcb47

Browse files
authored
Merge pull request #52 from SCOREC/jk/testCabBackend
Jk/test cab backend
2 parents 8c5e7df + ddfdad4 commit c7bcb47

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ meshfields_add_exe(OmegahCoordFieldTest test/testOmegahCoordField.cpp)
164164
meshfields_add_exe(ExceptionTest test/testExceptions.cpp)
165165

166166
if(MeshFields_USE_Cabana)
167+
meshfields_add_exe(ControllerPerformance test/testControllerPerformance.cpp)
167168
meshfields_add_exe(CabanaTests test/testCabana.cpp)
168169
test_func(CabanaTests ./CabanaTests)
170+
test_func(ControllerPerformance ./ControllerPerformance)
169171
endif()
170172

171173
test_func(KokkosTests ./KokkosTests)

test/testControllerPerformance.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "CabanaController.hpp"
2+
#include "KokkosController.hpp"
3+
#include "MeshField.hpp"
4+
#include "MeshField_For.hpp"
5+
#include "MeshField_SimdFor.hpp"
6+
#include <Kokkos_Core.hpp>
7+
#include <chrono>
8+
#include <iomanip>
9+
#include <iostream>
10+
#include <sstream>
11+
using ExecutionSpace = Kokkos::DefaultExecutionSpace;
12+
using MemorySpace = Kokkos::DefaultExecutionSpace::memory_space;
13+
#ifndef DIM1
14+
#define DIM1 3
15+
#endif
16+
#ifndef DIM2
17+
#define DIM2 3
18+
#endif
19+
int main(int argc, char **argv) {
20+
int n = 1000, runs = 10;
21+
bool which = true;
22+
if (argc == 4) {
23+
n = atoi(argv[1]);
24+
runs = atoi(argv[2]);
25+
which = atoi(argv[3]);
26+
}
27+
Kokkos::initialize(argc, argv);
28+
if (which) {
29+
double avg = 0;
30+
using cab = MeshField::CabanaController<ExecutionSpace, MemorySpace,
31+
int[DIM1][DIM2]>;
32+
cab cabCtrlr({n});
33+
auto cabField = MeshField::makeField<cab, 0>(cabCtrlr);
34+
auto cabDim4 = KOKKOS_LAMBDA(const int &i, const int &j, const int &k) {
35+
cabField(i, j, k) = i + j + k;
36+
};
37+
for (int i = 0; i < runs; ++i) {
38+
auto start = std::chrono::system_clock::now();
39+
MeshField::simd_parallel_for(cabCtrlr, {0, 0, 0}, {n, DIM1, DIM2},
40+
cabDim4, "CabTest");
41+
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
42+
std::chrono::system_clock::now() - start);
43+
avg += duration.count();
44+
}
45+
avg = avg / runs;
46+
std::cout << std::fixed << std::setprecision(1) << avg << std::endl;
47+
} else {
48+
double avg = 0;
49+
using kokkos =
50+
MeshField::KokkosController<MemorySpace, ExecutionSpace, int ***>;
51+
kokkos kokkosCtrlr({n, DIM1, DIM2});
52+
auto kokkosField = MeshField::makeField<kokkos, 0>(kokkosCtrlr);
53+
auto kokkosDim4 = KOKKOS_LAMBDA(const int &i, const int &j, const int &k) {
54+
kokkosField(i, j, k) = i + j + k;
55+
};
56+
for (int i = 0; i < runs; ++i) {
57+
auto start = std::chrono::system_clock::now();
58+
MeshField::parallel_for(ExecutionSpace(), {0, 0, 0}, {n, DIM1, DIM2},
59+
kokkosDim4, "KokkosTest");
60+
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
61+
std::chrono::system_clock::now() - start);
62+
avg += duration.count();
63+
}
64+
avg = avg / runs;
65+
std::cout << std::fixed << std::setprecision(1) << avg << std::endl;
66+
}
67+
Kokkos::finalize();
68+
return 0;
69+
}

0 commit comments

Comments
 (0)