Re: [Patch] Fortran: Add 'device_type' clause to OpenMP's declare target
Thanks. I have now committed it as r11-2858-gd58e7173ef964ddac3ab3ad8cc97de8f9f3b32ee Tobias On 8/20/20 6:10 PM, Andre Vehreschild wrote: Hi Tobias, to me this looks OK now. Regards, Andre On Thu, 20 Aug 2020 11:51:50 +0200 Tobias Burnus wrote: Updated patch – taking Andre's suggestions into account + extending the testcase, which now catches the previous (NO)HOST module issue. OK? Tobias On 8/19/20 2:51 PM, Tobias Burnus wrote: Am 18.08.20 um 19:33 schrieb Andre Vehreschild: +case OMP_DEVICE_TYPE_HOST: + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits); Why also NOHOST here? Copy and paste error. ... + tree clauses = NULL_TREE; Would you mind using "omp_clauses" or the like here? Done now. - Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter - Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter
Re: [Patch] Fortran: Add 'device_type' clause to OpenMP's declare target
Hi Tobias, to me this looks OK now. Regards, Andre On Thu, 20 Aug 2020 11:51:50 +0200 Tobias Burnus wrote: > Updated patch – taking Andre's suggestions into account + > extending the testcase, which now catches the previous (NO)HOST > module issue. > > OK? > > Tobias > > On 8/19/20 2:51 PM, Tobias Burnus wrote: > > Am 18.08.20 um 19:33 schrieb Andre Vehreschild: > >> +case OMP_DEVICE_TYPE_HOST: > >> + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits); > >> Why also NOHOST here? > > Copy and paste error. > ... > >> + tree clauses = NULL_TREE; > >> Would you mind using "omp_clauses" or the like here? > Done now. > - > Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany > Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, > Alexander Walter -- Andre Vehreschild * Email: vehre ad gmx dot de
Re: [Patch] Fortran: Add 'device_type' clause to OpenMP's declare target
Updated patch – taking Andre's suggestions into account + extending the testcase, which now catches the previous (NO)HOST module issue. OK? Tobias On 8/19/20 2:51 PM, Tobias Burnus wrote: Am 18.08.20 um 19:33 schrieb Andre Vehreschild: +case OMP_DEVICE_TYPE_HOST: + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits); Why also NOHOST here? Copy and paste error. ... + tree clauses = NULL_TREE; Would you mind using "omp_clauses" or the like here? Done now. - Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter Fortran: Add 'device_type' clause to OpenMP's declare target gcc/fortran/ChangeLog: * gfortran.h (enum gfc_omp_device_type): New. (symbol_attribute, gfc_omp_clauses, gfc_common_head): Use it. * module.c (enum ab_attribute): Add AB_OMP_DEVICE_TYPE_HOST, AB_OMP_DEVICE_TYPE_NOHOST and AB_OMP_DEVICE_TYPE_ANY. (attr_bits, mio_symbol_attribute): Handle it. (load_commons, write_common_0): Handle omp_device_type flag. * openmp.c (enum omp_mask1): Add OMP_CLAUSE_DEVICE_TYPE (OMP_DECLARE_TARGET_CLAUSES): Likewise. (gfc_match_omp_clauses): Match 'device_type'. (gfc_match_omp_declare_target): Handle it. * trans-common.c (build_common_decl): Write device-type clause. * trans-decl.c (add_attributes_to_decl): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/declare-target-4.f90: New test. * gfortran.dg/gomp/declare-target-5.f90: New test. gcc/fortran/gfortran.h | 10 +++ gcc/fortran/module.c | 33 - gcc/fortran/openmp.c | 50 - gcc/fortran/trans-common.c | 25 ++- gcc/fortran/trans-decl.c | 22 +- .../gfortran.dg/gomp/declare-target-4.f90 | 81 ++ .../gfortran.dg/gomp/declare-target-5.f90 | 63 + 7 files changed, 277 insertions(+), 7 deletions(-) diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 559d3c6b8b8..d0cea838444 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -753,6 +753,13 @@ CInteropKind_t; that the list is initialized. */ extern CInteropKind_t c_interop_kinds_table[]; +enum gfc_omp_device_type +{ + OMP_DEVICE_TYPE_UNSET, + OMP_DEVICE_TYPE_HOST, + OMP_DEVICE_TYPE_NOHOST, + OMP_DEVICE_TYPE_ANY +}; /* Structure and list of supported extension attributes. */ typedef enum @@ -919,6 +926,7 @@ typedef struct /* Mentioned in OMP DECLARE TARGET. */ unsigned omp_declare_target:1; unsigned omp_declare_target_link:1; + ENUM_BITFIELD (gfc_omp_device_type) omp_device_type:2; /* Mentioned in OACC DECLARE. */ unsigned oacc_declare_create:1; @@ -1360,6 +1368,7 @@ typedef struct gfc_omp_clauses struct gfc_expr *num_threads; gfc_omp_namelist *lists[OMP_LIST_NUM]; enum gfc_omp_sched_kind sched_kind; + enum gfc_omp_device_type device_type; struct gfc_expr *chunk_size; enum gfc_omp_default_sharing default_sharing; int collapse, orderedc; @@ -1699,6 +1708,7 @@ typedef struct gfc_common_head char use_assoc, saved, threadprivate; unsigned char omp_declare_target : 1; unsigned char omp_declare_target_link : 1; + ENUM_BITFIELD (gfc_omp_device_type) omp_device_type:2; /* Provide sufficient space to hold "symbol.symbol.eq.1234567890". */ char name[2*GFC_MAX_SYMBOL_LEN + 1 + 14 + 1]; struct gfc_symbol *head; diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 5114d5534b8..714fbd9c299 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -2051,7 +2051,8 @@ enum ab_attribute AB_OMP_REQ_REVERSE_OFFLOAD, AB_OMP_REQ_UNIFIED_ADDRESS, AB_OMP_REQ_UNIFIED_SHARED_MEMORY, AB_OMP_REQ_DYNAMIC_ALLOCATORS, AB_OMP_REQ_MEM_ORDER_SEQ_CST, AB_OMP_REQ_MEM_ORDER_ACQ_REL, - AB_OMP_REQ_MEM_ORDER_RELAXED + AB_OMP_REQ_MEM_ORDER_RELAXED, AB_OMP_DEVICE_TYPE_NOHOST, + AB_OMP_DEVICE_TYPE_HOST, AB_OMP_DEVICE_TYPE_ANY }; static const mstring attr_bits[] = @@ -2132,6 +2133,9 @@ static const mstring attr_bits[] = minit ("OMP_REQ_MEM_ORDER_SEQ_CST", AB_OMP_REQ_MEM_ORDER_SEQ_CST), minit ("OMP_REQ_MEM_ORDER_ACQ_REL", AB_OMP_REQ_MEM_ORDER_ACQ_REL), minit ("OMP_REQ_MEM_ORDER_RELAXED", AB_OMP_REQ_MEM_ORDER_RELAXED), +minit ("OMP_DEVICE_TYPE_HOST", AB_OMP_DEVICE_TYPE_HOST), +minit ("OMP_DEVICE_TYPE_NOHOST", AB_OMP_DEVICE_TYPE_NOHOST), +minit ("OMP_DEVICE_TYPE_ANYHOST", AB_OMP_DEVICE_TYPE_ANY), minit (NULL, -1) }; @@ -2397,6 +2401,22 @@ mio_symbol_attribute (symbol_attribute *attr) == OMP_REQ_ATOMIC_MEM_ORDER_RELAXED) MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_RELAXED, attr_bits); } + switch (attr->omp_device_type) + { + case OMP_DEVICE_TYPE_UNSET: + break; + case OMP_DEVICE_TYPE_HOST: + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_HOST, attr_bits); + break; + case
Re: [Patch] Fortran: Add 'device_type' clause to OpenMP's declare target
Hi Andre, thanks for the comments. Am 18.08.20 um 19:33 schrieb Andre Vehreschild: > + case OMP_DEVICE_TYPE_HOST: > + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits); > Why also NOHOST here? Copy and paste error. Well spotted. Thanks! (I wonder why it didn't show up in the testcase; probably because I generated the module in the same translation unit, I'd guess.) > @@ -426,6 +426,8 @@ build_common_decl (gfc_common_head *com, tree union_type, > bool is_init) /* If there is no backend_decl for the common block, build it. > */ >if (decl == NULL_TREE) > { > + tree clauses = NULL_TREE; > Would you mind using "omp_clauses" or the like here? I thought about this – but due to indentation, I think I used 'clauses'. But looking again at the patch, this must have been either 'c' or for some other patch as "omp_clauses" should work as well. I will later update the patch for the items. Tobias
Re: [Patch] Fortran: Add 'device_type' clause to OpenMP's declare target
Hi Tobias, I am not deep in OMP dev, i.e., not at all, but this does not make sense to me: @@ -2397,6 +2401,22 @@ mio_symbol_attribute (symbol_attribute *attr) == OMP_REQ_ATOMIC_MEM_ORDER_RELAXED) MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_RELAXED, attr_bits); } + switch (attr->omp_device_type) + { + case OMP_DEVICE_TYPE_UNSET: + break; + case OMP_DEVICE_TYPE_HOST: + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits); ^ Why also NOHOST here? If this intentional please comment. + break; + case OMP_DEVICE_TYPE_NOHOST: + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits); + break; diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c index c6383fc2352..1be5e51b67d 100644 --- a/gcc/fortran/trans-common.c +++ b/gcc/fortran/trans-common.c @@ -426,6 +426,8 @@ build_common_decl (gfc_common_head *com, tree union_type, bool is_init) /* If there is no backend_decl for the common block, build it. */ if (decl == NULL_TREE) { + tree clauses = NULL_TREE; Would you mind using "omp_clauses" or the like here? The reminder looks good to my omp-unexperienced eye. Regards, Andre On Fri, 7 Aug 2020 17:03:34 +0200 Tobias Burnus wrote: > This patch adds the device_type(any|nohost|host) > clause for 'omp declare target' to Fortran. > > In OpenMP 5.0, it has no effect on variables but > only on procedures – in TR8 (and later), it also > affects variables. > > This patch adds this clause to either – except that > the middle end does not seem to like 'target link' > with that clause – for normal variables, common > blocks are accepted. (In line with OpenMP 5, the > middle end ignores the clause for variables.) > > OK? > > Tobias > > - > Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany > Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, > Alexander Walter -- Andre Vehreschild * Email: vehre ad gmx dot de
*PING* / Re: [Patch] Fortran: Add 'device_type' clause to OpenMP's declare target
On 8/7/20 5:03 PM, Tobias Burnus wrote: This patch adds the device_type(any|nohost|host) clause for 'omp declare target' to Fortran. In OpenMP 5.0, it has no effect on variables but only on procedures – in TR8 (and later), it also affects variables. This patch adds this clause to either – except that the middle end does not seem to like 'target link' with that clause – for normal variables, common blocks are accepted. (In line with OpenMP 5, the middle end ignores the clause for variables.) OK? Tobias - Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter
[Patch] Fortran: Add 'device_type' clause to OpenMP's declare target
This patch adds the device_type(any|nohost|host) clause for 'omp declare target' to Fortran. In OpenMP 5.0, it has no effect on variables but only on procedures – in TR8 (and later), it also affects variables. This patch adds this clause to either – except that the middle end does not seem to like 'target link' with that clause – for normal variables, common blocks are accepted. (In line with OpenMP 5, the middle end ignores the clause for variables.) OK? Tobias - Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter Fortran: Add 'device_type' clause to OpenMP's declare target gcc/fortran/ChangeLog: * gfortran.h (enum gfc_omp_device_type): New. (symbol_attribute, gfc_omp_clauses, gfc_common_head): Use it. * module.c (enum ab_attribute): Add AB_OMP_DEVICE_TYPE_HOST, AB_OMP_DEVICE_TYPE_NOHOST and AB_OMP_DEVICE_TYPE_ANY. (attr_bits, mio_symbol_attribute): Handle it. (load_commons, write_common_0): Handle omp_device_type flag. * openmp.c (enum omp_mask1): Add OMP_CLAUSE_DEVICE_TYPE (OMP_DECLARE_TARGET_CLAUSES): Likewise. (gfc_match_omp_clauses): Match 'device_type'. (gfc_match_omp_declare_target): Handle it. * trans-common.c (build_common_decl): Write device-type clause. * trans-decl.c (add_attributes_to_decl): Likewise. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/declare-target-4.f90: New test. * gfortran.dg/gomp/declare-target-5.f90: New test. gcc/fortran/gfortran.h | 10 +++ gcc/fortran/module.c | 33 - gcc/fortran/openmp.c | 50 - gcc/fortran/trans-common.c | 25 ++- gcc/fortran/trans-decl.c | 22 +- .../gfortran.dg/gomp/declare-target-4.f90 | 81 ++ .../gfortran.dg/gomp/declare-target-5.f90 | 33 + 7 files changed, 247 insertions(+), 7 deletions(-) diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 48b2ab14fdb..846816039e5 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -753,6 +753,13 @@ CInteropKind_t; that the list is initialized. */ extern CInteropKind_t c_interop_kinds_table[]; +enum gfc_omp_device_type +{ + OMP_DEVICE_TYPE_UNSET, + OMP_DEVICE_TYPE_HOST, + OMP_DEVICE_TYPE_NOHOST, + OMP_DEVICE_TYPE_ANY +}; /* Structure and list of supported extension attributes. */ typedef enum @@ -919,6 +926,7 @@ typedef struct /* Mentioned in OMP DECLARE TARGET. */ unsigned omp_declare_target:1; unsigned omp_declare_target_link:1; + ENUM_BITFIELD (gfc_omp_device_type) omp_device_type:2; /* Mentioned in OACC DECLARE. */ unsigned oacc_declare_create:1; @@ -1359,6 +1367,7 @@ typedef struct gfc_omp_clauses struct gfc_expr *num_threads; gfc_omp_namelist *lists[OMP_LIST_NUM]; enum gfc_omp_sched_kind sched_kind; + enum gfc_omp_device_type device_type; struct gfc_expr *chunk_size; enum gfc_omp_default_sharing default_sharing; int collapse, orderedc; @@ -1698,6 +1707,7 @@ typedef struct gfc_common_head char use_assoc, saved, threadprivate; unsigned char omp_declare_target : 1; unsigned char omp_declare_target_link : 1; + ENUM_BITFIELD (gfc_omp_device_type) omp_device_type:2; /* Provide sufficient space to hold "symbol.symbol.eq.1234567890". */ char name[2*GFC_MAX_SYMBOL_LEN + 1 + 14 + 1]; struct gfc_symbol *head; diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 5114d5534b8..e122b1367bb 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -2051,7 +2051,8 @@ enum ab_attribute AB_OMP_REQ_REVERSE_OFFLOAD, AB_OMP_REQ_UNIFIED_ADDRESS, AB_OMP_REQ_UNIFIED_SHARED_MEMORY, AB_OMP_REQ_DYNAMIC_ALLOCATORS, AB_OMP_REQ_MEM_ORDER_SEQ_CST, AB_OMP_REQ_MEM_ORDER_ACQ_REL, - AB_OMP_REQ_MEM_ORDER_RELAXED + AB_OMP_REQ_MEM_ORDER_RELAXED, AB_OMP_DEVICE_TYPE_NOHOST, + AB_OMP_DEVICE_TYPE_HOST, AB_OMP_DEVICE_TYPE_ANY }; static const mstring attr_bits[] = @@ -2132,6 +2133,9 @@ static const mstring attr_bits[] = minit ("OMP_REQ_MEM_ORDER_SEQ_CST", AB_OMP_REQ_MEM_ORDER_SEQ_CST), minit ("OMP_REQ_MEM_ORDER_ACQ_REL", AB_OMP_REQ_MEM_ORDER_ACQ_REL), minit ("OMP_REQ_MEM_ORDER_RELAXED", AB_OMP_REQ_MEM_ORDER_RELAXED), +minit ("OMP_DEVICE_TYPE_HOST", AB_OMP_DEVICE_TYPE_HOST), +minit ("OMP_DEVICE_TYPE_NOHOST", AB_OMP_DEVICE_TYPE_NOHOST), +minit ("OMP_DEVICE_TYPE_ANYHOST", AB_OMP_DEVICE_TYPE_ANY), minit (NULL, -1) }; @@ -2397,6 +2401,22 @@ mio_symbol_attribute (symbol_attribute *attr) == OMP_REQ_ATOMIC_MEM_ORDER_RELAXED) MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_RELAXED, attr_bits); } + switch (attr->omp_device_type) + { + case OMP_DEVICE_TYPE_UNSET: + break; + case OMP_DEVICE_TYPE_HOST: + MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits); + break; + case OMP_DEVICE_TYPE_NOHOST: +