Skip to content

Commit d4de439

Browse files
committedNov 27, 2018
[OPENMP][NVPTX]Basic support for reductions across the teams.
Summary: Added functions __kmpc_nvptx_teams_reduce_nowait_simple and __kmpc_nvptx_teams_end_reduce_nowait_simple to implement basic support for reductions across the teams. Reviewers: gtbercea, kkwli0 Subscribers: guansong, jfb, caomhin, openmp-commits Differential Revision: https://reviews.llvm.org/D54967 llvm-svn: 347710
1 parent 00eae5e commit d4de439

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

‎openmp/libomptarget/deviceRTLs/nvptx/src/interface.h

+6
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ EXTERN int32_t __kmpc_nvptx_teams_reduce_nowait_simple_generic(
419419
int32_t global_tid, int32_t num_vars, size_t reduce_size, void *reduce_data,
420420
kmp_ShuffleReductFctPtr shflFct, kmp_InterWarpCopyFctPtr cpyFct,
421421
kmp_CopyToScratchpadFctPtr sratchFct, kmp_LoadReduceFctPtr ldFct);
422+
EXTERN int32_t __kmpc_nvptx_teams_reduce_nowait_simple(kmp_Ident *loc,
423+
int32_t global_tid,
424+
kmp_CriticalName *crit);
425+
EXTERN void __kmpc_nvptx_teams_end_reduce_nowait_simple(kmp_Ident *loc,
426+
int32_t global_tid,
427+
kmp_CriticalName *crit);
422428
EXTERN int32_t __kmpc_shuffle_int32(int32_t val, int16_t delta, int16_t size);
423429
EXTERN int64_t __kmpc_shuffle_int64(int64_t val, int16_t delta, int16_t size);
424430

‎openmp/libomptarget/deviceRTLs/nvptx/src/reduction.cu

+18
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,21 @@ int32_t __kmpc_nvptx_teams_reduce_nowait_simple_generic(
430430
/*isSPMDExecutionMode=*/false,
431431
/*isRuntimeUninitialized=*/true);
432432
}
433+
434+
EXTERN int32_t __kmpc_nvptx_teams_reduce_nowait_simple(kmp_Ident *loc,
435+
int32_t global_tid,
436+
kmp_CriticalName *crit) {
437+
if (checkSPMDMode(loc) && GetThreadIdInBlock() != 0)
438+
return 0;
439+
// The master thread of the team actually does the reduction.
440+
while (atomicCAS((uint32_t *)crit, 0, 1))
441+
;
442+
return 1;
443+
}
444+
445+
EXTERN void
446+
__kmpc_nvptx_teams_end_reduce_nowait_simple(kmp_Ident *loc, int32_t global_tid,
447+
kmp_CriticalName *crit) {
448+
(void)atomicExch((uint32_t *)crit, 0);
449+
}
450+

0 commit comments

Comments
 (0)