RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
reduce.hpp
Go to the documentation of this file.
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
2 // Copyright (c) Lawrence Livermore National Security, LLC and other
3 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
4 // files for dates and other details. No copyright assignment is required
5 // to contribute to RAJA.
6 //
7 // SPDX-License-Identifier: (BSD-3-Clause)
8 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
9 
10 #ifndef NEW_REDUCE_HIP_REDUCE_HPP
11 #define NEW_REDUCE_HIP_REDUCE_HPP
12 
13 #if defined(RAJA_HIP_ACTIVE)
14 
15 #include <hip/hip_runtime.h>
19 
20 namespace RAJA
21 {
22 namespace expt
23 {
24 namespace detail
25 {
26 
27 // Init
28 template<typename EXEC_POL, typename OP, typename T, typename VOp>
29 camp::concepts::enable_if<RAJA::type_traits::is_hip_policy<EXEC_POL>>
30 param_init(EXEC_POL const&,
31  Reducer<OP, T, VOp>& red,
32  RAJA::hip::detail::hipInfo& hi)
33 {
34  red.devicetarget =
35  RAJA::hip::pinned_mempool_type::getInstance().template malloc<T>(1);
36  red.device_mem.allocate(hi.gridDim.x * hi.gridDim.y * hi.gridDim.z);
37  red.device_count = RAJA::hip::device_zeroed_mempool_type::getInstance()
38  .template malloc<unsigned int>(1);
39 }
40 
41 // Combine
42 template<typename EXEC_POL, typename OP, typename T, typename VOp>
43 RAJA_HOST_DEVICE camp::concepts::enable_if<
45 param_combine(EXEC_POL const&, Reducer<OP, T, VOp>& red)
46 {
47  RAJA::hip::impl::expt::grid_reduce<typename EXEC_POL::IterationGetter, OP>(
48  red.devicetarget, red.getVal(), red.device_mem, red.device_count);
49 }
50 
51 // Resolve
52 template<typename EXEC_POL, typename OP, typename T, typename VOp>
53 camp::concepts::enable_if<RAJA::type_traits::is_hip_policy<EXEC_POL>>
54 param_resolve(EXEC_POL const&,
55  Reducer<OP, T, VOp>& red,
56  RAJA::hip::detail::hipInfo& hi)
57 {
58  // complete reduction
59  hi.res.wait();
60 
61  red.combineTarget(*red.devicetarget);
62 
63  // free memory
64  RAJA::hip::device_zeroed_mempool_type::getInstance().free(red.device_count);
65  red.device_count = nullptr;
66  red.device_mem.deallocate();
67  RAJA::hip::pinned_mempool_type::getInstance().free(red.devicetarget);
68  red.devicetarget = nullptr;
69 }
70 
71 } // namespace detail
72 } // namespace expt
73 } // namespace RAJA
74 
75 #endif
76 
77 #endif // NEW_REDUCE_HIP_REDUCE_HPP
Header file defining prototypes for routines used to manage memory for HIP reductions and other opera...
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
camp::concepts::enable_if< std::is_same< EXEC_POL, RAJA::seq_exec > > param_init(EXEC_POL const &, RAJA::detail::Name &)
Definition: kernel_name.hpp:24
camp::concepts::enable_if< concepts::negate< is_instance_of_Reducer< camp::decay< T > > >, concepts::negate< std::is_same< T, RAJA::detail::Name > > > param_combine(EXEC_POL const &, T &, const T &)
Definition: forall.hpp:97
camp::concepts::enable_if< std::is_same< EXEC_POL, RAJA::seq_exec > > param_resolve(EXEC_POL const &, RAJA::detail::Name &)
Definition: kernel_name.hpp:40
Definition: AlignedRangeIndexSetBuilders.cpp:35
Header file containing RAJA reduction templates for HIP execution.
Definition: PolicyBase.hpp:228