From: Tobias Burnus <tobias@codesourcery.com>
To: Chung-Lin Tang <cltang@codesourcery.com>,
gcc-patches <gcc-patches@gcc.gnu.org>,
Jakub Jelinek <jakub@redhat.com>,
Tobias Burnus <tobias@codesourcery.com>,
Catherine Moore <clm@codesourcery.com>,
Andrew Stubbs <ams@codesourcery.com>,
Hafiz Abid Qadeer <abid_qadeer@mentor.com>
Subject: Re: [PATCH, OpenMP] Implement uses_allocators clause for target regions
Date: Fri, 6 May 2022 18:40:43 +0200 [thread overview]
Message-ID: <9c0945fa-1054-095e-86ae-a9d8dd1ab625@codesourcery.com> (raw)
In-Reply-To: <46d77e14-080c-db6c-4032-e12899c5d059@codesourcery.com>
Hi Chung-Lin,
thanks for the patch – and some comments from my side.
On 06.05.22 15:20, Chung-Lin Tang wrote:
> For user defined allocator handles, this allows target regions to assign
> memory space and traits to allocators, and automatically calls
> omp_init/destroy_allocator() in the beginning/end of the target region.
Can please also handle the new clause in Fortran's dump-parse-tree.cc?
I did see some split handling in C, but not in Fortran; do you also need
to up update gfc_split_omp_clauses in Fortran's trans-openmp.cc?
Actually, glancing at the testcases, no combined construct (like
"omp target parallel") is used, I think that would be useful because of ↑.
> +/* OpenMP 5.2:
> + uses_allocators ( allocator-list )
That's not completely true: uses_allocators is OpenMP 5.1.
However, 5.1 only supports (for non-predefined allocators):
uses_allocators( allocator(traits) )
while OpenMP 5.2 added modifiers:
uses_allocatrors( traits(...), memspace(...) : allocator )
and deprecated the 5.1 'allocator(traits)'. (Scheduled for removal in OMP 6.0)
The advantage of 5.2 syntax is that a memory space can be defined.
BTW: This makes uses_allocators the first OpenMP 5.2 feature which
will make it into GCC :-)
gcc/fortran/openmp.cc:
> + if (gfc_get_symbol ("omp_allocator_handle_kind", NULL, &sym)
> + || !sym->value
> + || sym->value->expr_type != EXPR_CONSTANT
> + || sym->value->ts.type != BT_INTEGER)
> + {
> + gfc_error ("OpenMP %<omp_allocator_handle_kind%> constant not found by "
> + "%<uses_allocators%> clause at %C");
> + goto error;
> + }
> + allocator_handle_kind = sym;
I think you rather want to use
gfc_find_symbol ("omp_...", NULL, true, &sym)
|| sym == NULL
where true is for parent_flag to search also the parent namespace.
(The function returns 1 if the symbol is ambiguous, 0 otherwise -
including 0 + sym == NULL when the symbol could not be found.)
|| sym->attr.flavor != FL_PARAMETER
|| sym->ts.type != BT_INTEGER
|| sym->attr.dimension
Looks cleaner than to access sym->value. The attr.dimension is just
to makes sure the user did not smuggle an array into this.
(Invalid as omp_... is a reserved namespace but users will still do
this and some are good in finding ICE as hobby.)
* * *
However, I fear that will fail for the following two examples (both untested):
use omp_lib, my_kind = omp_allocator_handle_kind
integer(my_kind) :: my_allocator
as this gives 'my_kind' in the symtree->name (while symtree->n.sym->name is "omp_...").
Hence, by searching the symtree for 'omp_...' the symbol will not be found.
It will likely also fail for the following more realistic example:
module m
use omp_lib
implicit none
private
integer(omp_allocator_handle_kind), public :: my_allocator
type(omp_alloctrait), public, parameter :: my_traits(*) = [...]
end module
subroutine foo
use m
use omp_lib, only: omp_alloctrait
implicit none
! currently, same scope is required - makes sense for C and 'const' but
! not for Fortran's parameters; restriction might be lifted/clarified in
! next OpenMP version:
type(omp_alloctrait), parameter :: traits_array(*) = my_traits
integer :: A(200)
A = 0
!$omp target uses_allocators(my_allocator(traits_array) allocate(my_allocator:A) firstprivate(A)
...
!$omp end target
end
In this case, omp_allocator_handle_kind is not in the namespace of 'foo'
but the code should be still valid. Thus, an alternative would be to hard-code
the value - as done for the depobj. As we have:
integer, parameter :: omp_allocator_handle_kind = c_intptr_t
integer, parameter :: omp_memspace_handle_kind = c_intptr_t
that would be
sym->ts.type == BT_CHARACTER
sym->ts.kind == gfc_index_integer_kind
for the allocator variable and the the memspace kind.
However, I grant that either example is not very typical. The second one is more
natural – such a code will very likely be written in the real world. But not
with uses_allocators but rather with "!$omp requires dynamic_allocators" and
omp_init_allocator().
Thoughts?
* * *
gcc/fortran/openmp.cc
> + if (++i > 2)
> + {
> + gfc_error ("Only two modifiers are allowed on %<uses_allocators%> "
> + "clause at %C");
> + goto error;
> + }
> +
Is this really needed? There is a check for multiple traits and multiple memspace
Thus, 'trait(),memspace(),trait()' is already handled and
'trait(),something' give a break and will lead to an error as in that case
a ':' and not ',something' is expected.
> + if (gfc_match_char ('(') == MATCH_YES)
> + {
> + if (memspace_seen || traits_seen)
> + {
> + gfc_error ("Modifiers cannot be used with legacy "
> + "array syntax at %C");
I wouldn't uses the term 'array synax' to denote
uses_allocators(allocator (alloc_array) )
How about:
error: "Using both modifiers and allocator variable with traits argument"
(And I think 'deprecated' is better than 'legacy', if we really want to use it.)
> + if (traits_sym->ts.type != BT_DERIVED
> + || strcmp (traits_sym->ts.u.derived->name,
> + "omp_alloctrait") != 0
> + || traits_sym->attr.flavor != FL_PARAMETER
> + || traits_sym->as->rank != 1
> + || traits_sym->value == NULL
> + || !gfc_is_constant_expr (traits_sym->value))
I think the gfc_is_constant_expr is unreachable as you already
have checked FL_PARAMETER. Thus, you can remove the last two
lines.
[Regarding the traits_sym->ts.u.derived->name, I am not sure whether that
won't fail with
use omp_lib, trait_t => omp_alloctrait
but I have not checked. It likely does work correctly.]
> + /* Check if identifier is of 'omp_..._mem_space' format. */
> + || (pos = strstr (memspace_sym->name, "omp_")) == NULL
> + || pos != memspace_sym->name
> + || (pos = strstr (memspace_sym->name, "_mem_space")) == NULL
> + || *(pos + strlen ("_mem_space")) != '\0')
I wonder whether that's not more readable written as:
|| !startswith (memspace_sym->name, "omp_")
|| !endswith (memspace_sym->name, "_mem_space")
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
next prev parent reply other threads:[~2022-05-06 16:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-06 13:20 Chung-Lin Tang
2022-05-06 16:40 ` Tobias Burnus [this message]
2022-05-10 11:29 ` [PATCH, OpenMP, v2] " Chung-Lin Tang
2022-05-19 16:00 ` Jakub Jelinek
2022-05-19 17:02 ` Andrew Stubbs
2022-05-19 17:55 ` Jakub Jelinek
2022-05-20 6:59 ` Tobias Burnus
2022-05-19 17:46 ` Jakub Jelinek
2022-05-30 14:43 ` Chung-Lin Tang
2022-05-30 17:23 ` Jakub Jelinek
2022-05-31 10:02 ` Jakub Jelinek
2022-06-06 13:19 ` Chung-Lin Tang
2022-06-06 13:22 ` Jakub Jelinek
2022-06-06 13:38 ` Chung-Lin Tang
2022-06-06 13:42 ` Jakub Jelinek
2022-06-09 6:21 ` [PATCH, OpenMP, v4] " Chung-Lin Tang
2022-06-09 12:22 ` Jakub Jelinek
2022-06-13 13:29 ` Chung-Lin Tang
2022-06-13 14:04 ` Jakub Jelinek
2023-02-09 11:26 ` [og12] '{c-c++-common,gfortran.dg}/gomp/uses_allocators-*' -> 'libgomp.{c-c++-common,fortran}/uses_allocators-*' (was: [PATCH, OpenMP] Implement uses_allocators clause for target regions) Thomas Schwinge
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9c0945fa-1054-095e-86ae-a9d8dd1ab625@codesourcery.com \
--to=tobias@codesourcery.com \
--cc=abid_qadeer@mentor.com \
--cc=ams@codesourcery.com \
--cc=clm@codesourcery.com \
--cc=cltang@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).