[Openmp-commits] [openmp] r261915 - Add new OpenMP 4.5 affinity API
Jonathan Peyton via Openmp-commits
openmp-commits at lists.llvm.org
Thu Feb 25 10:49:52 PST 2016
Author: jlpeyton
Date: Thu Feb 25 12:49:52 2016
New Revision: 261915
URL: http://llvm.org/viewvc/llvm-project?rev=261915&view=rev
Log:
Add new OpenMP 4.5 affinity API
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
Modified:
openmp/trunk/runtime/src/dllexports
openmp/trunk/runtime/src/include/41/omp.h.var
openmp/trunk/runtime/src/include/41/omp_lib.f.var
openmp/trunk/runtime/src/include/41/omp_lib.f90.var
openmp/trunk/runtime/src/include/41/omp_lib.h.var
openmp/trunk/runtime/src/kmp_ftn_entry.h
openmp/trunk/runtime/src/kmp_ftn_os.h
openmp/trunk/runtime/src/kmp_runtime.c
Modified: openmp/trunk/runtime/src/dllexports
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/dllexports?rev=261915&r1=261914&r2=261915&view=diff
==============================================================================
--- openmp/trunk/runtime/src/dllexports (original)
+++ openmp/trunk/runtime/src/dllexports Thu Feb 25 12:49:52 2016
@@ -498,6 +498,12 @@ kmp_set_warnings_off
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
Modified: openmp/trunk/runtime/src/include/41/omp.h.var
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/include/41/omp.h.var?rev=261915&r1=261914&r2=261915&view=diff
==============================================================================
--- openmp/trunk/runtime/src/include/41/omp.h.var (original)
+++ openmp/trunk/runtime/src/include/41/omp.h.var Thu Feb 25 12:49:52 2016
@@ -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);
Modified: openmp/trunk/runtime/src/include/41/omp_lib.f.var
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/include/41/omp_lib.f.var?rev=261915&r1=261914&r2=261915&view=diff
==============================================================================
--- openmp/trunk/runtime/src/include/41/omp_lib.f.var (original)
+++ openmp/trunk/runtime/src/include/41/omp_lib.f.var Thu Feb 25 12:49:52 2016
@@ -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
Modified: openmp/trunk/runtime/src/include/41/omp_lib.f90.var
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/include/41/omp_lib.f90.var?rev=261915&r1=261914&r2=261915&view=diff
==============================================================================
--- openmp/trunk/runtime/src/include/41/omp_lib.f90.var (original)
+++ openmp/trunk/runtime/src/include/41/omp_lib.f90.var Thu Feb 25 12:49:52 2016
@@ -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
Modified: openmp/trunk/runtime/src/include/41/omp_lib.h.var
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/include/41/omp_lib.h.var?rev=261915&r1=261914&r2=261915&view=diff
==============================================================================
--- openmp/trunk/runtime/src/include/41/omp_lib.h.var (original)
+++ openmp/trunk/runtime/src/include/41/omp_lib.h.var Thu Feb 25 12:49:52 2016
@@ -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
Modified: openmp/trunk/runtime/src/kmp_ftn_entry.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_ftn_entry.h?rev=261915&r1=261914&r2=261915&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_ftn_entry.h (original)
+++ openmp/trunk/runtime/src/kmp_ftn_entry.h Thu Feb 25 12:49:52 2016
@@ -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 )
{
Modified: openmp/trunk/runtime/src/kmp_ftn_os.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_ftn_os.h?rev=261915&r1=261914&r2=261915&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_ftn_os.h (original)
+++ openmp/trunk/runtime/src/kmp_ftn_os.h Thu Feb 25 12:49:52 2016
@@ -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 */
@@ -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 */
@@ -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 */
@@ -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 */
Modified: openmp/trunk/runtime/src/kmp_runtime.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_runtime.c?rev=261915&r1=261914&r2=261915&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_runtime.c (original)
+++ openmp/trunk/runtime/src/kmp_runtime.c Thu Feb 25 12:49:52 2016
@@ -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 );
}
More information about the Openmp-commits
mailing list