Skip to content

Commit d30b082

Browse files
[OpenMP] Add num_threads clause list format and strict modifier support (llvm#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.
1 parent f2d3d82 commit d30b082

File tree

6 files changed

+520
-20
lines changed

6 files changed

+520
-20
lines changed

openmp/runtime/src/dllexports

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,11 @@ kmp_set_disp_num_buffers 890
12681268
__kmpc_atomic_val_8_cas_cpt 2158
12691269
%endif
12701270

1271+
# No longer need to put ordinal numbers
1272+
__kmpc_push_num_threads_list
1273+
__kmpc_push_num_threads_strict
1274+
__kmpc_push_num_threads_list_strict
1275+
12711276
%endif
12721277

12731278
__kmpc_set_thread_limit

openmp/runtime/src/kmp.h

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,15 @@ enum clock_function_type {
532532
enum mic_type { non_mic, mic1, mic2, mic3, dummy };
533533
#endif
534534

535+
// OpenMP 3.1 - Nested num threads array
536+
typedef struct kmp_nested_nthreads_t {
537+
int *nth;
538+
int size;
539+
int used;
540+
} kmp_nested_nthreads_t;
541+
542+
extern kmp_nested_nthreads_t __kmp_nested_nth;
543+
535544
/* -- fast reduction stuff ------------------------------------------------ */
536545

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

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

3545-
// OpenMP 3.1 - Nested num threads array
3546-
typedef struct kmp_nested_nthreads_t {
3547-
int *nth;
3548-
int size;
3549-
int used;
3550-
} kmp_nested_nthreads_t;
3551-
3552-
extern kmp_nested_nthreads_t __kmp_nested_nth;
3553-
35543561
#if KMP_USE_ADAPTIVE_LOCKS
35553562

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

37873794
extern void __kmp_push_num_threads(ident_t *loc, int gtid, int num_threads);
3795+
extern void __kmp_push_num_threads_list(ident_t *loc, int gtid,
3796+
kmp_uint32 list_length,
3797+
int *num_threads_list);
3798+
extern void __kmp_set_strict_num_threads(ident_t *loc, int gtid, int sev,
3799+
const char *msg);
37883800

37893801
extern void __kmp_push_proc_bind(ident_t *loc, int gtid,
37903802
kmp_proc_bind_t proc_bind);
@@ -4423,6 +4435,18 @@ KMP_EXPORT kmp_int32 __kmpc_in_parallel(ident_t *loc);
44234435
KMP_EXPORT void __kmpc_pop_num_threads(ident_t *loc, kmp_int32 global_tid);
44244436
KMP_EXPORT void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
44254437
kmp_int32 num_threads);
4438+
KMP_EXPORT void __kmpc_push_num_threads_strict(ident_t *loc,
4439+
kmp_int32 global_tid,
4440+
kmp_int32 num_threads,
4441+
int severity,
4442+
const char *message);
4443+
4444+
KMP_EXPORT void __kmpc_push_num_threads_list(ident_t *loc, kmp_int32 global_tid,
4445+
kmp_uint32 list_length,
4446+
kmp_int32 *num_threads_list);
4447+
KMP_EXPORT void __kmpc_push_num_threads_list_strict(
4448+
ident_t *loc, kmp_int32 global_tid, kmp_uint32 list_length,
4449+
kmp_int32 *num_threads_list, int severity, const char *message);
44264450

44274451
KMP_EXPORT void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 global_tid,
44284452
int proc_bind);

openmp/runtime/src/kmp_csupport.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,50 @@ void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid,
237237
__kmp_push_num_threads(loc, global_tid, num_threads);
238238
}
239239

240+
void __kmpc_push_num_threads_strict(ident_t *loc, kmp_int32 global_tid,
241+
kmp_int32 num_threads, int severity,
242+
const char *message) {
243+
__kmp_push_num_threads(loc, global_tid, num_threads);
244+
__kmp_set_strict_num_threads(loc, global_tid, severity, message);
245+
}
246+
247+
/*!
248+
@ingroup PARALLEL
249+
@param loc source location information
250+
@param global_tid global thread number
251+
@param list_length number of entries in the num_threads_list array
252+
@param num_threads_list array of numbers of threads requested for this parallel
253+
construct and subsequent nested parallel constructs
254+
255+
Set the number of threads to be used by the next fork spawned by this thread,
256+
and some nested forks as well.
257+
This call is only required if the parallel construct has a `num_threads` clause
258+
that has a list of integers as the argument.
259+
*/
260+
void __kmpc_push_num_threads_list(ident_t *loc, kmp_int32 global_tid,
261+
kmp_uint32 list_length,
262+
kmp_int32 *num_threads_list) {
263+
KA_TRACE(20, ("__kmpc_push_num_threads_list: enter T#%d num_threads_list=",
264+
global_tid));
265+
KA_TRACE(20, ("%d", num_threads_list[0]));
266+
#ifdef KMP_DEBUG
267+
for (kmp_uint32 i = 1; i < list_length; ++i)
268+
KA_TRACE(20, (", %d", num_threads_list[i]));
269+
#endif
270+
KA_TRACE(20, ("/n"));
271+
272+
__kmp_assert_valid_gtid(global_tid);
273+
__kmp_push_num_threads_list(loc, global_tid, list_length, num_threads_list);
274+
}
275+
276+
void __kmpc_push_num_threads_list_strict(ident_t *loc, kmp_int32 global_tid,
277+
kmp_uint32 list_length,
278+
kmp_int32 *num_threads_list,
279+
int severity, const char *message) {
280+
__kmp_push_num_threads_list(loc, global_tid, list_length, num_threads_list);
281+
__kmp_set_strict_num_threads(loc, global_tid, severity, message);
282+
}
283+
240284
void __kmpc_pop_num_threads(ident_t *loc, kmp_int32 global_tid) {
241285
KA_TRACE(20, ("__kmpc_pop_num_threads: enter\n"));
242286
/* the num_threads are automatically popped */

0 commit comments

Comments
 (0)