From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 3808B3858CD1; Sat, 9 Dec 2023 11:19:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3808B3858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3808B3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=68.232.141.98 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702120760; cv=none; b=SQv9dVLHgqTFSBJxMT8ELDBxJW+fzzsBr/vBxt4zT3TJbEOR1FRQYH56yjzD+NlbMWkULqC6RLS2m6HJ1b+EOeboKxTi/SeQwAYzwCVutY+j2PAWZooiI16ZS6I1+jQ6LleBZ8VHHfbNgrPY3MDXMlZOqbGwnQb+ZkPi6I0RvjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702120760; c=relaxed/simple; bh=jysCHY/yDvKU5aNp2SR9Cnpezv4MT1IQ5oTtG8D/jok=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NZzV0NM8I7oi3AS+DzDYWbGR1dRb1ZCTqlfo1vdEzImuDSpAiCap8vHexYomciCebHWT8J/wRVdeaoGWRQb6v5E1MT4wJtm8qpGtv+n2FEP4K8KWkstkaoCPUd8BDbXK7BzQLj/rceMGET4MFuL+V595Sr3O/Is6ZfVuwdEt4zA= ARC-Authentication-Results: i=1; server2.sourceware.org X-CSE-ConnectionGUID: RWr7xUHsTEO2hbh8N4p7vA== X-CSE-MsgGUID: NxGvtVRLSOObLFDzKPB+cg== X-IronPort-AV: E=Sophos;i="6.04,263,1695715200"; d="scan'208";a="27820882" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 09 Dec 2023 03:19:16 -0800 IronPort-SDR: GMDZREDM3JNk28U95b5JmcbAFQoS4LDIbQFCv3pyyXz99ovYXsxO4qtDU1MLcjyVBmGuDtp11s j/gvfKeMwNZ8nDtkvzGC+4RSe1q5CIvOw+cIj1cZhsLpAur2lIAkvJyoRYoYA0CU2ShC6/8GIQ kranXh3hAOv4d4Xc2CIc+XoaXYDq3N0Ml65EnF9y1H6W05VddlOGUtF5VLq7m7cOua32TnXvI4 SBG4amiSQ2hYeW0uT5nCEZ4+9Iz9Vn+ZroDTX0J18lQn1FsM57hOEFopAo1OxLQn5Qq792kg7L 1WU= From: Thomas Schwinge To: Tobias Burnus CC: , , Jakub Jelinek Subject: Re: [patch] OpenMP/Fortran: Implement omp allocators/allocate for ptr/allocatables In-Reply-To: <60940754-edc6-4110-b7ba-5bed2133bbb6@codesourcery.com> References: <60940754-edc6-4110-b7ba-5bed2133bbb6@codesourcery.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Sat, 9 Dec 2023 12:19:10 +0100 Message-ID: <87fs0bsjwx.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Tobias! On 2023-11-08T17:58:10+0100, Tobias Burnus 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 =3D NULL_TREE; > + if (fn =3D=3D NULL_TREE) > + { > + fn =3D build_function_type_list (void_type_node, ptr_type_node, NU= LL_TREE); > + fn =3D 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_allo= c 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 =3D NULL_TREE; > + if (fn =3D=3D NULL_TREE) > + { > + fn =3D build_function_type_list (boolean_type_node, ptr_type_node, > + NULL_TREE); > + fn =3D 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_REDUCT= ION_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_LI= ST) > 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=C3=BC=C3=9Fe Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955