Skip to content
Snippets Groups Projects

Adding scenario_1c with a 2D view and default layout

Merged Panos Adamidis requested to merge 2D_View_Loops into main
1 file
+ 40
2
Compare changes
  • Side-by-side
  • Inline
+ 40
2
@@ -15,7 +15,8 @@ Kokkos::Timer timer;
// constexpr int nlev = 90;
// constexpr int nproma = 55000;
// #define ENABLE_CHECK_BOUNDS
//#define ENABLE_CHECK_BOUNDS
//#define ENABLE_CHECK_BOUNDS_2D
static void validate(double* array, int nblocks, int nlev, int nproma) {
for (int i = 0; i < nblocks * nlev * nproma; ++i) {
@@ -29,6 +30,12 @@ KOKKOS_INLINE_FUNCTION void check_bounds(int i1, int i2, int i3, int n1, int n2,
#endif
}
KOKKOS_INLINE_FUNCTION void check_bounds_2d(int i1, int i2, int n1, int n2) {
#ifdef ENABLE_CHECK_BOUNDS_2D
assert(i1 >= 0 && i2 >= 0 && i1 < n1 && i2 < n2 );
#endif
}
void scenario_1(double* array, int nblocks, int nlev, int nproma, bool print = true) {
if (print)
std::cout << "scenario 1: Default layout; view(array, nblocks, nlev, nproma); d_view(jb, jk, jc) ----- "
@@ -83,6 +90,33 @@ void scenario_1b(double* array, int nblocks, int nlev, int nproma) {
}
void scenario_1c(double* array, int nblocks, int nlev, int nproma) {
std::cout << "scenario 1c: Default layout; view(array, ncells, nlev); d_view(jc, jk) ----- "
<< std::endl;
int ncells = nblocks*nproma;
Kokkos::View<double**, Kokkos::MemoryUnmanaged> d_view(array, ncells, nlev);
timer.reset();
Kokkos::parallel_for(
"", Kokkos::RangePolicy<>(0, ncells), KOKKOS_LAMBDA(const int jc) {
for (int jk = 0; jk < nlev; ++jk) {
#if defined(DEMO_DEVICE)
int p = jk * ncells + jc;
#else
int p = jc * nlev + jk;
#endif
check_bounds_2d(jc, jk, d_view.extent(0), d_view.extent(1));
d_view(jc, jk) = p;
}
});
Kokkos::fence();
printf("Time = %f ms\n\n", timer.seconds() * 1000);
}
void scenario_2(double* array, int nblocks, int nlev, int nproma, bool print = true) {
if (print)
std::cout << "scenario 2: Right layout; view(array, nproma, nlev, nblocks); d_view(jc, jk, jb) ----- " << std::endl;
@@ -455,6 +489,10 @@ int main() {
std::function<void(double*, int, int, int)> s_1b = scenario_1b;
openacc_calls(array, nblocks, nlev, nproma, s_1b);
memset(array, 0.0, sizeof(array));
std::function<void(double*, int, int, int)> s_1c = scenario_1c;
openacc_calls(array, nblocks, nlev, nproma, s_1c);
memset(array, 0.0, sizeof(array));
std::function<void(double*, int, int, int)> s_7b = scenario_7b;
openacc_calls(array, nblocks, nlev, nproma, s_7b);
@@ -477,4 +515,4 @@ int main() {
Kokkos::finalize();
return 0;
}
\ No newline at end of file
}
Loading