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;
80 void *cuda_apply_excl_fn_advanced, *cuda_apply_nonexcl_fn_advanced;
81 void *cuda_fold_excl_fn_advanced, *cuda_fold_nonexcl_fn_advanced;
82 void *cuda_apply_excl_fn_transpose, *cuda_apply_nonexcl_fn_transpose;
83 void *cuda_fold_excl_fn_transpose, *cuda_fold_nonexcl_fn_transpose;
88 void *cudaLaunchKernel_fn;
91 void *cudaGetFuncBySymbol_fn;
97 void *hip_apply_excl_fn, *hip_apply_nonexcl_fn;
98 void *hip_fold_excl_fn, *hip_fold_nonexcl_fn;
99 void *hip_apply_excl_fn_advanced, *hip_apply_nonexcl_fn_advanced;
100 void *hip_fold_excl_fn_advanced, *hip_fold_nonexcl_fn_advanced;
101 void *hip_apply_excl_fn_transpose, *hip_apply_nonexcl_fn_transpose;
102 void *hip_fold_excl_fn_transpose, *hip_fold_nonexcl_fn_transpose;
117 , cuda_apply_excl_fn(0)
118 , cuda_apply_nonexcl_fn(0)
119 , cuda_fold_excl_fn(0)
120 , cuda_fold_nonexcl_fn(0)
121 , cuda_apply_excl_fn_advanced(0)
122 , cuda_apply_nonexcl_fn_advanced(0)
123 , cuda_fold_excl_fn_advanced(0)
124 , cuda_fold_nonexcl_fn_advanced(0)
125 , cuda_apply_excl_fn_transpose(0)
126 , cuda_apply_nonexcl_fn_transpose(0)
127 , cuda_fold_excl_fn_transpose(0)
128 , cuda_fold_nonexcl_fn_transpose(0)
129 , cudaLaunchKernel_fn(0)
130 , cudaGetFuncBySymbol_fn(0)
133 , hip_apply_excl_fn(0)
134 , hip_apply_nonexcl_fn(0)
135 , hip_fold_excl_fn(0)
136 , hip_fold_nonexcl_fn(0)
137 , hip_apply_excl_fn_advanced(0)
138 , hip_apply_nonexcl_fn_advanced(0)
139 , hip_fold_excl_fn_advanced(0)
140 , hip_fold_nonexcl_fn_advanced(0)
141 , hip_apply_excl_fn_transpose(0)
142 , hip_apply_nonexcl_fn_transpose(0)
143 , hip_fold_excl_fn_transpose(0)
144 , hip_fold_nonexcl_fn_transpose(0)
148 template <
class REDOP>
159 static_assert(std::is_trivially_copyable<ReductionOp<REDOP>>::value &&
160 std::is_trivially_destructible<ReductionOp<REDOP>>::value,
161 "ReductionOp<REDOP> must be trivially copyable/destructible");
174 namespace ReductionKernels {
175 template <
typename REDOP,
bool EXCL>
177 size_t rhs_stride,
size_t count,
const void *userdata)
179 const REDOP *redop =
static_cast<const REDOP *
>(userdata);
180 for(
size_t i = 0; i < count; i++) {
181 redop->template apply<EXCL>(*
static_cast<typename REDOP::LHS *
>(lhs_ptr),
182 *
static_cast<const typename REDOP::RHS *
>(rhs_ptr));
183 lhs_ptr =
static_cast<char *
>(lhs_ptr) + lhs_stride;
184 rhs_ptr =
static_cast<const char *
>(rhs_ptr) + rhs_stride;
188 template <
typename REDOP,
bool EXCL>
190 size_t rhs2_stride,
size_t count,
const void *userdata)
192 const REDOP *redop =
static_cast<const REDOP *
>(userdata);
193 for(
size_t i = 0; i < count; i++) {
194 redop->template fold<EXCL>(*
static_cast<typename REDOP::RHS *
>(rhs1_ptr),
195 *
static_cast<const typename REDOP::RHS *
>(rhs2_ptr));
196 rhs1_ptr =
static_cast<char *
>(rhs1_ptr) + rhs1_stride;
197 rhs2_ptr =
static_cast<const char *
>(rhs2_ptr) + rhs2_stride;
202#if defined(REALM_USE_CUDA) && defined(__CUDACC__)
206 template <
typename T>
207 struct HasHasCudaReductions {
214 struct AltnerativeDefinition {
215 static const bool has_cuda_reductions =
false;
217 template <
typename T2>
218 struct Combined :
public T2,
public AltnerativeDefinition {};
219 template <
typename T2, T2>
220 struct CheckAmbiguous {};
221 template <
typename T2>
223 has_member(CheckAmbiguous<
const bool *, &Combined<T2>::has_cuda_reductions> *);
224 template <
typename T2>
225 static YES has_member(...);
226 const static bool value =
sizeof(has_member<T>(0)) ==
sizeof(YES);
229 template <
typename T,
bool OK>
230 struct MaybeAddCudaReductions;
231 template <
typename T>
232 struct MaybeAddCudaReductions<T, false> {
233 static void if_member_exists(ReductionOpUntyped *redop){};
234 static void if_member_is_true(ReductionOpUntyped *redop){};
236 template <
typename T>
237 struct MaybeAddCudaReductions<T, true> {
238 static void if_member_exists(ReductionOpUntyped *redop)
240 MaybeAddCudaReductions<T, T::has_cuda_reductions>::if_member_is_true(redop);
242 static void if_member_is_true(ReductionOpUntyped *redop)
244 Cuda::add_cuda_redop_kernels<T>(redop);
249#if defined(REALM_USE_HIP) && (defined(__CUDACC__) || defined(__HIPCC__))
253 template <
typename T>
254 struct HasHasHipReductions {
261 struct AltnerativeDefinition {
262 static const bool has_hip_reductions =
false;
264 template <
typename T2>
265 struct Combined :
public T2,
public AltnerativeDefinition {};
266 template <
typename T2, T2>
267 struct CheckAmbiguous {};
268 template <
typename T2>
270 has_member(CheckAmbiguous<
const bool *, &Combined<T2>::has_hip_reductions> *);
271 template <
typename T2>
272 static YES has_member(...);
273 const static bool value =
sizeof(has_member<T>(0)) ==
sizeof(YES);
276 template <
typename T,
bool OK>
277 struct MaybeAddHipReductions;
278 template <
typename T>
279 struct MaybeAddHipReductions<T, false> {
280 static void if_member_exists(ReductionOpUntyped *redop){};
281 static void if_member_is_true(ReductionOpUntyped *redop){};
283 template <
typename T>
284 struct MaybeAddHipReductions<T, true> {
285 static void if_member_exists(ReductionOpUntyped *redop)
287 MaybeAddHipReductions<T, T::has_hip_reductions>::if_member_is_true(redop);
289 static void if_member_is_true(ReductionOpUntyped *redop)
291 Hip::add_hip_redop_kernels<T>(redop);
296 template <
typename REDOP>
316#if defined(REALM_USE_CUDA) && defined(__CUDACC__)
319 MaybeAddCudaReductions<REDOP, HasHasCudaReductions<REDOP>::value>::if_member_exists(
322#if defined(REALM_USE_HIP) && (defined(__CUDACC__) || defined(__HIPCC__))
325 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:176
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:189
Definition activemsg.h:42
size_t sizeof_lhs
Definition redop.h:58
static ReductionOpUntyped * create_reduction_op(void)
Definition redop.h:149
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:105
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:302
REDOP userdata_val
Definition redop.h:300
REDOP::RHS identity_val
Definition redop.h:299