RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
Conditional.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_Conditional_HPP
21 #define RAJA_pattern_kernel_Conditional_HPP
22 
23 
24 #include "RAJA/config.hpp"
25 
27 
28 #include <iostream>
29 #include <type_traits>
30 
31 namespace RAJA
32 {
33 namespace statement
34 {
35 
36 
41 template<typename Condition, typename... EnclosedStmts>
42 struct If : public internal::Statement<camp::nil, EnclosedStmts...>
43 {};
44 
49 template<long value>
50 struct Value
51 {
52 
53  template<typename Data>
54  RAJA_HOST_DEVICE RAJA_INLINE static long eval(Data const&)
55  {
56  return value;
57  }
58 };
59 
64 template<typename L, typename R>
65 struct Equals
66 {
67 
68  template<typename Data>
69  RAJA_HOST_DEVICE RAJA_INLINE static bool eval(Data const& data)
70  {
71  return L::eval(data) == R::eval(data);
72  }
73 };
74 
79 template<typename L, typename R>
80 struct NotEquals
81 {
82 
83  template<typename Data>
84  RAJA_HOST_DEVICE RAJA_INLINE static bool eval(Data const& data)
85  {
86  return L::eval(data) != R::eval(data);
87  }
88 };
89 
94 template<typename L, typename R>
95 struct Or
96 {
97 
98  template<typename Data>
99  RAJA_HOST_DEVICE RAJA_INLINE static bool eval(Data const& data)
100  {
101  return L::eval(data) || R::eval(data);
102  }
103 };
104 
109 template<typename L, typename R>
110 struct And
111 {
112 
113  template<typename Data>
114  RAJA_HOST_DEVICE RAJA_INLINE static bool eval(Data const& data)
115  {
116  return L::eval(data) && R::eval(data);
117  }
118 };
119 
124 template<typename L, typename R>
125 struct LessThan
126 {
127 
128  template<typename Data>
129  RAJA_HOST_DEVICE RAJA_INLINE static bool eval(Data const& data)
130  {
131  return L::eval(data) < R::eval(data);
132  }
133 };
134 
139 template<typename L, typename R>
141 {
142 
143  template<typename Data>
144  RAJA_HOST_DEVICE RAJA_INLINE static bool eval(Data const& data)
145  {
146  return L::eval(data) <= R::eval(data);
147  }
148 };
149 
154 template<typename L, typename R>
156 {
157 
158  template<typename Data>
159  RAJA_HOST_DEVICE RAJA_INLINE static bool eval(Data const& data)
160  {
161  return L::eval(data) > R::eval(data);
162  }
163 };
164 
169 template<typename L, typename R>
171 {
172 
173  template<typename Data>
174  RAJA_HOST_DEVICE RAJA_INLINE static bool eval(Data const& data)
175  {
176  return L::eval(data) >= R::eval(data);
177  }
178 };
179 
184 template<typename L>
185 struct Not
186 {
187 
188  template<typename Data>
189  RAJA_HOST_DEVICE RAJA_INLINE static bool eval(Data const& data)
190  {
191  return !(L::eval(data));
192  }
193 };
194 
195 
196 } // end namespace statement
197 
198 namespace internal
199 {
200 
201 
202 template<typename Condition, typename... EnclosedStmts, typename Types>
203 struct StatementExecutor<statement::If<Condition, EnclosedStmts...>, Types>
204 {
205 
206 
207  template<typename Data>
208  static RAJA_INLINE void exec(Data&& data)
209  {
210 
211  if (Condition::eval(data))
212  {
213  execute_statement_list<camp::list<EnclosedStmts...>, Types>(
214  std::forward<Data>(data));
215  }
216  }
217 };
218 
219 
220 } // namespace internal
221 } // end namespace RAJA
222 
223 
224 #endif /* RAJA_pattern_kernel_HPP */
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
RAJA_INLINE void execute_statement_list(Data &&data)
Definition: StatementList.hpp:84
Definition: AlignedRangeIndexSetBuilders.cpp:35
Header file for loop kernel internals.
static RAJA_INLINE void exec(Data &&data)
Definition: Conditional.hpp:208
Definition: Statement.hpp:48
Definition: Statement.hpp:35
Definition: Conditional.hpp:111
RAJA_HOST_DEVICE static RAJA_INLINE bool eval(Data const &data)
Definition: Conditional.hpp:114
Definition: Conditional.hpp:66
RAJA_HOST_DEVICE static RAJA_INLINE bool eval(Data const &data)
Definition: Conditional.hpp:69
Definition: Conditional.hpp:171
RAJA_HOST_DEVICE static RAJA_INLINE bool eval(Data const &data)
Definition: Conditional.hpp:174
Definition: Conditional.hpp:156
RAJA_HOST_DEVICE static RAJA_INLINE bool eval(Data const &data)
Definition: Conditional.hpp:159
Definition: Conditional.hpp:43
Definition: Conditional.hpp:141
RAJA_HOST_DEVICE static RAJA_INLINE bool eval(Data const &data)
Definition: Conditional.hpp:144
Definition: Conditional.hpp:126
RAJA_HOST_DEVICE static RAJA_INLINE bool eval(Data const &data)
Definition: Conditional.hpp:129
Definition: Conditional.hpp:81
RAJA_HOST_DEVICE static RAJA_INLINE bool eval(Data const &data)
Definition: Conditional.hpp:84
Definition: Conditional.hpp:186
RAJA_HOST_DEVICE static RAJA_INLINE bool eval(Data const &data)
Definition: Conditional.hpp:189
Definition: Conditional.hpp:96
RAJA_HOST_DEVICE static RAJA_INLINE bool eval(Data const &data)
Definition: Conditional.hpp:99
Definition: Conditional.hpp:51
RAJA_HOST_DEVICE static RAJA_INLINE long eval(Data const &)
Definition: Conditional.hpp:54