|
| 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 |
0 commit comments