RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
For.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef RAJA_pattern_kernel_For_HPP
21 #define RAJA_pattern_kernel_For_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 #include <iostream>
26 #include <type_traits>
27 
30 
31 namespace RAJA
32 {
33 
34 namespace statement
35 {
36 
37 
43 template<camp::idx_t ArgumentId,
44  typename ExecPolicy = camp::nil,
45  typename... EnclosedStmts>
46 struct For : public internal::ForList,
47  public internal::ForTraitBase<ArgumentId, ExecPolicy>,
48  public internal::Statement<ExecPolicy, EnclosedStmts...>
49 {
50 
51  // TODO: add static_assert for valid policy in Pol
53 };
54 
55 
56 } // end namespace statement
57 
58 namespace internal
59 {
60 
66 template<camp::idx_t ArgumentId,
67  typename Data,
68  typename Types,
69  typename... EnclosedStmts>
70 struct ForWrapper : public GenericWrapper<Data, Types, EnclosedStmts...>
71 {
72 
73  using Base = GenericWrapper<Data, Types, EnclosedStmts...>;
74  using Base::Base;
76 
77  template<typename InIndexType>
78  RAJA_INLINE void operator()(InIndexType i)
79  {
80  Base::data.template assign_offset<ArgumentId>(i);
81  Base::exec();
82  }
83 };
84 
90 template<camp::idx_t ArgumentId,
91  typename ExecPolicy,
92  typename... EnclosedStmts,
93  typename Types>
95  statement::For<ArgumentId, ExecPolicy, EnclosedStmts...>,
96  Types>
97 {
98 
99 
100  template<typename Data>
101  static RAJA_INLINE void exec(Data&& data)
102  {
103 
104  // Set the argument type for this loop
106 
107  // Create a wrapper, just in case forall_impl needs to thread_privatize
108  ForWrapper<ArgumentId, Data, NewTypes, EnclosedStmts...> for_wrapper(data);
109 
110  auto len = segment_length<ArgumentId>(data);
111  using len_t = decltype(len);
112 
113  auto r = data.res;
114 
115  forall_impl(r, ExecPolicy {}, TypedRangeSegment<len_t>(0, len), for_wrapper,
116  RAJA::expt::get_empty_forall_param_pack());
117  }
118 };
119 
125 template<camp::idx_t ArgumentId, typename... EnclosedStmts, typename Types>
126 struct StatementExecutor<statement::For<ArgumentId, seq_exec, EnclosedStmts...>,
127  Types>
128 {
129 
130 
131  template<typename Data>
132  static RAJA_INLINE void exec(Data&& data)
133  {
134  // Set the argument type for this loop
136 
137  // Create a wrapper, just in case forall_impl needs to thread_privatize
138  ForWrapper<ArgumentId, Data, NewTypes, EnclosedStmts...> for_wrapper(data);
139 
140  auto len = segment_length<ArgumentId>(data);
141  using len_t = decltype(len);
142 
144  for (decltype(distance_it) i = 0; i < distance_it; ++i)
145  {
146  for_wrapper(*(begin_it + i));
147  }
148  }
149 };
150 
151 
152 } // namespace internal
153 } // end namespace RAJA
154 
155 
156 #endif /* RAJA_pattern_kernel_For_HPP */
setSegmentType< Types, Segment, camp::at_v< typename camp::decay< Data >::index_types_t, Segment > > setSegmentTypeFromData
Definition: LoopTypes.hpp:95
RAJA_INLINE void forall_impl(MultiPolicy< Selector, Policies... > p, Iterable &&iter, Body &&body)
Definition: MultiPolicy.hpp:96
Definition: AlignedRangeIndexSetBuilders.cpp:35
#define RAJA_EXTRACT_BED_IT(CONTAINER)
Definition: forall.hpp:32
Header file for loop kernel internals.
Segment class representing a contiguous range of typed indices.
Definition: RangeSegment.hpp:100
Definition: LoopData.hpp:48
Definition: LoopData.hpp:58
Definition: For.hpp:71
RAJA_INLINE void operator()(InIndexType i)
Definition: For.hpp:78
Definition: LoopData.hpp:196
RAJA_INLINE void exec()
Definition: LoopData.hpp:205
Definition: LoopData.hpp:216
Definition: Statement.hpp:48
Definition: Statement.hpp:35
Definition: IndexSet.hpp:70
Definition: For.hpp:49