Skip to content

Commit

Permalink
Add new OpenMP 4.5 affinity API
Browse files Browse the repository at this point in the history
This change introduces the new OpenMP 4.5 affinity api surrounding
OpenMP Places. There are six new entry points:

Typically called in serial region:
 * omp_get_num_places - returns the number of places available to the execution
       environment in the place list.
 * omp_get_place_num_procs - returns the number of processors available to the
       execution environment in the specified place.
 * omp_get_place_proc_ids - returns the numerical identifiers of the processors
       available to the execution environment in the specified place.

Typically called inside parallel region:
 * omp_get_place_num - returns the place number of the place to which the
       encountering thread is bound.
 * omp_get_partition_num_places - returns the number of places in the place
       partition of the innermost implicit task.
 * omp_get_partition_place_nums - returns the list of place numbers
       corresponding to the places in the place-var ICV of the innermost
       implicit task.

Differential Revision: http://reviews.llvm.org/D17417

llvm-svn: 261915
  • Loading branch information
jpeyton52 committed Feb 25, 2016
1 parent 29d8eef commit 2f7c077
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 0 deletions.
6 changes: 6 additions & 0 deletions openmp/runtime/src/dllexports
Expand Up @@ -498,6 +498,12 @@ kmp_set_warnings_off 780
omp_init_lock_with_hint 870
omp_init_nest_lock_with_hint 871
omp_get_max_task_priority 872
omp_get_num_places 873
omp_get_place_num_procs 874
omp_get_place_proc_ids 875
omp_get_place_num 876
omp_get_partition_num_places 877
omp_get_partition_place_nums 878
%endif # OMP_41

%ifndef stub
Expand Down
8 changes: 8 additions & 0 deletions openmp/runtime/src/include/41/omp.h.var
Expand Up @@ -153,6 +153,14 @@

extern omp_proc_bind_t __KAI_KMPC_CONVENTION omp_get_proc_bind (void);

/* OpenMP 4.5 affinity API */
extern int __KAI_KMPC_CONVENTION omp_get_num_places (void);
extern int __KAI_KMPC_CONVENTION omp_get_place_num_procs (int);
extern void __KAI_KMPC_CONVENTION omp_get_place_proc_ids (int, int *);
extern int __KAI_KMPC_CONVENTION omp_get_place_num (void);
extern int __KAI_KMPC_CONVENTION omp_get_partition_num_places (void);
extern void __KAI_KMPC_CONVENTION omp_get_partition_place_nums (int *);

extern void * __KAI_KMPC_CONVENTION kmp_malloc (size_t);
extern void * __KAI_KMPC_CONVENTION kmp_calloc (size_t, size_t);
extern void * __KAI_KMPC_CONVENTION kmp_realloc (void *, size_t);
Expand Down
32 changes: 32 additions & 0 deletions openmp/runtime/src/include/41/omp_lib.f.var
Expand Up @@ -180,6 +180,38 @@
integer (kind=omp_proc_bind_kind) omp_get_proc_bind
end function omp_get_proc_bind

function omp_get_num_places()
use omp_lib_kinds
integer (kind=omp_integer_kind) omp_get_num_places
end function omp_get_num_places

function omp_get_place_num_procs(place_num)
use omp_lib_kinds
integer (kind=omp_integer_kind) place_num
integer (kind=omp_integer_kind) omp_get_place_num_procs
end function omp_get_place_num_procs

subroutine omp_get_place_proc_ids(place_num, ids)
use omp_lib_kinds
integer (kind=omp_integer_kind) place_num
integer (kind=kmp_pointer_kind) ids
end subroutine omp_get_place_proc_ids

function omp_get_place_num()
use omp_lib_kinds
integer (kind=omp_integer_kind) omp_get_place_num
end function omp_get_place_num

function omp_get_partition_num_places()
use omp_lib_kinds
integer (kind=omp_integer_kind) omp_get_partition_num_places
end function omp_get_partition_num_places

subroutine omp_get_partition_place_nums(place_nums)
use omp_lib_kinds
integer (kind=kmp_pointer_kind) place_nums
end subroutine omp_get_partition_place_nums

function omp_get_wtime()
double precision omp_get_wtime
end function omp_get_wtime
Expand Down
32 changes: 32 additions & 0 deletions openmp/runtime/src/include/41/omp_lib.f90.var
Expand Up @@ -183,6 +183,38 @@
integer (kind=omp_proc_bind_kind) omp_get_proc_bind
end function omp_get_proc_bind

function omp_get_num_places() bind(c)
use omp_lib_kinds
integer (kind=omp_integer_kind) omp_get_num_places
end function omp_get_num_places

function omp_get_place_num_procs(place_num) bind(c)
use omp_lib_kinds
integer (kind=omp_integer_kind), value :: place_num
integer (kind=omp_integer_kind) omp_get_place_num_procs
end function omp_get_place_num_procs

subroutine omp_get_place_proc_ids(place_num, ids) bind(c)
use omp_lib_kinds
integer (kind=omp_integer_kind), value :: place_num
integer (kind=kmp_pointer_kind) ids
end subroutine omp_get_place_proc_ids

function omp_get_place_num() bind(c)
use omp_lib_kinds
integer (kind=omp_integer_kind) omp_get_place_num
end function omp_get_place_num

function omp_get_partition_num_places() bind(c)
use omp_lib_kinds
integer (kind=omp_integer_kind) omp_get_partition_num_places
end function omp_get_partition_num_places

subroutine omp_get_partition_place_nums(place_nums) bind(c)
use omp_lib_kinds
integer (kind=kmp_pointer_kind) place_nums
end subroutine omp_get_partition_place_nums

function omp_get_wtime() bind(c)
use omp_lib_kinds
real (kind=kmp_double_kind) omp_get_wtime
Expand Down
32 changes: 32 additions & 0 deletions openmp/runtime/src/include/41/omp_lib.h.var
Expand Up @@ -172,6 +172,38 @@
integer (kind=omp_proc_bind_kind) omp_get_proc_bind
end function omp_get_proc_bind

function omp_get_num_places() bind(c)
import
integer (kind=omp_integer_kind) omp_get_num_places
end function omp_get_num_places

function omp_get_place_num_procs(place_num) bind(c)
import
integer (kind=omp_integer_kind), value :: place_num
integer (kind=omp_integer_kind) omp_get_place_num_procs
end function omp_get_place_num_procs

subroutine omp_get_place_proc_ids(place_num, ids) bind(c)
import
integer (kind=omp_integer_kind), value :: place_num
integer (kind=kmp_pointer_kind) ids
end subroutine omp_get_place_proc_ids

function omp_get_place_num() bind(c)
import
integer (kind=omp_integer_kind) omp_get_place_num
end function omp_get_place_num

function omp_get_partition_num_places() bind(c)
import
integer (kind=omp_integer_kind) omp_get_partition_num_places
end function omp_get_partition_num_places

subroutine omp_get_partition_place_nums(place_nums) bind(c)
import
integer (kind=kmp_pointer_kind) place_nums
end subroutine omp_get_partition_place_nums

function omp_get_wtime() bind(c)
double precision omp_get_wtime
end function omp_get_wtime
Expand Down
133 changes: 133 additions & 0 deletions openmp/runtime/src/kmp_ftn_entry.h
Expand Up @@ -676,6 +676,139 @@ xexpand(FTN_GET_PROC_BIND)( void )
#endif
}

#if OMP_41_ENABLED
int FTN_STDCALL
FTN_GET_NUM_PLACES( void )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return 0;
#else
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
return __kmp_affinity_num_masks;
#endif
}

int FTN_STDCALL
FTN_GET_PLACE_NUM_PROCS( int place_num )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return 0;
#else
int i;
int retval = 0;
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
if ( place_num < 0 || place_num >= (int)__kmp_affinity_num_masks )
return 0;
kmp_affin_mask_t *mask = KMP_CPU_INDEX(__kmp_affinity_masks, place_num);
KMP_CPU_SET_ITERATE(i, mask) {
if ( !KMP_CPU_ISSET(i, mask) )
continue;
++retval;
}
return retval;
#endif
}

void FTN_STDCALL
FTN_GET_PLACE_PROC_IDS( int place_num, int *ids )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
// Nothing.
#else
int i,j;
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
if ( place_num < 0 || place_num >= (int)__kmp_affinity_num_masks )
return;
kmp_affin_mask_t *mask = KMP_CPU_INDEX(__kmp_affinity_masks, place_num);
j = 0;
KMP_CPU_SET_ITERATE(i, mask) {
if ( !KMP_CPU_ISSET(i, mask) )
continue;
ids[j++] = i;
}
#endif
}

int FTN_STDCALL
FTN_GET_PLACE_NUM( void )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return -1;
#else
int gtid;
kmp_info_t *thread;
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
gtid = __kmp_entry_gtid();
thread = __kmp_thread_from_gtid(gtid);
if ( thread->th.th_current_place < 0 )
return -1;
return thread->th.th_current_place;
#endif
}

int FTN_STDCALL
FTN_GET_PARTITION_NUM_PLACES( void )
{
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
return 0;
#else
int gtid, num_places, first_place, last_place;
kmp_info_t *thread;
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
gtid = __kmp_entry_gtid();
thread = __kmp_thread_from_gtid(gtid);
first_place = thread->th.th_first_place;
last_place = thread->th.th_last_place;
if ( first_place < 0 || last_place < 0 )
return 0;
if ( first_place <= last_place )
num_places = last_place - first_place + 1;
else
num_places = __kmp_affinity_num_masks - first_place + last_place + 1;
return num_places;
#endif
}

void FTN_STDCALL
FTN_GET_PARTITION_PLACE_NUMS( int *place_nums ) {
#if defined(KMP_STUB) || !KMP_AFFINITY_SUPPORTED
// Nothing.
#else
int i, gtid, place_num, first_place, last_place, start, end;
kmp_info_t *thread;
if ( ! TCR_4(__kmp_init_middle) ) {
__kmp_middle_initialize();
}
gtid = __kmp_entry_gtid();
thread = __kmp_thread_from_gtid(gtid);
first_place = thread->th.th_first_place;
last_place = thread->th.th_last_place;
if ( first_place < 0 || last_place < 0 )
return;
if ( first_place <= last_place ) {
start = first_place;
end = last_place;
} else {
start = last_place;
end = first_place;
}
for (i = 0, place_num = start; place_num <= end; ++place_num, ++i) {
place_nums[i] = place_num;
}
#endif
}
#endif

int FTN_STDCALL
xexpand(FTN_GET_NUM_TEAMS)( void )
{
Expand Down
24 changes: 24 additions & 0 deletions openmp/runtime/src/kmp_ftn_os.h
Expand Up @@ -115,6 +115,12 @@

#if OMP_41_ENABLED
#define FTN_GET_MAX_TASK_PRIORITY omp_get_max_task_priority
#define FTN_GET_NUM_PLACES omp_get_num_places
#define FTN_GET_PLACE_NUM_PROCS omp_get_place_num_procs
#define FTN_GET_PLACE_PROC_IDS omp_get_place_proc_ids
#define FTN_GET_PLACE_NUM omp_get_place_num
#define FTN_GET_PARTITION_NUM_PLACES omp_get_partition_num_places
#define FTN_GET_PARTITION_PLACE_NUMS omp_get_partition_place_nums
#endif

#endif /* KMP_FTN_PLAIN */
Expand Down Expand Up @@ -216,6 +222,12 @@

#if OMP_41_ENABLED
#define FTN_GET_MAX_TASK_PRIORITY omp_get_max_task_priority_
#define FTN_GET_NUM_PLACES omp_get_num_places_
#define FTN_GET_PLACE_NUM_PROCS omp_get_place_num_procs_
#define FTN_GET_PLACE_PROC_IDS omp_get_place_proc_ids_
#define FTN_GET_PLACE_NUM omp_get_place_num_
#define FTN_GET_PARTITION_NUM_PLACES omp_get_partition_num_places_
#define FTN_GET_PARTITION_PLACE_NUMS omp_get_partition_place_nums_
#endif

#endif /* KMP_FTN_APPEND */
Expand Down Expand Up @@ -317,6 +329,12 @@

#if OMP_41_ENABLED
#define FTN_GET_MAX_TASK_PRIORITY OMP_GET_MAX_TASK_PRIORITY
#define FTN_GET_NUM_PLACES OMP_GET_NUM_PLACES
#define FTN_GET_PLACE_NUM_PROCS OMP_GET_PLACE_NUM_PROCS
#define FTN_GET_PLACE_PROC_IDS OMP_GET_PLACE_PROC_IDS
#define FTN_GET_PLACE_NUM OMP_GET_PLACE_NUM
#define FTN_GET_PARTITION_NUM_PLACES OMP_GET_PARTITION_NUM_PLACES
#define FTN_GET_PARTITION_PLACE_NUMS OMP_GET_PARTITION_PLACE_NUMS
#endif

#endif /* KMP_FTN_UPPER */
Expand Down Expand Up @@ -418,6 +436,12 @@

#if OMP_41_ENABLED
#define FTN_GET_MAX_TASK_PRIORITY OMP_GET_MAX_TASK_PRIORITY_
#define FTN_GET_NUM_PLACES OMP_GET_NUM_PLACES_
#define FTN_GET_PLACE_NUM_PROCS OMP_GET_PLACE_NUM_PROCS_
#define FTN_GET_PLACE_PROC_IDS OMP_GET_PLACE_PROC_IDS_
#define FTN_GET_PLACE_NUM OMP_GET_PLACE_NUM_
#define FTN_GET_PARTITION_NUM_PLACES OMP_GET_PARTITION_NUM_PLACES_
#define FTN_GET_PARTITION_PLACE_NUMS OMP_GET_PARTITION_PLACE_NUMS_
#endif

#endif /* KMP_FTN_UAPPEND */
Expand Down
7 changes: 7 additions & 0 deletions openmp/runtime/src/kmp_runtime.c
Expand Up @@ -3834,6 +3834,13 @@ __kmp_register_root( int initial_thread )
KMP_DEBUG_ASSERT( root->r.r_hot_team->t.t_bar[ bs_forkjoin_barrier ].b_arrived == KMP_INIT_BARRIER_STATE );

#if KMP_AFFINITY_SUPPORTED
# if OMP_40_ENABLED
root_thread->th.th_current_place = KMP_PLACE_UNDEFINED;
root_thread->th.th_new_place = KMP_PLACE_UNDEFINED;
root_thread->th.th_first_place = KMP_PLACE_UNDEFINED;
root_thread->th.th_last_place = KMP_PLACE_UNDEFINED;
# endif

if ( TCR_4(__kmp_init_middle) ) {
__kmp_affinity_set_init_mask( gtid, TRUE );
}
Expand Down

0 comments on commit 2f7c077

Please sign in to comment.