Hi, On 15.11.21 13:05, Jakub Jelinek wrote:
OpenMP 5.1 says that thread_limit clause can also appear on target, and similarly to teams should affect the thread-limit-var ICV. On combined target teams, the clause goes to both.
This patch does this also for Fortran. OK, once the post-bootstap testing finished successfully? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
Fortran: openmp: Add support for thread_limit clause on target gcc/fortran/ChangeLog: * openmp.c (OMP_TARGET_CLAUSES): Add thread_limit. * trans-openmp.c (gfc_split_omp_clauses): Add thread_limit also to teams. libgomp/ChangeLog: * testsuite/libgomp.fortran/thread-limit-1.f90: New test. gcc/fortran/openmp.c | 3 +- gcc/fortran/trans-openmp.c | 2 ++ .../testsuite/libgomp.fortran/thread-limit-1.f90 | 41 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index 2893ab2befb..d120be81467 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -3563,7 +3563,8 @@ cleanup: (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_MAP | OMP_CLAUSE_IF \ | OMP_CLAUSE_DEPEND | OMP_CLAUSE_NOWAIT | OMP_CLAUSE_PRIVATE \ | OMP_CLAUSE_FIRSTPRIVATE | OMP_CLAUSE_DEFAULTMAP \ - | OMP_CLAUSE_IS_DEVICE_PTR | OMP_CLAUSE_IN_REDUCTION) + | OMP_CLAUSE_IS_DEVICE_PTR | OMP_CLAUSE_IN_REDUCTION \ + | OMP_CLAUSE_THREAD_LIMIT) #define OMP_TARGET_DATA_CLAUSES \ (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_MAP | OMP_CLAUSE_IF \ | OMP_CLAUSE_USE_DEVICE_PTR | OMP_CLAUSE_USE_DEVICE_ADDR) diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index b86c7cf9833..5b3c310ba59 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -5870,6 +5870,8 @@ gfc_split_omp_clauses (gfc_code *code, = code->ext.omp_clauses->lists[OMP_LIST_IS_DEVICE_PTR]; clausesa[GFC_OMP_SPLIT_TARGET].device = code->ext.omp_clauses->device; + clausesa[GFC_OMP_SPLIT_TARGET].thread_limit + = code->ext.omp_clauses->thread_limit; for (int i = 0; i < OMP_DEFAULTMAP_CAT_NUM; i++) clausesa[GFC_OMP_SPLIT_TARGET].defaultmap[i] = code->ext.omp_clauses->defaultmap[i]; diff --git a/libgomp/testsuite/libgomp.fortran/thread-limit-1.f90 b/libgomp/testsuite/libgomp.fortran/thread-limit-1.f90 new file mode 100644 index 00000000000..bca69fbb466 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/thread-limit-1.f90 @@ -0,0 +1,41 @@ +! { dg-additional-options "-fdump-tree-original" } + +! { dg-final { scan-tree-dump-times "#pragma omp teams thread_limit\\(9\\)" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp target thread_limit\\(9\\)" 1 "original" } } + +! { dg-final { scan-tree-dump-times "#pragma omp target nowait thread_limit\\(4\\)" 1 "original" } } +! { dg-final { scan-tree-dump-times "#pragma omp parallel num_threads\\(1\\)" 1 "original" } } + +! { dg-final { scan-tree-dump-times "#pragma omp target thread_limit\\(6\\)" 1 "original" } } + + +module m + use omp_lib + implicit none +contains + +subroutine uncalled() + !$omp target teams thread_limit (9) + !$omp end target teams +end + +subroutine foo () + block + !$omp target parallel nowait thread_limit (4) num_threads (1) + if (omp_get_thread_limit () > 4) & + stop 1 + !$omp end target parallel + end block + !$omp taskwait +end +end module + +program main + use m + implicit none + !$omp target thread_limit (6) + if (omp_get_thread_limit () > 6) & + stop 2 + !$omp end target + call foo () +end