Skip to content

[OpenMP] Add num_threads clause list format and strict modifier support #85466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not cause issue on Windows anymore?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, you can add exported symbols just by name now. Older symbols keep their ordinal number.

__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 @@ -2963,6 +2972,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 @@ -3204,6 +3219,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 @@ -3540,15 +3556,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 @@ -3783,6 +3790,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 @@ -4421,6 +4433,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