From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1729) id EF16F384D14F; Wed, 29 Jun 2022 14:35:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF16F384D14F Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Kwok Yeung To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] Assumed-size arrays with non-lexical data mappings X-Act-Checkin: gcc X-Git-Author: Julian Brown X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: fd532ca87c3ff63883ffe54f81f6ab561a47cac4 X-Git-Newrev: 9f7117014813a510d529583f03c9da48be1a0ae1 Message-Id: <20220629143541.EF16F384D14F@sourceware.org> Date: Wed, 29 Jun 2022 14:35:41 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jun 2022 14:35:42 -0000 https://gcc.gnu.org/g:9f7117014813a510d529583f03c9da48be1a0ae1 commit 9f7117014813a510d529583f03c9da48be1a0ae1 Author: Julian Brown Date: Thu Jul 4 18:14:41 2019 -0700 Assumed-size arrays with non-lexical data mappings gcc/ * gimplify.cc (gimplify_adjust_omp_clauses_1): Raise error for assumed-size arrays in map clauses for Fortran/OpenMP. * omp-low.cc (lower_omp_target): Set the size of assumed-size Fortran arrays to one to allow use of data already mapped on the offload device. gcc/fortran/ * trans-openmp.cc (gfc_omp_finish_clause): Change clauses mapping assumed-size arrays to use the GOMP_MAP_FORCE_PRESENT map type. Diff: --- gcc/ChangeLog.omp | 8 ++++++++ gcc/fortran/ChangeLog.omp | 5 +++++ gcc/fortran/trans-openmp.cc | 22 +++++++++++++--------- gcc/gimplify.cc | 14 ++++++++++++++ gcc/omp-low.cc | 5 +++++ 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 40d7e5ad8a5..52d41d4a0c1 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,11 @@ +2019-07-10 Cesar Philippidis + Julian Brown + + * gimplify.cc (gimplify_adjust_omp_clauses_1): Raise error for + assumed-size arrays in map clauses for Fortran/OpenMP. + * omp-low.cc (lower_omp_target): Set the size of assumed-size Fortran + arrays to one to allow use of data already mapped on the offload device. + 2019-05-20 Julian Brown * gimplify.cc (gimplify_adjust_omp_clauses_1): Support implied no_alloc diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp index c234fadfe50..176c23274b7 100644 --- a/gcc/fortran/ChangeLog.omp +++ b/gcc/fortran/ChangeLog.omp @@ -1,3 +1,8 @@ +2019-07-10 Julian Brown + + * trans-openmp.cc (gfc_omp_finish_clause): Change clauses mapping + assumed-size arrays to use the GOMP_MAP_FORCE_PRESENT map type. + 2019-05-19 Julian Brown * trans-openmp.cc (gfc_omp_finish_clause): Guard addition of clauses for diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 8f4e27cfad1..e0121af1465 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -1489,10 +1489,18 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc) tree decl = OMP_CLAUSE_DECL (c); /* Assumed-size arrays can't be mapped implicitly, they have to be mapped - explicitly using array sections. An exception is if the array is - mapped explicitly in an enclosing data construct for OpenACC, in which - case we see GOMP_MAP_FORCE_PRESENT here and do not need to raise an - error. */ + explicitly using array sections. For OpenACC this restriction is lifted + if the array has already been mapped: + + - Using a lexically-enclosing data region: in that case we see the + GOMP_MAP_FORCE_PRESENT mapping kind here. + + - Using a non-lexical data mapping ("acc enter data"). + + In the latter case we change the mapping type to GOMP_MAP_FORCE_PRESENT. + This raises an error for OpenMP in the caller + (gimplify.c:gimplify_adjust_omp_clauses_1). OpenACC will raise a runtime + error if the implicitly-referenced assumed-size array is not mapped. */ if (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_PRESENT && TREE_CODE (decl) == PARM_DECL && GFC_ARRAY_TYPE_P (TREE_TYPE (decl)) @@ -1500,11 +1508,7 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc) && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl), GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)) - 1) == NULL) - { - error_at (OMP_CLAUSE_LOCATION (c), - "implicit mapping of assumed size array %qD", decl); - return; - } + OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_PRESENT); if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR) return; diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 477576ff0e7..03769d57200 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -11535,12 +11535,26 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) *list_p = clause; struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp; gimplify_omp_ctxp = ctx->outer_context; + gomp_map_kind kind = (code == OMP_CLAUSE_MAP) ? OMP_CLAUSE_MAP_KIND (clause) + : (gomp_map_kind) GOMP_MAP_LAST; /* Don't call omp_finish_clause on implicitly added OMP_CLAUSE_PRIVATE in simd. Those are only added for the local vars inside of simd body and they don't need to be e.g. default constructible. */ if (code != OMP_CLAUSE_PRIVATE || ctx->region_type != ORT_SIMD) lang_hooks.decls.omp_finish_clause (clause, pre_p, (ctx->region_type & ORT_ACC) != 0); + /* Allow OpenACC to have implicit assumed-size arrays via FORCE_PRESENT, + which should work as long as the array has previously been mapped + explicitly on the target (e.g. by "enter data"). Raise an error for + OpenMP. */ + if (lang_GNU_Fortran () + && code == OMP_CLAUSE_MAP + && (ctx->region_type & ORT_ACC) == 0 + && kind == GOMP_MAP_TOFROM + && OMP_CLAUSE_MAP_KIND (clause) == GOMP_MAP_FORCE_PRESENT) + error_at (OMP_CLAUSE_LOCATION (clause), + "implicit mapping of assumed size array %qD", + OMP_CLAUSE_DECL (clause)); if (gimplify_omp_ctxp) for (; clause != chain; clause = OMP_CLAUSE_CHAIN (clause)) if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index 5575ae47ef7..1143f5ac2e3 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -13657,6 +13657,11 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) s = OMP_CLAUSE_SIZE (c); if (s == NULL_TREE) s = TYPE_SIZE_UNIT (TREE_TYPE (ovar)); + /* Fortran assumed-size arrays have zero size because the type is + incomplete. Set the size to one to allow the runtime to remap + any existing data that is already present on the accelerator. */ + if (s == NULL_TREE && is_gimple_omp_oacc (ctx->stmt)) + s = integer_one_node; s = fold_convert (size_type_node, s); purpose = size_int (map_idx++); CONSTRUCTOR_APPEND_ELT (vsize, purpose, s);