From fa65fc45972d27f2fd79a44eaba1978348177ee9 Mon Sep 17 00:00:00 2001 From: Andrew Stubbs Date: Thu, 10 Mar 2022 21:38:54 +0000 Subject: [PATCH] openmp: allow requires unified_shared_memory This is the front-end portion of the Unified Shared Memory implementation. It checks that -foffload-memory isn't set to an incompatible mode. Backport of the patch posted at https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591351.html gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_requires): Check compatibility of -foffload-memory option with requires directive. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_requires): Check compatibility of -foffload-memory option with requires directive. gcc/fortran/ChangeLog: * openmp.cc (gfc_match_omp_requires): Check compatibility of -foffload-memory option with requires directive. gcc/testsuite/ChangeLog: * c-c++-common/gomp/usm-1.c: New test. * gfortran.dg/gomp/usm-1.f90: New test. --- gcc/c/ChangeLog.omp | 8 ++++++++ gcc/c/c-parser.cc | 9 +++++++++ gcc/cp/ChangeLog.omp | 8 ++++++++ gcc/cp/parser.cc | 9 +++++++++ gcc/fortran/ChangeLog.omp | 8 ++++++++ gcc/fortran/openmp.cc | 6 ++++++ gcc/testsuite/ChangeLog.omp | 8 ++++++++ gcc/testsuite/c-c++-common/gomp/usm-1.c | 4 ++++ gcc/testsuite/gfortran.dg/gomp/usm-1.f90 | 6 ++++++ 9 files changed, 66 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/gomp/usm-1.c create mode 100644 gcc/testsuite/gfortran.dg/gomp/usm-1.f90 diff --git a/gcc/c/ChangeLog.omp b/gcc/c/ChangeLog.omp index 11d0bbe78181..a918af2a22f9 100644 --- a/gcc/c/ChangeLog.omp +++ b/gcc/c/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-03-10 Andrew Stubbs + + Backport of the patch posted at + https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591351.html + + * c-parser.cc (c_parser_omp_requires): Check compatibility of + -foffload-memory option with requires directive. + 2022-02-24 Chung-Lin Tang * c-typeck.cc (handle_omp_array_sections): Add handling for diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 60734268f7ee..cd04c6902cbe 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -22627,7 +22627,16 @@ c_parser_omp_requires (c_parser *parser) if (!strcmp (p, "unified_address")) this_req = OMP_REQUIRES_UNIFIED_ADDRESS; else if (!strcmp (p, "unified_shared_memory")) + { this_req = OMP_REQUIRES_UNIFIED_SHARED_MEMORY; + + if (flag_offload_memory != OFFLOAD_MEMORY_UNIFIED + && flag_offload_memory != OFFLOAD_MEMORY_NONE) + error_at (cloc, + "unified_shared_memory is incompatible with the " + "selected -foffload-memory option"); + flag_offload_memory = OFFLOAD_MEMORY_UNIFIED; + } else if (!strcmp (p, "dynamic_allocators")) this_req = OMP_REQUIRES_DYNAMIC_ALLOCATORS; else if (!strcmp (p, "reverse_offload")) diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp index b0f96782d48e..0e90645e0945 100644 --- a/gcc/cp/ChangeLog.omp +++ b/gcc/cp/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-03-10 Andrew Stubbs + + Backport of the patch posted at + https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591351.html + + * parser.cc (cp_parser_omp_requires): Check compatibility of + -foffload-memory option with requires directive. + 2022-02-24 Chung-Lin Tang * semantics.cc (handle_omp_array_sections): Add handling for diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 7377849105d7..8b76ea740b83 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -46921,7 +46921,16 @@ cp_parser_omp_requires (cp_parser *parser, cp_token *pragma_tok) if (!strcmp (p, "unified_address")) this_req = OMP_REQUIRES_UNIFIED_ADDRESS; else if (!strcmp (p, "unified_shared_memory")) + { this_req = OMP_REQUIRES_UNIFIED_SHARED_MEMORY; + + if (flag_offload_memory != OFFLOAD_MEMORY_UNIFIED + && flag_offload_memory != OFFLOAD_MEMORY_NONE) + error_at (cloc, + "unified_shared_memory is incompatible with the " + "selected -foffload-memory option"); + flag_offload_memory = OFFLOAD_MEMORY_UNIFIED; + } else if (!strcmp (p, "dynamic_allocators")) this_req = OMP_REQUIRES_DYNAMIC_ALLOCATORS; else if (!strcmp (p, "reverse_offload")) diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp index 9e2b67850dff..d172be951234 100644 --- a/gcc/fortran/ChangeLog.omp +++ b/gcc/fortran/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-03-10 Andrew Stubbs + + Backport of the patch posted at + https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591351.html + + * openmp.cc (gfc_match_omp_requires): Check compatibility of + -foffload-memory option with requires directive. + 2022-03-09 Abid Qadeer Backport of a patch posted at diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 42423585395f..0067415e4890 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -5564,6 +5564,12 @@ gfc_match_omp_requires (void) requires_clause = OMP_REQ_UNIFIED_SHARED_MEMORY; if (requires_clauses & OMP_REQ_UNIFIED_SHARED_MEMORY) goto duplicate_clause; + + if (flag_offload_memory != OFFLOAD_MEMORY_UNIFIED + && flag_offload_memory != OFFLOAD_MEMORY_NONE) + gfc_error_now ("unified_shared_memory at %C is incompatible with " + "the selected -foffload-memory option"); + flag_offload_memory = OFFLOAD_MEMORY_UNIFIED; } else if (gfc_match (clauses[3]) == MATCH_YES) { diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index 8367e4995f3d..552124bda135 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-03-10 Andrew Stubbs + + Backport of the patch posted at + https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591351.html + + * c-c++-common/gomp/usm-1.c: New test. + * gfortran.dg/gomp/usm-1.f90: New test. + 2022-03-09 Abid Qadeer Backport of a patch posted at diff --git a/gcc/testsuite/c-c++-common/gomp/usm-1.c b/gcc/testsuite/c-c++-common/gomp/usm-1.c new file mode 100644 index 000000000000..619c21a83f48 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/usm-1.c @@ -0,0 +1,4 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-foffload-memory=pinned" } */ + +#pragma omp requires unified_shared_memory /* { dg-error "unified_shared_memory is incompatible with the selected -foffload-memory option" } */ diff --git a/gcc/testsuite/gfortran.dg/gomp/usm-1.f90 b/gcc/testsuite/gfortran.dg/gomp/usm-1.f90 new file mode 100644 index 000000000000..340f6bb50a57 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/usm-1.f90 @@ -0,0 +1,6 @@ +! { dg-do compile } +! { dg-additional-options "-foffload-memory=pinned" } + +!$omp requires unified_shared_memory ! { dg-error "unified_shared_memory at .* is incompatible with the selected -foffload-memory option" } + +end -- 2.47.2