Skip to content

Commit e525f0d

Browse files
committedSep 26, 2018
[OpenMP] Fix balanced affinity so thread's private affinity mask is updated
Balanced affinity only updated the thread's affinity with the operating system. This change also has the thread's private mask reflect that change as well so that any API that probes the thread's affinity mask will report the correct mask value. Differential Revision: https://reviews.llvm.org/D52379 llvm-svn: 343142
1 parent f929e2b commit e525f0d

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed
 

‎openmp/runtime/src/kmp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,7 @@ extern int __kmp_aux_get_affinity_max_proc();
33623362
extern int __kmp_aux_set_affinity_mask_proc(int proc, void **mask);
33633363
extern int __kmp_aux_unset_affinity_mask_proc(int proc, void **mask);
33643364
extern int __kmp_aux_get_affinity_mask_proc(int proc, void **mask);
3365-
extern void __kmp_balanced_affinity(int tid, int team_size);
3365+
extern void __kmp_balanced_affinity(kmp_info_t *th, int team_size);
33663366
#if KMP_OS_LINUX
33673367
extern int kmp_set_thread_affinity_mask_initial(void);
33683368
#endif

‎openmp/runtime/src/kmp_affinity.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -5012,8 +5012,10 @@ int __kmp_aux_get_affinity_mask_proc(int proc, void **mask) {
50125012
}
50135013

50145014
// Dynamic affinity settings - Affinity balanced
5015-
void __kmp_balanced_affinity(int tid, int nthreads) {
5015+
void __kmp_balanced_affinity(kmp_info_t *th, int nthreads) {
5016+
KMP_DEBUG_ASSERT(th);
50165017
bool fine_gran = true;
5018+
int tid = th->th.th_info.ds.ds_tid;
50175019

50185020
switch (__kmp_affinity_gran) {
50195021
case affinity_gran_fine:
@@ -5061,8 +5063,7 @@ void __kmp_balanced_affinity(int tid, int nthreads) {
50615063
KMP_DEBUG_ASSERT2(KMP_AFFINITY_CAPABLE(),
50625064
"Illegal set affinity operation when not capable");
50635065

5064-
kmp_affin_mask_t *mask;
5065-
KMP_CPU_ALLOC_ON_STACK(mask);
5066+
kmp_affin_mask_t *mask = th->th.th_affin_mask;
50665067
KMP_CPU_ZERO(mask);
50675068

50685069
if (fine_gran) {
@@ -5082,11 +5083,9 @@ void __kmp_balanced_affinity(int tid, int nthreads) {
50825083
__kmp_gettid(), tid, buf);
50835084
}
50845085
__kmp_set_system_affinity(mask, TRUE);
5085-
KMP_CPU_FREE_FROM_STACK(mask);
50865086
} else { // Non-uniform topology
50875087

5088-
kmp_affin_mask_t *mask;
5089-
KMP_CPU_ALLOC_ON_STACK(mask);
5088+
kmp_affin_mask_t *mask = th->th.th_affin_mask;
50905089
KMP_CPU_ZERO(mask);
50915090

50925091
int core_level = __kmp_affinity_find_core_level(
@@ -5250,7 +5249,6 @@ void __kmp_balanced_affinity(int tid, int nthreads) {
52505249
__kmp_gettid(), tid, buf);
52515250
}
52525251
__kmp_set_system_affinity(mask, TRUE);
5253-
KMP_CPU_FREE_FROM_STACK(mask);
52545252
}
52555253
}
52565254

‎openmp/runtime/src/kmp_barrier.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,7 @@ void __kmp_fork_barrier(int gtid, int tid) {
19701970
#if KMP_AFFINITY_SUPPORTED
19711971
// Call dynamic affinity settings
19721972
if (__kmp_affinity_type == affinity_balanced && team->t.t_size_changed) {
1973-
__kmp_balanced_affinity(tid, team->t.t_nproc);
1973+
__kmp_balanced_affinity(this_thr, team->t.t_nproc);
19741974
}
19751975
#endif // KMP_AFFINITY_SUPPORTED
19761976
#if OMP_40_ENABLED && KMP_AFFINITY_SUPPORTED

0 commit comments

Comments
 (0)
Please sign in to comment.