[PATCH 1/5] OpenMP, NVPTX: memcpy[23]D bias correction
This patch works around behaviour of the 2D and 3D memcpy operations in the CUDA driver runtime. Particularly in Fortran, the "base pointer" of an array (used for either source or destination of a host/device copy) may lie outside of data that is actually stored on the device. The fix is to make sure that we use the first element of data to be transferred instead, and adjust parameters accordingly. 2023-09-05 Julian Brown libgomp/ * plugin/plugin-nvptx.c (GOMP_OFFLOAD_memcpy2d): Adjust parameters to avoid out-of-bounds array checks in CUDA runtime. (GOMP_OFFLOAD_memcpy3d): Likewise. --- libgomp/plugin/plugin-nvptx.c | 67 +++ 1 file changed, 67 insertions(+) diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index 00d4241ae02b..cefe288a8aab 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -1827,6 +1827,35 @@ GOMP_OFFLOAD_memcpy2d (int dst_ord, int src_ord, size_t dim1_size, data.srcXInBytes = src_offset1_size; data.srcY = src_offset0_len; + if (data.srcXInBytes != 0 || data.srcY != 0) +{ + /* Adjust origin to the actual array data, else the CUDA 2D memory +copy API calls below may fail to validate source/dest pointers +correctly (especially for Fortran where the "virtual origin" of an +array is often outside the stored data). */ + if (src_ord == -1) + data.srcHost = (const void *) ((const char *) data.srcHost + + data.srcY * data.srcPitch + + data.srcXInBytes); + else + data.srcDevice += data.srcY * data.srcPitch + data.srcXInBytes; + data.srcXInBytes = 0; + data.srcY = 0; +} + + if (data.dstXInBytes != 0 || data.dstY != 0) +{ + /* As above. */ + if (dst_ord == -1) + data.dstHost = (void *) ((char *) data.dstHost ++ data.dstY * data.dstPitch ++ data.dstXInBytes); + else + data.dstDevice += data.dstY * data.dstPitch + data.dstXInBytes; + data.dstXInBytes = 0; + data.dstY = 0; +} + CUresult res = CUDA_CALL_NOCHECK (cuMemcpy2D, &data); if (res == CUDA_ERROR_INVALID_VALUE) /* If pitch > CU_DEVICE_ATTRIBUTE_MAX_PITCH or for device-to-device @@ -1895,6 +1924,44 @@ GOMP_OFFLOAD_memcpy3d (int dst_ord, int src_ord, size_t dim2_size, data.srcY = src_offset1_len; data.srcZ = src_offset0_len; + if (data.srcXInBytes != 0 || data.srcY != 0 || data.srcZ != 0) +{ + /* Adjust origin to the actual array data, else the CUDA 3D memory +copy API call below may fail to validate source/dest pointers +correctly (especially for Fortran where the "virtual origin" of an +array is often outside the stored data). */ + if (src_ord == -1) + data.srcHost + = (const void *) ((const char *) data.srcHost + + (data.srcZ * data.srcHeight + data.srcY) + * data.srcPitch + + data.srcXInBytes); + else + data.srcDevice + += (data.srcZ * data.srcHeight + data.srcY) * data.srcPitch ++ data.srcXInBytes; + data.srcXInBytes = 0; + data.srcY = 0; + data.srcZ = 0; +} + + if (data.dstXInBytes != 0 || data.dstY != 0 || data.dstZ != 0) +{ + /* As above. */ + if (dst_ord == -1) + data.dstHost = (void *) ((char *) data.dstHost ++ (data.dstZ * data.dstHeight + data.dstY) + * data.dstPitch ++ data.dstXInBytes); + else + data.dstDevice + += (data.dstZ * data.dstHeight + data.dstY) * data.dstPitch ++ data.dstXInBytes; + data.dstXInBytes = 0; + data.dstY = 0; + data.dstZ = 0; +} + CUDA_CALL (cuMemcpy3D, &data); return true; } -- 2.41.0
[PATCH 0/5] OpenMP: Array-shaping operator and strided/rectangular 'target update' support
This patch series provides support for the OpenMP 5.0+ array-shaping operator and for strided/rectangular updates for 'target update' directives. Each of C, C++ and Fortran is supported (using existing base language syntax for the last). This series applies on top of the "infrastructure" support series: https://gcc.gnu.org/pipermail/gcc-patches/2023-August/627895.html and the lvalue parsing/declare mapper series: https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629363.html The og13 version of this series was posted here: https://gcc.gnu.org/pipermail/gcc-patches/2023-July/623502.html This version of the series contains several follow-up fixes relative to the og13 version, and omits some parts that are only present on the branch for now. Further comments on individual patches. Tested with offloading to NVPTX and bootstrapped. OK? Julian Brown (5): OpenMP, NVPTX: memcpy[23]D bias correction OpenMP: Allow complete replacement of clause during map/to/from expansion OpenMP: Support strided and shaped-array updates for C++ OpenMP: Array shaping operator and strided "target update" for C OpenMP: Noncontiguous "target update" for Fortran gcc/c-family/c-common.h | 12 +- gcc/c-family/c-omp.cc | 277 -- gcc/c-family/c-pretty-print.cc| 5 + gcc/c/c-parser.cc | 330 +++- gcc/c/c-tree.h| 6 +- gcc/c/c-typeck.cc | 281 -- gcc/cp/cp-objcp-common.cc | 1 + gcc/cp/cp-tree.def| 1 + gcc/cp/cp-tree.h | 13 +- gcc/cp/decl.cc| 75 +++ gcc/cp/decl2.cc | 19 +- gcc/cp/error.cc | 5 + gcc/cp/mangle.cc | 1 + gcc/cp/operators.def | 1 + gcc/cp/parser.cc | 303 ++- gcc/cp/parser.h | 7 + gcc/cp/pt.cc | 39 +- gcc/cp/semantics.cc | 289 -- gcc/cp/typeck.cc | 12 +- gcc/fortran/openmp.cc | 5 +- gcc/fortran/trans-openmp.cc | 499 ++ gcc/gimplify.cc | 54 +- gcc/omp-general.cc| 47 ++ gcc/omp-general.h | 4 +- gcc/omp-low.cc| 476 - gcc/testsuite/g++.dg/gomp/array-shaping-1.C | 22 + gcc/testsuite/g++.dg/gomp/array-shaping-2.C | 134 + .../g++.dg/gomp/bad-array-shaping-1.C | 47 ++ .../g++.dg/gomp/bad-array-shaping-2.C | 52 ++ .../g++.dg/gomp/bad-array-shaping-3.C | 53 ++ .../g++.dg/gomp/bad-array-shaping-4.C | 60 +++ .../g++.dg/gomp/bad-array-shaping-5.C | 55 ++ .../g++.dg/gomp/bad-array-shaping-6.C | 59 +++ .../g++.dg/gomp/bad-array-shaping-7.C | 48 ++ .../g++.dg/gomp/bad-array-shaping-8.C | 50 ++ .../gcc.dg/gomp/bad-array-shaping-c-1.c | 26 + .../gcc.dg/gomp/bad-array-shaping-c-2.c | 24 + .../gcc.dg/gomp/bad-array-shaping-c-3.c | 30 ++ .../gcc.dg/gomp/bad-array-shaping-c-4.c | 27 + .../gcc.dg/gomp/bad-array-shaping-c-5.c | 17 + .../gcc.dg/gomp/bad-array-shaping-c-6.c | 26 + .../gcc.dg/gomp/bad-array-shaping-c-7.c | 15 + .../gfortran.dg/gomp/noncontig-updates-1.f90 | 19 + .../gfortran.dg/gomp/noncontig-updates-2.f90 | 16 + .../gfortran.dg/gomp/noncontig-updates-3.f90 | 16 + .../gfortran.dg/gomp/noncontig-updates-4.f90 | 15 + gcc/tree-pretty-print.cc | 17 + gcc/tree.def | 2 +- include/gomp-constants.h | 7 +- libgomp/libgomp.h | 15 + libgomp/plugin/plugin-nvptx.c | 67 +++ libgomp/target.c | 271 +++--- .../testsuite/libgomp.c++/array-shaping-1.C | 469 .../testsuite/libgomp.c++/array-shaping-10.C | 61 +++ .../testsuite/libgomp.c++/array-shaping-11.C | 63 +++ .../testsuite/libgomp.c++/array-shaping-12.C | 65 +++ .../testsuite/libgomp.c++/array-shaping-13.C | 89 .../testsuite/libgomp.c++/array-shaping-2.C | 38 ++ .../testsuite/libgomp.c++/array-shaping-3.C | 38 ++ .../testsuite/libgomp.c++/array-shaping-4.C | 38 ++ .../testsuite/libgomp.c++/array-shaping-5.C | 38 ++ .../testsuite/libgomp.c++/array-shaping-6.C | 54 ++ .../testsuite/libgomp.c++/array-shaping-7.C | 54 ++ .../testsuite/libgomp.c++/array-shaping-8.C | 65 +++ .../testsuite/libgomp.c++/array-shaping-9.C | 95 .../libgomp.c-c++-common/array-shaping-14.c | 34 ++ libgomp/testsuite/libgo
[PATCH 2/5] OpenMP: Allow complete replacement of clause during map/to/from expansion
At present, map/to/from clauses on OpenMP "target" directives may be expanded into several mapping nodes if they describe array sections with pointer or reference bases, or similar. This patch allows the original clause to be replaced during that expansion, mostly by passing the list pointer to the node to various functions rather than the node itself. This is needed by the following patch. There shouldn't be any functional changes introduced by this patch itself. 2023-09-05 Julian Brown gcc/c-family/ * c-common.h (expand_array_base, expand_component_selector, expand_map_clause): Adjust member declarations. * c-omp.cc (omp_expand_access_chain): Pass and return pointer to clause. (c_omp_address_inspector::expand_array_base): Likewise. (c_omp_address_inspector::expand_component_selector): Likewise. (c_omp_address_inspector::expand_map_clause): Likewise. gcc/c/ * c-typeck.cc (handle_omp_array_sections): Pass pointer to clause to process instead of clause. (c_finish_omp_clauses): Update calls to handle_omp_array_sections. Handle cases where initial clause might be replaced. gcc/cp/ * semantics.cc (handle_omp_array_sections): Pass pointer to clause instead of clause. Add PNEXT return parameter for next clause in list to process. (finish_omp_clauses): Update calls to handle_omp_array_sections. Handle cases where initial clause might be replaced. --- gcc/c-family/c-common.h | 12 +++ gcc/c-family/c-omp.cc | 75 + gcc/c/c-typeck.cc | 32 +++--- gcc/cp/semantics.cc | 37 +--- 4 files changed, 88 insertions(+), 68 deletions(-) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index b4e49c7d0cbc..e2b85d394d32 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1383,12 +1383,12 @@ public: bool maybe_zero_length_array_section (tree); - tree expand_array_base (tree, vec &, tree, unsigned *, - c_omp_region_type, bool); - tree expand_component_selector (tree, vec &, tree, - unsigned *); - tree expand_map_clause (tree, tree, vec &, - c_omp_region_type); + tree * expand_array_base (tree *, vec &, tree, unsigned *, + c_omp_region_type, bool); + tree * expand_component_selector (tree *, vec &, tree, + unsigned *); + tree * expand_map_clause (tree *, tree, vec &, + c_omp_region_type); }; enum c_omp_directive_kind { diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc index b73f9682f460..3c6b79107edc 100644 --- a/gcc/c-family/c-omp.cc +++ b/gcc/c-family/c-omp.cc @@ -3331,11 +3331,12 @@ c_omp_address_inspector::maybe_zero_length_array_section (tree clause) expression types here, because e.g. you can't have an array of references. See also gimplify.cc:omp_expand_access_chain. */ -static tree -omp_expand_access_chain (tree c, tree expr, vec &addr_tokens, -unsigned *idx) +static tree * +omp_expand_access_chain (tree *pc, tree expr, +vec &addr_tokens, unsigned *idx) { using namespace omp_addr_tokenizer; + tree c = *pc; location_t loc = OMP_CLAUSE_LOCATION (c); unsigned i = *idx; tree c2 = NULL_TREE; @@ -3373,35 +3374,36 @@ omp_expand_access_chain (tree c, tree expr, vec &addr_tokens, break; default: - return error_mark_node; + return NULL; } if (c2) { OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); OMP_CLAUSE_CHAIN (c) = c2; - c = c2; + pc = &OMP_CLAUSE_CHAIN (c); } *idx = ++i; if (i < addr_tokens.length () && addr_tokens[i]->type == ACCESS_METHOD) -return omp_expand_access_chain (c, expr, addr_tokens, idx); +return omp_expand_access_chain (pc, expr, addr_tokens, idx); - return c; + return pc; } /* Translate "array_base_decl access_method" to OMP mapping clauses. */ -tree -c_omp_address_inspector::expand_array_base (tree c, +tree * +c_omp_address_inspector::expand_array_base (tree *pc, vec &addr_tokens, tree expr, unsigned *idx, c_omp_region_type ort, bool decl_p) { using namespace omp_addr_tokenizer; + tree c = *pc; location_t loc = OMP_CLAUSE_LOCATION (c); int i = *idx; tree decl = addr_tokens[i + 1]->expr; @@ -3426,7 +3428,7 @@ c_omp_address_inspector::expand_array_base (tree c, || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)) { *idx = ++i; - return c; + return pc; } switch (addr_tokens[i + 1]->u.access_kind) @@ -3672,7 +3674,7 @@ c_omp_address_inspector::expand_array_base (tree c, def
[PATCH 4/5] OpenMP: Array shaping operator and strided "target update" for C
Following the similar support for C++, here is the C implementation for the OpenMP 5.0 array-shaping operator, and for strided and rectangular updates for "target update". Much of the implementation is shared with the C++ support added by the previous patch. Some details of parsing necessarily differ for C, but the general ideas are the same. This version of the patch has been rebased and contains a couple of minor fixes relative to versions posted previously. 2023-09-05 Julian Brown gcc/c/ * c-parser.cc (c_parser_braced_init): Disallow array-shaping operator in braced init. (c_parser_conditional_expression): Disallow array-shaping operator in conditional expression. (c_parser_cast_expression): Add array-shaping operator support. (c_parser_postfix_expression): Disallow array-shaping operator in statement expressions. (c_parser_postfix_expression_after_primary): Add OpenMP array section stride support. (c_parser_expr_list): Disallow array-shaping operator in expression lists. (c_array_type_nelts_top, c_array_type_nelts_total): New functions. (c_parser_omp_variable_list): Support array-shaping operator. (c_parser_omp_target_update): Recognize GOMP_MAP_TO_GRID and GOMP_MAP_FROM_GRID map kinds as well as OMP_CLAUSE_TO/OMP_CLAUSE_FROM. * c-tree.h (c_omp_array_shaping_op_p, c_omp_has_array_shape_p): New extern declarations. (create_omp_arrayshape_type): Add prototype. * c-typeck.cc (c_omp_array_shaping_op_p, c_omp_has_array_shape_p): New globals. (build_omp_array_section): Permit integral types, not just integer constants, when creating array types for array sections. (create_omp_arrayshape_type): New function. (handle_omp_array_sections_1): Add DISCONTIGUOUS parameter. Add strided/rectangular array section support. (omp_array_section_low_bound): New function. (handle_omp_array_sections): Add DISCONTIGUOUS parameter. Add strided/rectangular array section support. (c_finish_omp_clauses): Update calls to handle_omp_array_sections. Handle discontiguous updates. gcc/testsuite/ * gcc.dg/gomp/bad-array-shaping-c-1.c: New test. * gcc.dg/gomp/bad-array-shaping-c-2.c: New test. * gcc.dg/gomp/bad-array-shaping-c-3.c: New test. * gcc.dg/gomp/bad-array-shaping-c-4.c: New test. * gcc.dg/gomp/bad-array-shaping-c-5.c: New test. * gcc.dg/gomp/bad-array-shaping-c-6.c: New test. * gcc.dg/gomp/bad-array-shaping-c-7.c: New test. libgomp/ * testsuite/libgomp.c/array-shaping-1.c: New test. * testsuite/libgomp.c/array-shaping-2.c: New test. * testsuite/libgomp.c/array-shaping-3.c: New test. * testsuite/libgomp.c/array-shaping-4.c: New test. * testsuite/libgomp.c/array-shaping-5.c: New test. * testsuite/libgomp.c/array-shaping-6.c: New test. --- gcc/c/c-parser.cc | 300 +- gcc/c/c-tree.h| 4 + gcc/c/c-typeck.cc | 235 -- .../gcc.dg/gomp/bad-array-shaping-c-1.c | 26 ++ .../gcc.dg/gomp/bad-array-shaping-c-2.c | 24 ++ .../gcc.dg/gomp/bad-array-shaping-c-3.c | 30 ++ .../gcc.dg/gomp/bad-array-shaping-c-4.c | 27 ++ .../gcc.dg/gomp/bad-array-shaping-c-5.c | 17 + .../gcc.dg/gomp/bad-array-shaping-c-6.c | 26 ++ .../gcc.dg/gomp/bad-array-shaping-c-7.c | 15 + libgomp/testsuite/libgomp.c/array-shaping-1.c | 236 ++ libgomp/testsuite/libgomp.c/array-shaping-2.c | 39 +++ libgomp/testsuite/libgomp.c/array-shaping-3.c | 42 +++ libgomp/testsuite/libgomp.c/array-shaping-4.c | 36 +++ libgomp/testsuite/libgomp.c/array-shaping-5.c | 38 +++ libgomp/testsuite/libgomp.c/array-shaping-6.c | 45 +++ 16 files changed, 1097 insertions(+), 43 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-1.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-2.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-3.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-4.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-5.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-6.c create mode 100644 gcc/testsuite/gcc.dg/gomp/bad-array-shaping-c-7.c create mode 100644 libgomp/testsuite/libgomp.c/array-shaping-1.c create mode 100644 libgomp/testsuite/libgomp.c/array-shaping-2.c create mode 100644 libgomp/testsuite/libgomp.c/array-shaping-3.c create mode 100644 libgomp/testsuite/libgomp.c/array-shaping-4.c create mode 100644 libgomp/testsuite/libgomp.c/array-shaping-5.c create mode 100644 libgomp/testsuite/libgomp.c/array-shaping-6.c diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index be80c2723ef0..1c28f763c8a0 100644 --- a/gc
[PATCH 5/5] OpenMP: Noncontiguous "target update" for Fortran
This patch implements noncontiguous "target update" for Fortran. The existing middle end/runtime bits relating to C and C++ support are reused, with some small adjustments, e.g.: 1. The node used to map the OMP "array descriptor" (from omp-low.cc onwards) now uses the OMP_CLAUSE_SIZE field as a bias (the difference between the "virtual origin" element with zero indices in each dimension and the first element actually stored in memory). 2. The OMP_CLAUSE_SIZE field of a GOMP_MAP_DIM_STRIDE node may now be used to store a "span", which is the distance in bytes between two adjacent elements in an array (with unit stride) when that is different from the element size, as it can be in Fortran. The implementation goes to some effort to massage Fortran array metadata (array descriptors) into a form that can ultimately be consumed by omp_target_memcpy_rect_worker. The method for doing this is described in comments in the patch body. This version of the patch has been rebased and contains some additional minor fixes relative to the version posted for the og13 branch. 2023-09-05 Julian Brown gcc/fortran/ * openmp.cc (omp_verify_map_motion_clauses): Allow strided array sections with 'omp target update'. * trans-openmp.cc (gfc_trans_omp_arrayshape_type, gfc_omp_calculate_gcd, gfc_desc_to_omp_noncontig_array, gfc_omp_contiguous_update_p): New functions. (gfc_trans_omp_clauses): Handle noncontiguous to/from clauses for OMP "target update" directives. gcc/ * gimplify.cc (gimplify_adjust_omp_clauses): Don't gimplify VIEW_CONVERT_EXPR away in GOMP_MAP_TO_GRID/GOMP_MAP_FROM_GRID clauses. * omp-low.cc (omp_noncontig_descriptor_type): Add SPAN field. (scan_sharing_clauses): Don't store descriptor size in its OMP_CLAUSE_SIZE field. (lower_omp_target): Add missing OMP_CLAUSE_MAP check. Add special-case string handling. Handle span and bias. Use low bound instead of zero as index for trailing full dimensions. gcc/testsuite/ * gfortran.dg/gomp/noncontig-updates-1.f90: New test. * gfortran.dg/gomp/noncontig-updates-2.f90: New test. * gfortran.dg/gomp/noncontig-updates-3.f90: New test. * gfortran.dg/gomp/noncontig-updates-4.f90: New test. libgomp/ * libgomp.h (omp_noncontig_array_desc): Add span field. * target.c (omp_target_memcpy_rect_worker): Add span parameter. Update forward declaration. Handle span != element_size. (gomp_update): Handle bias in descriptor's size slot. Update calls to omp_target_memcpy_rect_worker. (omp_target_memcpy_rect_worker): Add element_size == span checks (to existing stride == 1 check) to guard use of target plugin's 2D/3D memcpy hooks. * testsuite/libgomp.fortran/noncontig-updates-1.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-2.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-3.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-4.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-5.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-6.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-7.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-8.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-9.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-10.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-11.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-12.f90: New test. * testsuite/libgomp.fortran/noncontig-updates-13.f90: New test. --- gcc/fortran/openmp.cc | 5 +- gcc/fortran/trans-openmp.cc | 499 ++ gcc/gimplify.cc | 10 + gcc/omp-low.cc| 53 +- .../gfortran.dg/gomp/noncontig-updates-1.f90 | 19 + .../gfortran.dg/gomp/noncontig-updates-2.f90 | 16 + .../gfortran.dg/gomp/noncontig-updates-3.f90 | 16 + .../gfortran.dg/gomp/noncontig-updates-4.f90 | 15 + libgomp/libgomp.h | 1 + libgomp/target.c | 57 +- .../libgomp.fortran/noncontig-updates-1.f90 | 54 ++ .../libgomp.fortran/noncontig-updates-10.f90 | 29 + .../libgomp.fortran/noncontig-updates-11.f90 | 51 ++ .../libgomp.fortran/noncontig-updates-12.f90 | 59 +++ .../libgomp.fortran/noncontig-updates-13.f90 | 42 ++ .../libgomp.fortran/noncontig-updates-2.f90 | 101 .../libgomp.fortran/noncontig-updates-3.f90 | 47 ++ .../libgomp.fortran/noncontig-updates-4.f90 | 78 +++ .../libgomp.fortran/noncontig-updates-5.f90 | 55 ++ .../libgomp.fortran/noncontig-updates-6.f90 | 34 ++ .../libgomp.fortran/noncontig-updates-7.f90 | 36 ++ .../libgomp.fortran/noncon
[PATCH] OpenMP: Enable 'declare mapper' mappers for 'target update' directives
This patch enables use of 'declare mapper' for 'target update' directives, for each of C, C++ and Fortran. There are some implementation choices here and some "read-between-the-lines" consequences regarding this functionality, as follows: * It is possible to invoke a mapper which contains clauses that don't make sense for a given 'target update' operation. E.g. if a mapper definition specifies a "from:" mapping and the user does "target update to(...)" which triggers that mapper, the resulting map kind (OpenMP 5.2, "Table 5.3: Map-Type Decay of Map Type Combinations") is "alloc" (and for the inverse case "release"). For such cases, an unconditional warning is issued and the map clause in question is dropped from the mapper expansion. (Other choices might be to make this an error, or to do the same thing but silently, or warn only given some special option.) * The array-shaping operator is *permitted* for map clauses within 'declare mapper' definitions. That is because such mappers may be used for 'target update' directives, where the array-shaping operator is permitted. I think that makes sense, depending on the semantic model of how and when substitution is supposed to take place, but I couldn't find such behaviour explicitly mentioned in the spec (as of 5.2). If the mapper is triggered by a different directive ("omp target", "omp target data", etc.), an error will be raised. Support is also added for the "mapper" modifier on to/from clauses for all three base languages. This version of the patch incorporates signature changes to OpenMP variable list parsing functions for C and C++ that are already present on the og13 branch. It applies on top of the "infrastructure" support series: https://gcc.gnu.org/pipermail/gcc-patches/2023-August/627895.html and the lvalue parsing/declare mapper series: https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629363.html and the array-shaping operator and strided/rectangular 'target update' support series: https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629422.html Tested with offloading to NVPTX. OK? 2023-09-06 Julian Brown gcc/c-family/ * c-common.h (c_omp_region_type): Add C_ORT_UPDATE and C_ORT_OMP_UPDATE codes. * c-omp.cc (omp_basic_map_kind_name): New function. (omp_instantiate_mapper): Add 'target update' support. (c_omp_instantiate_mappers): Add 'target update' support. gcc/c/ * c-parser.cc (c_parser_omp_variable_list): Add ORT parameter. Support array-shaping operator in 'declare mapper' definitions. (c_parser_omp_var_list_parens): Add ORT parameter. Pass to c_parser_omp_variable_list. (c_parser_oacc_data_clause): Update calls to c_parser_omp_var_list_parens. (c_parser_omp_clause_map): Pass C_ORT_OMP_DECLARE_MAPPER to c_parser_omp_variable_list in mapper definitions. (c_parser_omp_clause_from_to): Add parsing for mapper modifier. (c_parser_omp_target_update): Instantiate mappers. gcc/cp/ * parser.cc (cp_parser_omp_var_list_no_open): Add ORT parameter. Support array-shaping operator in 'declare mapper' definitions. (cp_parser_omp_var_list): Add ORT parameter. (cp_parser_oacc_data_clause): Update call to cp_parser_omp_var_list. (cp_parser_omp_clause_from_to): Add parsing for mapper modifier. (cp_parser_omp_clause_map): Pass C_ORT_OMP_DECLARE_MAPPER to cp_parser_omp_var_list_no_open in mapper definitions. (cp_parser_omp_target_update): Instantiate mappers. gcc/fortran/ * openmp.cc (gfc_match_motion_var_list): Add parsing for mapper modifier. (gfc_match_omp_clauses): Adjust error handling for changes to gfc_match_motion_var_list. * trans-openmp.cc (gfc_trans_omp_target_update): Instantiate mappers. gcc/testsuite/ * c-c++-common/gomp/declare-mapper-17.c: New test. * c-c++-common/gomp/declare-mapper-19.c: New test. * gfortran.dg/gomp/declare-mapper-24.f90: New test. * gfortran.dg/gomp/declare-mapper-26.f90: Uncomment 'target update' part of test. * gfortran.dg/gomp/declare-mapper-26-p.f90: Likewise. * gfortran.dg/gomp/declare-mapper-27.f90: New test. libgomp/ * testsuite/libgomp.c-c++-common/declare-mapper-18.c: New test. * testsuite/libgomp.fortran/declare-mapper-25.f90: New test. * testsuite/libgomp.fortran/declare-mapper-25-p.f90: New test. * testsuite/libgomp.fortran/declare-mapper-28.f90: New test. --- gcc/c-family/c-common.h | 2 + gcc/c-family/c-omp.cc | 107 ++- gcc/c/c-parser.cc | 165 +++-- gcc/cp/parser.cc | 169 -- gcc/fortran/openmp.cc | 86 +++-- gcc/fortran/trans-openmp.cc