Skip to content

Commit 268c5d6

Browse files
authored
Merge pull request #596 from LLNL/add-kokkos-nodal-accum
This PR adds a Kokkos variant for NODAL_ACCUMULATION_3D.
2 parents eab7885 + 32e79ab commit 268c5d6

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_subdirectory(common)
1212
add_subdirectory(basic)
1313
add_subdirectory(basic-kokkos)
1414
add_subdirectory(apps)
15+
add_subdirectory(apps-kokkos)
1516
add_subdirectory(lcals)
1617
add_subdirectory(lcals-kokkos)
1718
add_subdirectory(polybench)
@@ -23,6 +24,7 @@ add_subdirectory(comm)
2324
set(RAJA_PERFSUITE_LIBS
2425
common
2526
apps
27+
apps-kokkos
2628
basic
2729
basic-kokkos
2830
lcals

src/apps-kokkos/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
###############################################################################
2+
# Copyright (c) 2017-25, Lawrence Livermore National Security, LLC
3+
# and RAJA Performance Suite project contributors.
4+
# See the RAJAPerf/LICENSE file for details.
5+
#
6+
# SPDX-License-Identifier: (BSD-3-Clause)
7+
###############################################################################
8+
9+
10+
blt_add_library(
11+
NAME apps-kokkos
12+
SOURCES
13+
NODAL_ACCUMULATION_3D-Kokkos.cpp
14+
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../apps
15+
DEPENDS_ON common ${RAJA_PERFSUITE_DEPENDS}
16+
)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
2+
// Copyright (c) 2017-25, Lawrence Livermore National Security, LLC
3+
// and RAJA Performance Suite project contributors.
4+
// See the RAJAPerf/LICENSE file for details.
5+
//
6+
// SPDX-License-Identifier: (BSD-3-Clause)
7+
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
8+
9+
#include "NODAL_ACCUMULATION_3D.hpp"
10+
11+
#if defined(RUN_KOKKOS)
12+
#include "common/KokkosViewUtils.hpp"
13+
#include <iostream>
14+
#include "AppsData.hpp"
15+
16+
namespace rajaperf
17+
{
18+
namespace apps
19+
{
20+
21+
void NODAL_ACCUMULATION_3D::runKokkosVariant(VariantID vid)
22+
{
23+
const Index_type run_reps = getRunReps();
24+
const Index_type ibegin = 0;
25+
const Index_type iend = getActualProblemSize(); //m_domain->n_real_zones;
26+
27+
NODAL_ACCUMULATION_3D_DATA_SETUP;
28+
29+
if ( vid == Kokkos_Lambda ) {
30+
int jp = m_domain->jp;
31+
int kp = m_domain->kp;
32+
auto real_zones_v = getViewFromPointer(real_zones, iend);
33+
auto vol_v = getViewFromPointer(vol, m_nodal_array_length);
34+
auto x_v = getViewFromPointer(x, m_nodal_array_length);
35+
36+
using view_t = decltype(x_v);
37+
view_t x0_v = x_v;
38+
view_t x1_v(x_v.data() + 1, m_nodal_array_length - 1);
39+
view_t x2_v(x_v.data() + jp, m_nodal_array_length - jp);
40+
view_t x3_v(x_v.data() + jp, m_nodal_array_length - jp);
41+
view_t x4_v(x_v.data() + jp, m_nodal_array_length - jp);
42+
view_t x5_v(x_v.data() + kp, m_nodal_array_length - kp);
43+
view_t x6_v(x_v.data() + kp, m_nodal_array_length - kp);
44+
view_t x7_v(x_v.data() + kp, m_nodal_array_length - kp);
45+
46+
Kokkos::fence();
47+
startTimer();
48+
// Awkward expression for loop counter quiets C++20 compiler warning
49+
for (RepIndex_type irep = 0; irep < run_reps; ((irep = irep + 1), 0)) {
50+
Kokkos::parallel_for("NODAL_ACCUMULATION_3D", iend, KOKKOS_LAMBDA(Index_type ii) {
51+
Index_type i = real_zones_v(ii);
52+
Real_type val = 0.125 * vol_v(i);
53+
Kokkos::atomic_add(&x0_v(i), val);
54+
Kokkos::atomic_add(&x1_v(i), val);
55+
Kokkos::atomic_add(&x2_v(i), val);
56+
Kokkos::atomic_add(&x3_v(i), val);
57+
Kokkos::atomic_add(&x4_v(i), val);
58+
Kokkos::atomic_add(&x5_v(i), val);
59+
Kokkos::atomic_add(&x6_v(i), val);
60+
Kokkos::atomic_add(&x7_v(i), val);
61+
});
62+
}
63+
Kokkos::fence();
64+
stopTimer();
65+
66+
moveDataToHostFromKokkosView(x, x_v, m_nodal_array_length);
67+
68+
} else {
69+
getCout() << "\n NODAL_ACCUMULATION_3D : Unknown Kokkos variant id = " << vid << std::endl;
70+
}
71+
}
72+
73+
RAJAPERF_DEFAULT_TUNING_DEFINE_BOILERPLATE(NODAL_ACCUMULATION_3D, Kokkos, Kokkos_Lambda)
74+
75+
} // end namespace apps
76+
} // end namespace rajaperf
77+
78+
#endif // RAJA_ENABLE_CUDA

src/apps/NODAL_ACCUMULATION_3D.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ class NODAL_ACCUMULATION_3D : public KernelBase
8585
void defineOpenMPTargetVariantTunings();
8686
void defineCudaVariantTunings();
8787
void defineHipVariantTunings();
88+
void defineKokkosVariantTunings();
8889

8990
void runSeqVariant(VariantID vid);
9091
void runOpenMPVariant(VariantID vid);
9192
void runOpenMPTargetVariant(VariantID vid);
93+
void runKokkosVariant(VariantID vid);
9294

9395
template < size_t block_size >
9496
void runCudaVariantImpl(VariantID vid);

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
set(RAJA_PERFSUITE_TEST_EXECUTABLE_DEPENDS
1010
common
1111
apps
12+
apps-kokkos
1213
basic
1314
basic-kokkos
1415
lcals

0 commit comments

Comments
 (0)