Re: [PATCH, OpenACC] Fortran deviceptr
On 2019/10/19 9:04 PM, Bernhard Reutner-Fischer wrote: On 18 October 2019 17:08:54 CEST, Chung-Lin Tang wrote: Also, I've added a new libgomp.oacc-fortran/deviceptr-2.f90 testcase that actually copies out and verifies the deviceptr computation. In testcases please do not 'call abort' which is nonstandard but use 'stop N' which is standard, ideally with different stop integers so one can see easily which test failed. We went through all of the testsuite a while ago to remove the nonstandard abort, FYI. TIA, Hi Bernhard, I've adjusted the testcases as advised, updated patch attached. That said, there seems many more such cases in libgomp/testsuite/libgomp.oacc-fortran, to be updated later. Thanks, Chung-Lin Is this okay for trunk now? Thanks, Chung-Lin 2019-10-18 Cesar Philippidis Chung-Lin Tang gcc/fortran/ * trans-openmp.c (gfc_omp_finish_clause): Don't create pointer data mappings for deviceptr clauses. (gfc_trans_omp_clauses): Likewise. gcc/ * gimplify.c (enum gimplify_omp_var_data): Add GOVD_DEVICETPR. (omp_notice_variable): Add GOVD_DEVICEPTR attribute when appropriate. (gimplify_scan_omp_clauses): Likewise. (gimplify_adjust_omp_clauses_1): Set GOMP_MAP_FORCE_DEVICEPTR for implicit deviceptr mappings. gcc/testsuite/ * c-c++-common/goacc/deviceptr-4.c: Update expected data mapping. 2019-10-18 Chung-Lin Tang James Norris libgomp/ * oacc-parallel.c (handle_ftn_pointers): Delete function. (GOACC_parallel_keyed): Remove call to handle_ftn_pointers. * testsuite/libgomp.oacc-fortran/deviceptr-1.f90: New test. * testsuite/libgomp.oacc-fortran/deviceptr-2.f90: New test. Index: gcc/fortran/trans-openmp.c === --- gcc/fortran/trans-openmp.c (revision 277237) +++ gcc/fortran/trans-openmp.c (working copy) @@ -1099,7 +1099,8 @@ gfc_omp_clause_dtor (tree clause, tree decl) void gfc_omp_finish_clause (tree c, gimple_seq *pre_p) { - if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP + || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR) return; tree decl = OMP_CLAUSE_DECL (c); @@ -2173,6 +2174,12 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL) { if (POINTER_TYPE_P (TREE_TYPE (decl)) + && n->u.map_op == OMP_MAP_FORCE_DEVICEPTR) + { + OMP_CLAUSE_DECL (node) = decl; + goto finalize_map_clause; + } + else if (POINTER_TYPE_P (TREE_TYPE (decl)) && (gfc_omp_privatize_by_reference (decl) || GFC_DECL_GET_SCALAR_POINTER (decl) || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl) @@ -2346,6 +2353,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp OMP_CLAUSE_SIZE (node3) = fold_build2 (MINUS_EXPR, sizetype, ptr, ptr2); } + finalize_map_clause: switch (n->u.map_op) { case OMP_MAP_ALLOC: Index: gcc/gimplify.c === --- gcc/gimplify.c (revision 277237) +++ gcc/gimplify.c (working copy) @@ -123,6 +123,9 @@ enum gimplify_omp_var_data /* Flag for GOVD_REDUCTION: inscan seen in {in,ex}clusive clause. */ GOVD_REDUCTION_INSCAN = 0x200, + /* Flag for OpenACC deviceptrs. */ + GOVD_DEVICEPTR = 0x400, + GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LINEAR | GOVD_LOCAL) @@ -7426,6 +7429,7 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, error ("variable %qE declared in enclosing " "% region", DECL_NAME (decl)); nflags |= GOVD_MAP; + nflags |= (n2->value & GOVD_DEVICEPTR); if (octx->region_type == ORT_ACC_DATA && (n2->value & GOVD_MAP_0LEN_ARRAY)) nflags |= GOVD_MAP_0LEN_ARRAY; @@ -8943,6 +8947,8 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_se if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_TO || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_TOFROM) flags |= GOVD_MAP_ALWAYS_TO; + else if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR) + flags |= GOVD_DEVICEPTR; goto do_add; case OMP_CLAUSE_DEPEND: @@ -9727,7 +9733,8 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, | GOVD_MAP_FORCE | GOVD_MAP_FORCE_PRESENT
Re: [PATCH, OpenACC] Fortran deviceptr
On 19 October 2019 15:04:39 CEST, Bernhard Reutner-Fischer wrote: >On 18 October 2019 17:08:54 CEST, Chung-Lin Tang > wrote: > >>Also, I've added a new libgomp.oacc-fortran/deviceptr-2.f90 testcase >>that >>actually copies out and verifies the deviceptr computation. > >In testcases please do not 'call abort' which is nonstandard but use >'stop N' which is standard, ideally with different stop integers so one >can see easily which test failed. > >We went through all of the testsuite a while ago to remove the >nonstandard abort, FYI. Like (modulo typos, untested): $ cat abort_to_stop.awk ; echo EOF # awk -f ./abort_to_stop.awk < foo.f90 > x && mv x foo.f90 BEGIN { IGNORECASE = 1; i = 1 } { while (sub(/call\s\s*abort/, "stop " i)) {let i++;}; print $0; } EOF
Re: [PATCH, OpenACC] Fortran deviceptr
On 18 October 2019 17:08:54 CEST, Chung-Lin Tang wrote: >Also, I've added a new libgomp.oacc-fortran/deviceptr-2.f90 testcase >that >actually copies out and verifies the deviceptr computation. In testcases please do not 'call abort' which is nonstandard but use 'stop N' which is standard, ideally with different stop integers so one can see easily which test failed. We went through all of the testsuite a while ago to remove the nonstandard abort, FYI. TIA, >Is this okay for trunk now? > >Thanks, >Chung-Lin > >2019-10-18 Cesar Philippidis > Chung-Lin Tang > > gcc/fortran/ > * trans-openmp.c (gfc_omp_finish_clause): Don't create pointer data > mappings for deviceptr clauses. > (gfc_trans_omp_clauses): Likewise. > > gcc/ > * gimplify.c (enum gimplify_omp_var_data): Add GOVD_DEVICETPR. > (omp_notice_variable): Add GOVD_DEVICEPTR attribute when appropriate. > (gimplify_scan_omp_clauses): Likewise. > (gimplify_adjust_omp_clauses_1): Set GOMP_MAP_FORCE_DEVICEPTR for > implicit deviceptr mappings. > gcc/testsuite/ > * c-c++-common/goacc/deviceptr-4.c: Update expected data mapping. > >2019-10-18 Chung-Lin Tang > James Norris > > libgomp/ > * oacc-parallel.c (handle_ftn_pointers): Delete function. > (GOACC_parallel_keyed): Remove call to handle_ftn_pointers. > * testsuite/libgomp.oacc-fortran/deviceptr-1.f90: New test. > * testsuite/libgomp.oacc-fortran/deviceptr-2.f90: New test.
[PATCH, OpenACC] Fortran deviceptr
Hi Thomas, this is the updated Fortran deviceptr patche, originated from Cesar, and one of the tests was from James Norris: https://gcc.gnu.org/ml/gcc-patches/2018-05/msg00286.html https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00532.html There were a few style cleanups, but the goal of modification is the same: to use only one clause to represent Fortran deviceptr, and to preserve it during gimplification. Because of this modification, and as we discussed earlier, the handle_ftn_pointers() code in libgomp/oacc-parallel.c appeared to be no longer needed. I have remove them in this patch, and tested libgomp without regressions. Also, I've added a new libgomp.oacc-fortran/deviceptr-2.f90 testcase that actually copies out and verifies the deviceptr computation. Is this okay for trunk now? Thanks, Chung-Lin 2019-10-18 Cesar Philippidis Chung-Lin Tang gcc/fortran/ * trans-openmp.c (gfc_omp_finish_clause): Don't create pointer data mappings for deviceptr clauses. (gfc_trans_omp_clauses): Likewise. gcc/ * gimplify.c (enum gimplify_omp_var_data): Add GOVD_DEVICETPR. (omp_notice_variable): Add GOVD_DEVICEPTR attribute when appropriate. (gimplify_scan_omp_clauses): Likewise. (gimplify_adjust_omp_clauses_1): Set GOMP_MAP_FORCE_DEVICEPTR for implicit deviceptr mappings. gcc/testsuite/ * c-c++-common/goacc/deviceptr-4.c: Update expected data mapping. 2019-10-18 Chung-Lin Tang James Norris libgomp/ * oacc-parallel.c (handle_ftn_pointers): Delete function. (GOACC_parallel_keyed): Remove call to handle_ftn_pointers. * testsuite/libgomp.oacc-fortran/deviceptr-1.f90: New test. * testsuite/libgomp.oacc-fortran/deviceptr-2.f90: New test. Index: gcc/fortran/trans-openmp.c === --- gcc/fortran/trans-openmp.c (revision 277155) +++ gcc/fortran/trans-openmp.c (working copy) @@ -1099,7 +1099,8 @@ gfc_omp_clause_dtor (tree clause, tree decl) void gfc_omp_finish_clause (tree c, gimple_seq *pre_p) { - if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP) + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP + || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR) return; tree decl = OMP_CLAUSE_DECL (c); @@ -2173,6 +2174,12 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp if (n->expr == NULL || n->expr->ref->u.ar.type == AR_FULL) { if (POINTER_TYPE_P (TREE_TYPE (decl)) + && n->u.map_op == OMP_MAP_FORCE_DEVICEPTR) + { + OMP_CLAUSE_DECL (node) = decl; + goto finalize_map_clause; + } + else if (POINTER_TYPE_P (TREE_TYPE (decl)) && (gfc_omp_privatize_by_reference (decl) || GFC_DECL_GET_SCALAR_POINTER (decl) || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl) @@ -2346,6 +2353,7 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp OMP_CLAUSE_SIZE (node3) = fold_build2 (MINUS_EXPR, sizetype, ptr, ptr2); } + finalize_map_clause: switch (n->u.map_op) { case OMP_MAP_ALLOC: Index: gcc/gimplify.c === --- gcc/gimplify.c (revision 277155) +++ gcc/gimplify.c (working copy) @@ -123,6 +123,9 @@ enum gimplify_omp_var_data /* Flag for GOVD_REDUCTION: inscan seen in {in,ex}clusive clause. */ GOVD_REDUCTION_INSCAN = 0x200, + /* Flag for OpenACC deviceptrs. */ + GOVD_DEVICEPTR = 0x400, + GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LINEAR | GOVD_LOCAL) @@ -7426,6 +7429,7 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, error ("variable %qE declared in enclosing " "% region", DECL_NAME (decl)); nflags |= GOVD_MAP; + nflags |= (n2->value & GOVD_DEVICEPTR); if (octx->region_type == ORT_ACC_DATA && (n2->value & GOVD_MAP_0LEN_ARRAY)) nflags |= GOVD_MAP_0LEN_ARRAY; @@ -8943,6 +8947,8 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_se if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_TO || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_TOFROM) flags |= GOVD_MAP_ALWAYS_TO; + else if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR) + flags |= GOVD_DEVICEPTR; goto do_add; case OMP_CLAUSE_DEPEND: @@ -9727,7 +9733,8 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, | GOVD_MAP_FORCE | G