Skip to content

Commit

Permalink
[OpenMP] Add num_threads clause list format and strict modifier suppo…
Browse files Browse the repository at this point in the history
…rt (#85466)

Add support to the runtime for 6.0 spec features that allow num_threads
clause to take a list, and also make use of the strict modifier.
Provides new compiler interface functions for these features.
  • Loading branch information
TerryLWilmarth authored Jun 24, 2024
1 parent f2d3d82 commit d30b082
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 20 deletions.
5 changes: 5 additions & 0 deletions openmp/runtime/src/dllexports
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,11 @@ kmp_set_disp_num_buffers 890
__kmpc_atomic_val_8_cas_cpt 2158
%endif

# No longer need to put ordinal numbers
__kmpc_push_num_threads_list
__kmpc_push_num_threads_strict
__kmpc_push_num_threads_list_strict

%endif

__kmpc_set_thread_limit
Expand Down
42 changes: 33 additions & 9 deletions openmp/runtime/src/kmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,15 @@ enum clock_function_type {
enum mic_type { non_mic, mic1, mic2, mic3, dummy };
#endif

// OpenMP 3.1 - Nested num threads array
typedef struct kmp_nested_nthreads_t {
int *nth;
int size;
int used;
} kmp_nested_nthreads_t;

extern kmp_nested_nthreads_t __kmp_nested_nth;

/* -- fast reduction stuff ------------------------------------------------ */

#undef KMP_FAST_REDUCTION_BARRIER
Expand Down Expand Up @@ -2965,6 +2974,12 @@ typedef struct KMP_ALIGN_CACHE kmp_base_info {
/* The data set by the primary thread at reinit, then R/W by the worker */
KMP_ALIGN_CACHE int
th_set_nproc; /* if > 0, then only use this request for the next fork */
int *th_set_nested_nth;
bool th_nt_strict; // num_threads clause has strict modifier
ident_t *th_nt_loc; // loc for strict modifier
int th_nt_sev; // error severity for strict modifier
const char *th_nt_msg; // error message for strict modifier
int th_set_nested_nth_sz;
#if KMP_NESTED_HOT_TEAMS
kmp_hot_team_ptr_t *th_hot_teams; /* array of hot teams */
#endif
Expand Down Expand Up @@ -3206,6 +3221,7 @@ typedef struct KMP_ALIGN_CACHE kmp_base_team {
void *t_stack_id; // team specific stack stitching id (for ittnotify)
#endif /* USE_ITT_BUILD */
distributedBarrier *b; // Distributed barrier data associated with team
kmp_nested_nthreads_t *t_nested_nth;
} kmp_base_team_t;

// Assert that the list structure fits and aligns within
Expand Down Expand Up @@ -3542,15 +3558,6 @@ extern enum mic_type __kmp_mic_type;
extern double __kmp_load_balance_interval; // load balance algorithm interval
#endif /* USE_LOAD_BALANCE */

// OpenMP 3.1 - Nested num threads array
typedef struct kmp_nested_nthreads_t {
int *nth;
int size;
int used;
} kmp_nested_nthreads_t;

extern kmp_nested_nthreads_t __kmp_nested_nth;

#if KMP_USE_ADAPTIVE_LOCKS

// Parameters for the speculative lock backoff system.
Expand Down Expand Up @@ -3785,6 +3792,11 @@ extern void ___kmp_thread_free(kmp_info_t *th, void *ptr KMP_SRC_LOC_DECL);
___kmp_thread_free((th), (ptr)KMP_SRC_LOC_CURR)

extern void __kmp_push_num_threads(ident_t *loc, int gtid, int num_threads);
extern void __kmp_push_num_threads_list(ident_t *loc, int gtid,
kmp_uint32 list_length,
int *num_threads_list);
extern void __kmp_set_strict_num_threads(ident_t *loc, int gtid, int sev,
const char *msg);

extern void __kmp_push_proc_bind(ident_t *loc, int gtid,
kmp_proc_bind_t proc_bind);
Expand Down Expand Up @@ -4423,6 +4435,18 @@ KMP_EXPORT kmp_int32 __kmpc_in_parallel(ident_t *loc);
KMP_EXPORT void __kmpc_pop_num_threads(ident_t *loc, kmp_int32 global_tid);
KMP_EXPORT void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
kmp_int32 num_threads);
KMP_EXPORT void __kmpc_push_num_threads_strict(ident_t *loc,
kmp_int32 global_tid,
kmp_int32 num_threads,
int severity,
const char *message);

KMP_EXPORT void __kmpc_push_num_threads_list(ident_t *loc, kmp_int32 global_tid,
kmp_uint32 list_length,
kmp_int32 *num_threads_list);
KMP_EXPORT void __kmpc_push_num_threads_list_strict(
ident_t *loc, kmp_int32 global_tid, kmp_uint32 list_length,
kmp_int32 *num_threads_list, int severity, const char *message);

KMP_EXPORT void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 global_tid,
int proc_bind);
Expand Down
44 changes: 44 additions & 0 deletions openmp/runtime/src/kmp_csupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,50 @@ void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
__kmp_push_num_threads(loc, global_tid, num_threads);
}

void __kmpc_push_num_threads_strict(ident_t *loc, kmp_int32 global_tid,
kmp_int32 num_threads, int severity,
const char *message) {
__kmp_push_num_threads(loc, global_tid, num_threads);
__kmp_set_strict_num_threads(loc, global_tid, severity, message);
}

/*!
@ingroup PARALLEL
@param loc source location information
@param global_tid global thread number
@param list_length number of entries in the num_threads_list array
@param num_threads_list array of numbers of threads requested for this parallel
construct and subsequent nested parallel constructs
Set the number of threads to be used by the next fork spawned by this thread,
and some nested forks as well.
This call is only required if the parallel construct has a `num_threads` clause
that has a list of integers as the argument.
*/
void __kmpc_push_num_threads_list(ident_t *loc, kmp_int32 global_tid,
kmp_uint32 list_length,
kmp_int32 *num_threads_list) {
KA_TRACE(20, ("__kmpc_push_num_threads_list: enter T#%d num_threads_list=",
global_tid));
KA_TRACE(20, ("%d", num_threads_list[0]));
#ifdef KMP_DEBUG
for (kmp_uint32 i = 1; i < list_length; ++i)
KA_TRACE(20, (", %d", num_threads_list[i]));
#endif
KA_TRACE(20, ("/n"));

__kmp_assert_valid_gtid(global_tid);
__kmp_push_num_threads_list(loc, global_tid, list_length, num_threads_list);
}

void __kmpc_push_num_threads_list_strict(ident_t *loc, kmp_int32 global_tid,
kmp_uint32 list_length,
kmp_int32 *num_threads_list,
int severity, const char *message) {
__kmp_push_num_threads_list(loc, global_tid, list_length, num_threads_list);
__kmp_set_strict_num_threads(loc, global_tid, severity, message);
}

void __kmpc_pop_num_threads(ident_t *loc, kmp_int32 global_tid) {
KA_TRACE(20, ("__kmpc_pop_num_threads: enter\n"));
/* the num_threads are automatically popped */
Expand Down
Loading

0 comments on commit d30b082

Please sign in to comment.