Re: [PATCH 3/3] OpenACC 2.6 manual deep copy support (attach/detach)
On Sat, 10 Nov 2018 09:11:20 -0800 Julian Brown wrote: Two nits. > diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c > index 6430e61..ebba7ca 100644 > --- a/gcc/fortran/openmp.c > +++ b/gcc/fortran/openmp.c > @@ -3781,9 +3805,6 @@ check_array_not_assumed (gfc_symbol *sym, locus loc, > const char *name) > static void > resolve_oacc_data_clauses (gfc_symbol *sym, locus loc, const char *name) > { > - if (sym->ts.type == BT_DERIVED && sym->attr.allocatable) > -gfc_error ("ALLOCATABLE object %qs of derived type in %s clause at %L", > -sym->name, name, ); >if ((sym->ts.type == BT_ASSUMED && sym->attr.allocatable) >|| (sym->ts.type == BT_CLASS && CLASS_DATA (sym) > && CLASS_DATA (sym)->attr.allocatable)) > @@ -4153,11 +4174,23 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses > *omp_clauses, > && (list != OMP_LIST_REDUCTION || !openacc)) >for (n = omp_clauses->lists[list]; n; n = n->next) > { > - if (n->sym->mark) > - gfc_error ("Symbol %qs present on multiple clauses at %L", > -n->sym->name, >where); > - else > - n->sym->mark = 1; > + bool array_only_p = true; > + /* Disallow duplicate bare variable references and multiple > + subarrays of the same array here, but allow multiple components of > + the same (e.g. derived-type) variable. For the latter, duplicate > + components are detected elsewhere. */ > + if (openacc && n->expr && n->expr->expr_type == EXPR_VARIABLE) > + for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next) > + if (ref->type != REF_ARRAY) > + array_only_p = false; you could break here. It seems we do not perform this optimization ourself even when we could (or should) prove that the dataflow does not force the loop to run to completion?! Consider: int foo(char *str) { _Bool cond = 0; for (char *chp = str; *chp != 0; chp++) if (*chp == 42) { cond = 1; #ifdef BREAK break; #endif } return 0x0815 + cond; } $ for i in 0 1 2 3 s;do gcc -UBREAK -O$i -c -o $i.o /tmp/1/foo.c -fomit-frame-pointer -m32 -mtune=i386;done;size ?.o textdata bss dec hex filename 109 0 0 109 6d 0.o 97 0 0 97 61 1.o 107 0 0 107 6b 2.o 107 0 0 107 6b 3.o 86 0 0 86 56 s.o $ for i in 0 1 2 3 s;do gcc -DBREAK -O$i -c -o $i.o /tmp/1/foo.c -fomit-frame-pointer -m32 -mtune=i386;done;size ?.o textdata bss dec hex filename 111 0 0 111 6f 0.o 82 0 0 82 52 1.o 82 0 0 82 52 2.o 82 0 0 82 52 3.o 77 0 0 77 4d s.o respectively $ for i in 0 1 2 3 s;do gcc -UBREAK -O$i -c -o $i.o /tmp/1/foo.c -fomit-frame-pointer -m32 -mtune=i386 -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-guess-branch-probability;done;size ?.o textdata bss dec hex filename 61 0 0 61 3d 0.o 38 0 0 38 26 1.o 43 0 0 43 2b 2.o 43 0 0 43 2b 3.o 34 0 0 34 22 s.o $ for i in 0 1 2 3 s;do gcc -DBREAK -O$i -c -o $i.o /tmp/1/foo.c -fomit-frame-pointer -m32 -mtune=i386 -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-guess-branch-probability;done;size ?.o textdata bss dec hex filename 63 0 0 63 3f 0.o 39 0 0 39 27 1.o 39 0 0 39 27 2.o 39 0 0 39 27 3.o 33 0 0 33 21 s.o that's really a pity. > + if (array_only_p) > + { > + if (n->sym->mark) > + gfc_error ("Symbol %qs present on multiple clauses at %L", > +n->sym->name, >where); > + else > + n->sym->mark = 1; > + } > } > diff --git a/gcc/gimplify.c b/gcc/gimplify.c > index 274edc0..aa7723d 100644 > --- a/gcc/gimplify.c > +++
[PATCH 3/3] OpenACC 2.6 manual deep copy support (attach/detach)
This patch implements the bulk of support for OpenACC 2.6 manual deep copy for the C, C++ and Fortran front-ends, the middle end and the libgomp runtime. I've incorporated parts of the patches previously posted by Cesar: https://gcc.gnu.org/ml/gcc-patches/2018-10/msg01941.html https://gcc.gnu.org/ml/gcc-patches/2018-10/msg01942.html https://gcc.gnu.org/ml/gcc-patches/2018-10/msg01943.html https://gcc.gnu.org/ml/gcc-patches/2018-10/msg01946.html The patch also supersedes the patch posted earlier to support OpenACC 2.5 "update" directives with Fortran derived types: https://gcc.gnu.org/ml/gcc-patches/2018-09/msg00153.html Some brief notes: * Struct members mapped with a tuple of map(to/from), optional pset and an always_pointer are rewritten in gimplify_scan_omp_clauses to use a new GOMP_MAP_ATTACH mapping type instead of the final GOMP_MAP_ALWAYS_POINTER. Explicit "attach" clauses also use the GOMP_MAP_ATTACH mapping, and explicit "detach" uses GOMP_MAP_DETACH. This means that the new "attach operation" takes place when, and only when, the GOMP_MAP_ATTACH appears explicitly in the list of clauses (as rewritten by gimplify.c). Similarly for GOMP_MAP_DETACH. * The runtime needs to keep track of potentially multiple "attachment counters" for each mapped struct/derived type. The way I've implemented this is as a simple array of shorts, where each element maps 1-to-1 onto logical "slots" in the mapped struct. The attachment counters are associated with the block of memory containing the structure in the host's address space, hence the array is allocated on-demand in the splay_tree_key_s structure. This does unfortunately grow that structure a little in all cases. Tested alongside the other patches in the series and bootstrapped. OK? Julian ChangeLog gcc/c-family/ * c-pragma.h (pragma_omp_clause): Add PRAGMA_OACC_CLAUSE_ATTACH, PRAGMA_OACC_CLAUSE_DETACH. gcc/c/ * c-parser.c (c_parser_omp_clause_name): Add parsing of attach and detach clauses. (c_parser_omp_variable_list): Allow deref (->) in variable lists. (c_parser_oacc_data_clause): Support attach and detach clauses. (c_parser_oacc_all_clauses): Likewise. (OACC_DATA_CLAUSE_MASK, OACC_ENTER_DATA_CLAUSE_MASK) (OACC_KERNELS_CLAUSE_MASK, OACC_PARALLEL_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_ATTACH. (OACC_EXIT_DATA_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_DETACH. * c-typeck.c (handle_omp_array_sections_1): Reject subarrays for attach and detach. Support deref. (c_oacc_check_attachments): New function. (c_finish_omp_clauses): Check attach/detach arguments for being pointers using above. Support deref. gcc/cp/ * parser.c (cp_parser_omp_clause_name): Support attach and detach clauses. (cp_parser_omp_var_list_no_open): Support deref. (cp_parser_oacc_data_clause): Support attach and detach clauses. (cp_parser_oacc_all_clauses): Likewise. (OACC_DATA_CLAUSE_MASK, OACC_ENTER_DATA_CLAUSE_MASK) (OACC_KERNELS_CLAUSE_MASK, OACC_PARALLEL_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_ATTACH. (OACC_EXIT_DATA_CLAUSE_MASK): Add PRAGMA_OACC_CLAUSE_DETACH. * semantics.c (handle_omp_array_sections_1): Reject subarrays for attach and detach. (cp_oacc_check_attachments): New function. (finish_omp_clauses): Use above function. Allow structure fields and class members to appear in OpenACC data clauses. Support deref. gcc/fortran/ * gfortran.h (gfc_omp_map_op): Add OMP_MAP_ATTACH, OMP_MAP_DETACH. * openmp.c (gfc_match_omp_variable_list): Add allow_derived parameter. Parse derived-type member accesses if true. (omp_mask2): Add OMP_CLAUSE_ATTACH, OMP_CLAUSE_DETACH. (gfc_match_omp_map_clause): Add allow_derived parameter. Pass to gfc_match_omp_variable_list. (gfc_match_omp_clauses): Support attach and detach. Support derived types for appropriate OpenACC directives. (OACC_PARALLEL_CLAUSES, OACC_KERNELS_CLAUSES, OACC_DATA_CLAUSES) (OACC_ENTER_DATA_CLAUSES): Add OMP_CLAUSE_ATTACH. (OACC_EXIT_DATA_CLAUSES): Add OMP_CLAUSE_DETACH. (check_symbol_not_pointer): Don't disallow pointer objects of derived type. (resolve_oacc_data_clauses): Don't disallow allocatable derived types. (resolve_omp_clauses): Perform duplicate checking only for non-derived type component accesses (plain variables and arrays or array sections). Support component refs. * trans-openmp.c (gfc_omp_privatize_by_reference): Support component refs. (gfc_trans_omp_clauses): Support component refs, attach and detach clauses. gcc/ * gimplify.c (gimplify_omp_var_data): Add GOVD_MAP_HAS_ATTACHMENTS.