Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • k202174/demo
1 result
Show changes
Commits on Source (2)
......@@ -17,7 +17,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) {
......@@ -31,6 +32,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) ----- "
......@@ -85,6 +92,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;
......@@ -567,6 +601,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);
......