From: Thomas Schwinge <thomas@codesourcery.com>
To: Tobias Burnus <tobias@codesourcery.com>
Cc: <gcc-patches@gcc.gnu.org>, <fortran@gcc.gnu.org>,
Jakub Jelinek <jakub@redhat.com>
Subject: Re: [patch] OpenMP/Fortran: Implement omp allocators/allocate for ptr/allocatables
Date: Sat, 9 Dec 2023 12:19:10 +0100 [thread overview]
Message-ID: <87fs0bsjwx.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <60940754-edc6-4110-b7ba-5bed2133bbb6@codesourcery.com>
Hi Tobias!
On 2023-11-08T17:58:10+0100, Tobias Burnus <tobias@codesourcery.com> wrote:
> OpenMP/Fortran: Implement omp allocators/allocate for ptr/allocatables
Nice work!
> This commit adds -fopenmp-allocators which enables support for
> 'omp allocators' and 'omp allocate' that are associated with a Fortran
> allocate-stmt. If such a construct is encountered, an error is shown,
> unless the -fopenmp-allocators flag is present.
>
> With -fopenmp -fopenmp-allocators, those constructs get turned into
> GOMP_alloc allocations, while -fopenmp-allocators (also without -fopenmp)
> ensures deallocation and reallocation (via intrinsic assignments) are
> properly directed to GOMP_free/omp_realloc - while normal Fortran
> allocations are processed by free/realloc.
>
> In order to distinguish a 'malloc'ed from a 'GOMP_alloc'ed memory, the
> version field of the Fortran array discriptor is (mis)used: 0 indicates
> the normal Fortran allocation while 1 denotes GOMP_alloc. For scalars,
> there is record keeping in libgomp: GOMP_add_alloc(ptr) will add the
> pointer address to a splay_tree while GOMP_is_alloc(ptr) will return
> true it was previously added but also removes it from the list.
>
> Besides Fortran FE work, BUILT_IN_GOMP_REALLOC is no part of
> omp-builtins.def and libgomp gains the mentioned two new function.
Minor comments:
> --- a/gcc/fortran/trans-openmp.cc
> +++ b/gcc/fortran/trans-openmp.cc
> +/* Add ptr for tracking as being allocated by GOMP_alloc. */
> +
> +tree
> +gfc_omp_call_add_alloc (tree ptr)
> +{
> + static tree fn = NULL_TREE;
> + if (fn == NULL_TREE)
> + {
> + fn = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
> + fn = build_fn_decl ("GOMP_add_alloc", fn);
> +/* FIXME: attributes. */
> + }
> + return build_call_expr_loc (input_location, fn, 1, ptr);
> +}
> +
> +/* Generated function returns true when it was tracked via GOMP_add_alloc and
> + removes it from the tracking. As called just before GOMP_free or omp_realloc
> + the pointer is or might become invalid, thus, it is always removed. */
> +
> +tree
> +gfc_omp_call_is_alloc (tree ptr)
> +{
> + static tree fn = NULL_TREE;
> + if (fn == NULL_TREE)
> + {
> + fn = build_function_type_list (boolean_type_node, ptr_type_node,
> + NULL_TREE);
> + fn = build_fn_decl ("GOMP_is_alloc", fn);
> +/* FIXME: attributes. */
> + }
> + return build_call_expr_loc (input_location, fn, 1, ptr);
> +}
Why not define 'GOMP_add_alloc', 'GOMP_is_alloc' via
'gcc/omp-builtins.def'?
> --- a/gcc/omp-builtins.def
> +++ b/gcc/omp-builtins.def
> @@ -467,6 +467,9 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER,
> DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ALLOC,
> "GOMP_alloc", BT_FN_PTR_SIZE_SIZE_PTRMODE,
> ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LIST)
> +DEF_GOMP_BUILTIN (BUILT_IN_GOMP_REALLOC,
> + "omp_realloc", BT_FN_PTR_PTR_SIZE_PTRMODE_PTRMODE,
> + ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LEAF_LIST)
> DEF_GOMP_BUILTIN (BUILT_IN_GOMP_FREE,
> "GOMP_free", BT_FN_VOID_PTR_PTRMODE, ATTR_NOTHROW_LEAF_LIST)
> DEF_GOMP_BUILTIN (BUILT_IN_GOMP_WARNING, "GOMP_warning",
Should this either be 'BUILT_IN_OMP_REALLOC' ('OMP' instead of 'GOMP'),
or otherwise a 'GOMP_realloc' be added to 'libgomp/allocator.c', like for
'GOMP_alloc', 'GOMP_free'; 'ialias_call'ing the respective 'omp_[...]'
functions? (Verbatim 'omp_realloc' also mentioned in the comment before
'gcc/fortran/trans-openmp.cc:gfc_omp_call_is_alloc'.)
> --- a/libgomp/allocator.c
> +++ b/libgomp/allocator.c
> +/* Add pointer as being alloced by GOMP_alloc. */
> +void
> +GOMP_add_alloc (void *ptr)
> +{
> + [...]
> +}
> +
> +/* Remove pointer, either called by FREE or by REALLOC,
> + either of them can change the allocation status. */
> +bool
> +GOMP_is_alloc (void *ptr)
> +{
> + [...]
> +}
> --- a/libgomp/libgomp.map
> +++ b/libgomp/libgomp.map
> +GOMP_5.1.2 {
> + global:
> + GOMP_add_alloc;
> + GOMP_is_alloc;
> + [...]
> +} GOMP_5.1.1;
'GOMP_add_alloc', 'GOMP_is_alloc' should get prototyped in
'libgomp/libgomp_g.h'.
Grüße
Thomas
-----------------
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:[~2023-12-09 11:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 16:58 Tobias Burnus
2023-12-08 12:04 ` Jakub Jelinek
2023-12-09 11:19 ` Thomas Schwinge [this message]
2023-12-09 15:14 ` Jakub Jelinek
2023-12-11 11:45 ` [Patch] OpenMP: Minor '!$omp allocators' cleanup - and still: " Tobias Burnus
2023-12-11 22:12 ` Thomas Schwinge
2023-12-11 23:45 ` Andrew MacLeod
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=87fs0bsjwx.fsf@euler.schwinge.homeip.net \
--to=thomas@codesourcery.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=tobias@codesourcery.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).