45 void apply(LHS &lhs, RHS rhs)
const;
48 static const RHS identity;
49 void fold(RHS &rhs1, RHS rhs2)
const;
53 template <
typename REDOP>
66 size_t rhs_stride,
size_t count,
const void *
userdata);
68 size_t rhs_stride,
size_t count,
const void *
userdata);
70 size_t rhs2_stride,
size_t count,
const void *
userdata);
72 size_t rhs2_stride,
size_t count,
const void *
userdata);
78 void *cuda_apply_excl_fn, *cuda_apply_nonexcl_fn;
79 void *cuda_fold_excl_fn, *cuda_fold_nonexcl_fn;
85 void *cudaLaunchKernel_fn;
88 void *cudaGetFuncBySymbol_fn;
94 void *hip_apply_excl_fn, *hip_apply_nonexcl_fn;
95 void *hip_fold_excl_fn, *hip_fold_nonexcl_fn;
110 , cuda_apply_excl_fn(0)
111 , cuda_apply_nonexcl_fn(0)
112 , cuda_fold_excl_fn(0)
113 , cuda_fold_nonexcl_fn(0)
114 , cudaLaunchKernel_fn(0)
115 , cudaGetFuncBySymbol_fn(0)
118 , hip_apply_excl_fn(0)
119 , hip_apply_nonexcl_fn(0)
120 , hip_fold_excl_fn(0)
121 , hip_fold_nonexcl_fn(0)
125 template <
class REDOP>
136 static_assert(std::is_trivially_copyable<ReductionOp<REDOP>>::value &&
137 std::is_trivially_destructible<ReductionOp<REDOP>>::value,
138 "ReductionOp<REDOP> must be trivially copyable/destructible");
151 namespace ReductionKernels {
152 template <
typename REDOP,
bool EXCL>
154 size_t rhs_stride,
size_t count,
const void *userdata)
156 const REDOP *redop =
static_cast<const REDOP *
>(userdata);
157 for(
size_t i = 0; i < count; i++) {
158 redop->template apply<EXCL>(*
static_cast<typename REDOP::LHS *
>(lhs_ptr),
159 *
static_cast<const typename REDOP::RHS *
>(rhs_ptr));
160 lhs_ptr =
static_cast<char *
>(lhs_ptr) + lhs_stride;
161 rhs_ptr =
static_cast<const char *
>(rhs_ptr) + rhs_stride;
165 template <
typename REDOP,
bool EXCL>
167 size_t rhs2_stride,
size_t count,
const void *userdata)
169 const REDOP *redop =
static_cast<const REDOP *
>(userdata);
170 for(
size_t i = 0; i < count; i++) {
171 redop->template fold<EXCL>(*
static_cast<typename REDOP::RHS *
>(rhs1_ptr),
172 *
static_cast<const typename REDOP::RHS *
>(rhs2_ptr));
173 rhs1_ptr =
static_cast<char *
>(rhs1_ptr) + rhs1_stride;
174 rhs2_ptr =
static_cast<const char *
>(rhs2_ptr) + rhs2_stride;
179#if defined(REALM_USE_CUDA) && defined(__CUDACC__)
183 template <
typename T>
184 struct HasHasCudaReductions {
191 struct AltnerativeDefinition {
192 static const bool has_cuda_reductions =
false;
194 template <
typename T2>
195 struct Combined :
public T2,
public AltnerativeDefinition {};
196 template <
typename T2, T2>
197 struct CheckAmbiguous {};
198 template <
typename T2>
200 has_member(CheckAmbiguous<
const bool *, &Combined<T2>::has_cuda_reductions> *);
201 template <
typename T2>
202 static YES has_member(...);
203 const static bool value =
sizeof(has_member<T>(0)) ==
sizeof(YES);
206 template <
typename T,
bool OK>
207 struct MaybeAddCudaReductions;
208 template <
typename T>
209 struct MaybeAddCudaReductions<T, false> {
210 static void if_member_exists(ReductionOpUntyped *redop){};
211 static void if_member_is_true(ReductionOpUntyped *redop){};
213 template <
typename T>
214 struct MaybeAddCudaReductions<T, true> {
215 static void if_member_exists(ReductionOpUntyped *redop)
217 MaybeAddCudaReductions<T, T::has_cuda_reductions>::if_member_is_true(redop);
219 static void if_member_is_true(ReductionOpUntyped *redop)
221 Cuda::add_cuda_redop_kernels<T>(redop);
226#if defined(REALM_USE_HIP) && (defined(__CUDACC__) || defined(__HIPCC__))
230 template <
typename T>
231 struct HasHasHipReductions {
238 struct AltnerativeDefinition {
239 static const bool has_hip_reductions =
false;
241 template <
typename T2>
242 struct Combined :
public T2,
public AltnerativeDefinition {};
243 template <
typename T2, T2>
244 struct CheckAmbiguous {};
245 template <
typename T2>
247 has_member(CheckAmbiguous<
const bool *, &Combined<T2>::has_hip_reductions> *);
248 template <
typename T2>
249 static YES has_member(...);
250 const static bool value =
sizeof(has_member<T>(0)) ==
sizeof(YES);
253 template <
typename T,
bool OK>
254 struct MaybeAddHipReductions;
255 template <
typename T>
256 struct MaybeAddHipReductions<T, false> {
257 static void if_member_exists(ReductionOpUntyped *redop){};
258 static void if_member_is_true(ReductionOpUntyped *redop){};
260 template <
typename T>
261 struct MaybeAddHipReductions<T, true> {
262 static void if_member_exists(ReductionOpUntyped *redop)
264 MaybeAddHipReductions<T, T::has_hip_reductions>::if_member_is_true(redop);
266 static void if_member_is_true(ReductionOpUntyped *redop)
268 Hip::add_hip_redop_kernels<T>(redop);
273 template <
typename REDOP>
293#if defined(REALM_USE_CUDA) && defined(__CUDACC__)
296 MaybeAddCudaReductions<REDOP, HasHasCudaReductions<REDOP>::value>::if_member_exists(
299#if defined(REALM_USE_HIP) && (defined(__CUDACC__) || defined(__HIPCC__))
302 MaybeAddHipReductions<REDOP, HasHasHipReductions<REDOP>::value>::if_member_exists(
Realm::ReductionOp< REDOP > ReductionOp
Definition prealm.h:88
void cpu_apply_wrapper(void *lhs_ptr, size_t lhs_stride, const void *rhs_ptr, size_t rhs_stride, size_t count, const void *userdata)
Definition redop.h:153
void cpu_fold_wrapper(void *rhs1_ptr, size_t rhs1_stride, const void *rhs2_ptr, size_t rhs2_stride, size_t count, const void *userdata)
Definition redop.h:166
Definition activemsg.h:38
size_t sizeof_lhs
Definition redop.h:58
static ReductionOpUntyped * create_reduction_op(void)
Definition redop.h:126
void(* cpu_apply_nonexcl_fn)(void *lhs_ptr, size_t lhs_stride, const void *rhs_ptr, size_t rhs_stride, size_t count, const void *userdata)
Definition redop.h:67
size_t sizeof_this
Definition redop.h:57
void(* cpu_fold_nonexcl_fn)(void *rhs1_ptr, size_t rhs1_stride, const void *rhs2_ptr, size_t rhs2_stride, size_t count, const void *userdata)
Definition redop.h:71
ReductionOpUntyped()
Definition redop.h:98
static ReductionOpUntyped * clone_reduction_op(const ReductionOpUntyped *redop)
void * identity
Definition redop.h:61
void * userdata
Definition redop.h:62
size_t sizeof_rhs
Definition redop.h:59
size_t sizeof_userdata
Definition redop.h:60
void(* cpu_fold_excl_fn)(void *rhs1_ptr, size_t rhs1_stride, const void *rhs2_ptr, size_t rhs2_stride, size_t count, const void *userdata)
Definition redop.h:69
void(* cpu_apply_excl_fn)(void *lhs_ptr, size_t lhs_stride, const void *rhs_ptr, size_t rhs_stride, size_t count, const void *userdata)
Definition redop.h:65
ReductionOp()
Definition redop.h:279
REDOP userdata_val
Definition redop.h:277
REDOP::RHS identity_val
Definition redop.h:276