Skip to content

Commit

Permalink
New implementation of OpenMP 5.0 detached tasks.
Browse files Browse the repository at this point in the history
Patch by Alex Duran

Differential Revision: https://reviews.llvm.org/D62485

llvm-svn: 363799
  • Loading branch information
AndreyChurbanov committed Jun 19, 2019
1 parent 982a1cf commit 405037c
Show file tree
Hide file tree
Showing 12 changed files with 564 additions and 24 deletions.
3 changes: 2 additions & 1 deletion openmp/runtime/src/dllexports
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ kmpc_set_disp_num_buffers 267
__kmpc_pause_resource 273
__kmpc_task_reduction_modifier_init 274
__kmpc_task_reduction_modifier_fini 275
# __kmpc_task_allow_completion_event 276
__kmpc_task_allow_completion_event 276
__kmpc_taskred_init 277
__kmpc_taskred_modifier_init 278
%endif
Expand Down Expand Up @@ -572,6 +572,7 @@ kmp_set_disp_num_buffers 890
omp_pause_resource 756
omp_pause_resource_all 757
omp_get_supported_active_levels 758
omp_fulfill_event 759

omp_null_allocator DATA
omp_default_mem_alloc DATA
Expand Down
9 changes: 9 additions & 0 deletions openmp/runtime/src/include/50/omp.h.var
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@
extern void __KAI_KMPC_CONVENTION omp_display_affinity(char const *);
extern size_t __KAI_KMPC_CONVENTION omp_capture_affinity(char *, size_t, char const *);

/* OpenMP 5.0 events */
# if defined(_WIN32)
// On Windows cl and icl do not support 64-bit enum, let's use integer then.
typedef omp_uintptr_t omp_event_handle_t;
# else
typedef enum omp_event_handle_t { KMP_EVENT_MAX_HANDLE = UINTPTR_MAX } omp_event_handle_t;
# endif
extern void __KAI_KMPC_CONVENTION omp_fulfill_event ( omp_event_handle_t event );

/* OpenMP 5.0 Pause Resources */
typedef enum omp_pause_resource_t {
omp_pause_resume = 0,
Expand Down
10 changes: 10 additions & 0 deletions openmp/runtime/src/include/50/omp_lib.f.var
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

integer, parameter :: omp_pause_resource_kind = omp_integer_kind
integer, parameter :: omp_depend_kind = int_ptr_kind()
integer, parameter :: omp_event_handle_kind = int_ptr_kind()

end module omp_lib_kinds

Expand Down Expand Up @@ -351,6 +352,11 @@
integer (kind=omp_integer_kind) omp_get_supported_active_levels
end function omp_get_supported_active_levels

subroutine omp_fulfill_event(event)
use omp_lib_kinds
integer (kind=omp_event_handle_kind) event
end subroutine omp_fulfill_event

subroutine omp_init_lock(svar)
!DIR$ IF(__INTEL_COMPILER.GE.1400)
!DIR$ attributes known_intrinsic :: omp_init_lock
Expand Down Expand Up @@ -705,6 +711,7 @@
!dec$ attributes alias:'OMP_PAUSE_RESOURCE' :: omp_pause_resource
!dec$ attributes alias:'OMP_PAUSE_RESOURCE_ALL' :: omp_pause_resource_all
!dec$ attributes alias:'OMP_GET_SUPPORTED_ACTIVE_LEVELS' :: omp_get_supported_active_levels
!dec$ attributes alias:'OMP_FULFILL_EVENT' :: omp_fulfill_event

!dec$ attributes alias:'OMP_CONTROL_TOOL' :: omp_control_tool
!dec$ attributes alias:'OMP_SET_AFFINITY_FORMAT' :: omp_set_affinity_format
Expand Down Expand Up @@ -796,6 +803,7 @@
!dec$ attributes alias:'_OMP_PAUSE_RESOURCE' :: omp_pause_resource
!dec$ attributes alias:'_OMP_PAUSE_RESOURCE_ALL' :: omp_pause_resource_all
!dec$ attributes alias:'_OMP_GET_SUPPORTED_ACTIVE_LEVELS' :: omp_get_supported_active_levels
!dec$ attributes alias:'_OMP_FULFILL_EVENT' :: omp_fulfill_event

!dec$ attributes alias:'_OMP_CONTROL_TOOL' :: omp_control_tool
!dec$ attributes alias:'_OMP_SET_AFFINITY_FORMAT' :: omp_set_affinity_format
Expand Down Expand Up @@ -890,6 +898,7 @@
!dec$ attributes alias:'omp_pause_resource_' :: omp_pause_resource
!dec$ attributes alias:'omp_pause_resource_all_' :: omp_pause_resource_all
!dec$ attributes alias:'omp_get_supported_active_levels_' :: omp_get_supported_active_levels
!dec$ attributes alias:'omp_fulfill_event_' :: omp_fulfill_event

!dec$ attributes alias:'omp_set_affinity_format_' :: omp_set_affinity_format
!dec$ attributes alias:'omp_get_affinity_format_' :: omp_get_affinity_format
Expand Down Expand Up @@ -983,6 +992,7 @@
!dec$ attributes alias:'_omp_pause_resource_' :: omp_pause_resource
!dec$ attributes alias:'_omp_pause_resource_all_' :: omp_pause_resource_all
!dec$ attributes alias:'_omp_get_supported_active_levels_' :: omp_get_supported_active_levels
!dec$ attributes alias:'_omp_fulfill_event_' :: omp_fulfill_event

!dec$ attributes alias:'_omp_init_lock_'::omp_init_lock
!dec$ attributes alias:'_omp_init_lock_with_hint_'::omp_init_lock_with_hint
Expand Down
6 changes: 6 additions & 0 deletions openmp/runtime/src/include/50/omp_lib.f90.var
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

integer, parameter :: omp_pause_resource_kind = omp_integer_kind
integer, parameter :: omp_depend_kind = c_intptr_t
integer, parameter :: omp_event_handle_kind = c_intptr_t

end module omp_lib_kinds

Expand Down Expand Up @@ -366,6 +367,11 @@
integer (kind=omp_integer_kind) omp_get_supported_active_levels
end function omp_get_supported_active_levels

subroutine omp_fulfill_event(event) bind(c)
use omp_lib_kinds
integer (kind=omp_event_handle_kind), value :: event
end subroutine omp_fulfill_event

subroutine omp_init_lock(svar) bind(c)
!DIR$ IF(__INTEL_COMPILER.GE.1400)
!DIR$ attributes known_intrinsic :: omp_init_lock
Expand Down
9 changes: 9 additions & 0 deletions openmp/runtime/src/include/50/omp_lib.h.var
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
parameter(omp_pause_resource_kind=omp_integer_kind)
integer omp_depend_kind
parameter(omp_depend_kind=int_ptr_kind())
integer omp_event_handle_kind
parameter(omp_event_handle_kind=int_ptr_kind())

integer(kind=omp_integer_kind)openmp_version
parameter(openmp_version=@LIBOMP_OMP_YEAR_MONTH@)
Expand Down Expand Up @@ -442,6 +444,11 @@
integer (kind=omp_integer_kind) omp_get_supported_active_levels
end function omp_get_supported_active_levels

subroutine omp_fulfill_event(event) bind(c)
import
integer (kind=omp_event_handle_kind), value :: event
end subroutine omp_fulfill_event

subroutine omp_init_lock(svar) bind(c)
!DIR$ IF(__INTEL_COMPILER.GE.1400)
!DIR$ attributes known_intrinsic :: omp_init_lock
Expand Down Expand Up @@ -778,6 +785,7 @@
!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_pause_resource
!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_pause_resource_all
!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_supported_active_levels
!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_fulfill_event
!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_num_teams
!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_get_team_num
!DIR$ ATTRIBUTES OFFLOAD:MIC :: omp_init_lock
Expand Down Expand Up @@ -860,6 +868,7 @@
!$omp declare target(omp_pause_resource )
!$omp declare target(omp_pause_resource_all )
!$omp declare target(omp_get_supported_active_levels )
!$omp declare target(omp_fulfill_event)
!$omp declare target(omp_get_num_teams )
!$omp declare target(omp_get_team_num )
!$omp declare target(omp_init_lock )
Expand Down
29 changes: 28 additions & 1 deletion openmp/runtime/src/kmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#define TASK_IMPLICIT 0
#define TASK_PROXY 1
#define TASK_FULL 0
#define TASK_DETACHABLE 1
#define TASK_UNDETACHABLE 0

#define KMP_CANCEL_THREADS
#define KMP_THREAD_ATTR
Expand Down Expand Up @@ -2269,6 +2271,19 @@ typedef struct kmp_task_affinity_info {
kmp_int32 reserved : 30;
} flags;
} kmp_task_affinity_info_t;

typedef enum kmp_event_type_t {
KMP_EVENT_UNINITIALIZED = 0,
KMP_EVENT_ALLOW_COMPLETION = 1
} kmp_event_type_t;

typedef struct {
kmp_event_type_t type;
kmp_tas_lock_t lock;
union {
kmp_task_t *task;
} ed;
} kmp_event_t;
#endif

#endif
Expand Down Expand Up @@ -2304,7 +2319,8 @@ typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
context of the RTL) */
unsigned priority_specified : 1; /* set if the compiler provides priority
setting for the task */
unsigned reserved : 10; /* reserved for compiler use */
unsigned detachable : 1; /* 1 == can detach */
unsigned reserved : 9; /* reserved for compiler use */
#else
unsigned reserved : 12; /* reserved for compiler use */
#endif
Expand Down Expand Up @@ -2372,6 +2388,9 @@ struct kmp_taskdata { /* aligned during dynamic allocation */
// GOMP sends in a copy function for copy constructors
void (*td_copy_func)(void *, void *);
#endif
#if OMP_50_ENABLED
kmp_event_t td_allow_completion_event;
#endif
#if OMPT_SUPPORT
ompt_task_info_t ompt_task_info;
#endif
Expand Down Expand Up @@ -3642,6 +3661,14 @@ extern void __kmp_init_implicit_task(ident_t *loc_ref, kmp_info_t *this_thr,
int set_curr_task);
extern void __kmp_finish_implicit_task(kmp_info_t *this_thr);
extern void __kmp_free_implicit_task(kmp_info_t *this_thr);

#ifdef OMP_50_ENABLED
extern kmp_event_t *__kmpc_task_allow_completion_event(ident_t *loc_ref,
int gtid,
kmp_task_t *task);
extern void __kmp_fulfill_event(kmp_event_t *event);
#endif

int __kmp_execute_tasks_32(kmp_info_t *thread, kmp_int32 gtid,
kmp_flag_32 *flag, int final_spin,
int *thread_finished,
Expand Down
7 changes: 7 additions & 0 deletions openmp/runtime/src/kmp_ftn_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,12 @@ int FTN_STDCALL FTN_GET_SUPPORTED_ACTIVE_LEVELS(void) {
#endif
}

void FTN_STDCALL FTN_FULFILL_EVENT(kmp_event_t *event) {
#ifndef KMP_STUB
__kmp_fulfill_event(event);
#endif
}

#endif // OMP_50_ENABLED

// GCC compatibility (versioned symbols)
Expand Down Expand Up @@ -1493,6 +1499,7 @@ KMP_VERSION_SYMBOL(FTN_GET_PARTITION_PLACE_NUMS, 45, "OMP_4.5");
// KMP_VERSION_SYMBOL(FTN_PAUSE_RESOURCE, 50, "OMP_5.0");
// KMP_VERSION_SYMBOL(FTN_PAUSE_RESOURCE_ALL, 50, "OMP_5.0");
// KMP_VERSION_SYMBOL(FTN_GET_SUPPORTED_ACTIVE_LEVELS, 50, "OMP_5.0");
// KMP_VERSION_SYMBOL(FTN_FULFILL_EVENT, 50, "OMP_5.0");
#endif

#endif // KMP_USE_VERSION_SYMBOLS
Expand Down
4 changes: 4 additions & 0 deletions openmp/runtime/src/kmp_ftn_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
#define FTN_PAUSE_RESOURCE omp_pause_resource
#define FTN_PAUSE_RESOURCE_ALL omp_pause_resource_all
#define FTN_GET_SUPPORTED_ACTIVE_LEVELS omp_get_supported_active_levels
#define FTN_FULFILL_EVENT omp_fulfill_event
#endif

#endif /* KMP_FTN_PLAIN */
Expand Down Expand Up @@ -278,6 +279,7 @@
#define FTN_PAUSE_RESOURCE omp_pause_resource_
#define FTN_PAUSE_RESOURCE_ALL omp_pause_resource_all_
#define FTN_GET_SUPPORTED_ACTIVE_LEVELS omp_get_supported_active_levels_
#define FTN_FULFILL_EVENT omp_fulfill_event_
#endif

#endif /* KMP_FTN_APPEND */
Expand Down Expand Up @@ -410,6 +412,7 @@
#define FTN_PAUSE_RESOURCE OMP_PAUSE_RESOURCE
#define FTN_PAUSE_RESOURCE_ALL OMP_PAUSE_RESOURCE_ALL
#define FTN_GET_SUPPORTED_ACTIVE_LEVELS OMP_GET_SUPPORTED_ACTIVE_LEVELS
#define FTN_FULFILL_EVENT OMP_FULFILL_EVENT
#endif

#endif /* KMP_FTN_UPPER */
Expand Down Expand Up @@ -544,6 +547,7 @@
#define FTN_PAUSE_RESOURCE OMP_PAUSE_RESOURCE_
#define FTN_PAUSE_RESOURCE_ALL OMP_PAUSE_RESOURCE_ALL_
#define FTN_GET_SUPPORTED_ACTIVE_LEVELS OMP_GET_SUPPORTED_ACTIVE_LEVELS_
#define FTN_FULFILL_EVENT OMP_FULFILL_EVENT_
#endif

#endif /* KMP_FTN_UAPPEND */
Expand Down
Loading

0 comments on commit 405037c

Please sign in to comment.