From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id CAFF53858D39 for ; Fri, 4 Mar 2022 15:09:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CAFF53858D39 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-482-b-Y2SFxCM7OI6PiuQ5e1RA-1; Fri, 04 Mar 2022 10:09:47 -0500 X-MC-Unique: b-Y2SFxCM7OI6PiuQ5e1RA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8915801AFE; Fri, 4 Mar 2022 15:09:45 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 718CB303C2; Fri, 4 Mar 2022 15:09:45 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 224F9gCi896999 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 4 Mar 2022 16:09:42 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 224F9fV5896998; Fri, 4 Mar 2022 16:09:41 +0100 Date: Fri, 4 Mar 2022 16:09:41 +0100 From: Jakub Jelinek To: Marcel Vollweiler Cc: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: Re: [PATCH] OpenMP, libgomp: Add new runtime routine omp_get_mapped_ptr. Message-ID: Reply-To: Jakub Jelinek References: <43ad60ea-875a-5f6f-106b-206ecd4807ba@codesourcery.com> MIME-Version: 1.0 In-Reply-To: <43ad60ea-875a-5f6f-106b-206ecd4807ba@codesourcery.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2022 15:09:52 -0000 On Fri, Mar 04, 2022 at 03:47:31PM +0100, Marcel Vollweiler wrote: > libgomp/ChangeLog: > > * libgomp.map: Added omp_get_mapped_ptr. > * libgomp.texi: Tagged omp_get_mapped_ptr as supported. > * omp.h.in: Added omp_get_mapped_ptr. > * omp_lib.f90.in: Added interface for omp_get_mapped_ptr. > * omp_lib.h.in: Likewise. > * target.c (omp_get_mapped_ptr): Added implementation of > omp_get_mapped_ptr. > * testsuite/libgomp.c-c++-common/get-mapped-ptr-1.c: New test. > * testsuite/libgomp.c-c++-common/get-mapped-ptr-2.c: New test. > * testsuite/libgomp.c-c++-common/get-mapped-ptr-3.c: New test. > * testsuite/libgomp.c-c++-common/get-mapped-ptr-4.c: New test. > * testsuite/libgomp.fortran/get-mapped-ptr-1.f90: New test. > * testsuite/libgomp.fortran/get-mapped-ptr-2.f90: New test. > * testsuite/libgomp.fortran/get-mapped-ptr-3.f90: New test. > * testsuite/libgomp.fortran/get-mapped-ptr-4.f90: New test. > > diff --git a/libgomp/libgomp.map b/libgomp/libgomp.map > index 2ac5809..00a4858 100644 > --- a/libgomp/libgomp.map > +++ b/libgomp/libgomp.map > @@ -224,6 +224,7 @@ OMP_5.1 { > omp_set_teams_thread_limit_8_; > omp_get_teams_thread_limit; > omp_get_teams_thread_limit_; > + omp_get_mapped_ptr; > } OMP_5.0.2; I think it is too late for this to be targetted for GCC 12, and for GCC 13 it will need to go into OMP_5.1.1 symver. > GOMP_1.0 { > diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi > index 161a423..c163b56 100644 > --- a/libgomp/libgomp.texi > +++ b/libgomp/libgomp.texi > @@ -314,7 +314,7 @@ The OpenMP 4.5 specification is fully supported. > @item @code{omp_target_is_accessible} runtime routine @tab N @tab > @item @code{omp_target_memcpy_async} and @code{omp_target_memcpy_rect_async} > runtime routines @tab N @tab > -@item @code{omp_get_mapped_ptr} runtime routine @tab N @tab > +@item @code{omp_get_mapped_ptr} runtime routine @tab Y @tab > @item @code{omp_calloc}, @code{omp_realloc}, @code{omp_aligned_alloc} and > @code{omp_aligned_calloc} runtime routines @tab Y @tab > @item @code{omp_alloctrait_key_t} enum: @code{omp_atv_serialized} added, > diff --git a/libgomp/omp.h.in b/libgomp/omp.h.in > index 89c5d65..18d0152 100644 > --- a/libgomp/omp.h.in > +++ b/libgomp/omp.h.in > @@ -282,6 +282,7 @@ extern int omp_target_memcpy_rect (void *, const void *, __SIZE_TYPE__, int, > extern int omp_target_associate_ptr (const void *, const void *, __SIZE_TYPE__, > __SIZE_TYPE__, int) __GOMP_NOTHROW; > extern int omp_target_disassociate_ptr (const void *, int) __GOMP_NOTHROW; > +extern void *omp_get_mapped_ptr (const void *, int) __GOMP_NOTHROW; > > extern void omp_set_affinity_format (const char *) __GOMP_NOTHROW; > extern __SIZE_TYPE__ omp_get_affinity_format (char *, __SIZE_TYPE__) > diff --git a/libgomp/omp_lib.f90.in b/libgomp/omp_lib.f90.in > index daf40dc..506f15c 100644 > --- a/libgomp/omp_lib.f90.in > +++ b/libgomp/omp_lib.f90.in > @@ -835,6 +835,15 @@ > end function omp_target_disassociate_ptr > end interface > > + interface > + function omp_get_mapped_ptr (ptr, device_num) bind(c) > + use, intrinsic :: iso_c_binding, only : c_ptr, c_int > + type(c_ptr) :: omp_get_mapped_ptr > + type(c_ptr), value :: ptr > + integer(c_int), value :: device_num > + end function omp_get_mapped_ptr > + end interface > + > #if _OPENMP >= 201811 > !GCC$ ATTRIBUTES DEPRECATED :: omp_get_nested, omp_set_nested > #endif > diff --git a/libgomp/omp_lib.h.in b/libgomp/omp_lib.h.in > index ff857a4..0f48510 100644 > --- a/libgomp/omp_lib.h.in > +++ b/libgomp/omp_lib.h.in > @@ -416,3 +416,12 @@ > integer(c_int), value :: device_num > end function omp_target_disassociate_ptr > end interface > + > + interface > + function omp_get_mapped_ptr (ptr, device_num) bind(c) > + use, intrinsic :: iso_c_binding, only : c_ptr, c_int > + type(c_ptr) :: omp_get_mapped_ptr > + type(c_ptr), value :: ptr > + integer(c_int), value :: device_num > + end function omp_get_mapped_ptr > + end interface > diff --git a/libgomp/target.c b/libgomp/target.c > index 9017458..735d70b 100644 > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -3665,6 +3665,49 @@ omp_target_disassociate_ptr (const void *ptr, int device_num) > return ret; > } > > +void * > +omp_get_mapped_ptr (const void *ptr, int device_num) > +{ > + if (device_num < 0 || device_num > omp_get_num_devices ()) > + return NULL; > + > + if (device_num == omp_get_initial_device ()) > + return (void*)ptr; Space before * and space after ) > + struct gomp_device_descr *devicep = resolve_device (device_num); > + if (devicep == NULL) > + return NULL; > + > + if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_OPENMP_400) > + || devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) > + return (void*)ptr; Likewise. > + > + gomp_mutex_lock (&devicep->lock); > + > + struct splay_tree_s *mem_map = &devicep->mem_map; > + struct splay_tree_key_s cur_node; > + void *ret = NULL; > + uintptr_t offset = 0; offset should be moved to the only place that defines it. > + > + cur_node.host_start = (uintptr_t) ptr; > + cur_node.host_end = cur_node.host_start; > + splay_tree_key n = gomp_map_0len_lookup (mem_map, &cur_node); > + > + if (n && n->host_start == cur_node.host_start) > + { > + ret = (void*) n->tgt->tgt_start + n->tgt_offset; > + } Single statement body, so without {}s and reindented, space before *. > + else if (n) > + { > + offset = cur_node.host_start - n->host_start; uintptr_t offset = cur_node.host_start - n->host_start; > + ret = (void*) n->tgt->tgt_start + n->tgt_offset + offset; Space before *. Though, looking at this more, what is the point of the first if? The second if would compute offset = 0... Also, void * arithmetics is a GNU extension, maybe better use char *. > + if (omp_get_mapped_ptr (q, -1) != NULL) > + __builtin_abort (); When you do include stdlib.h, what is the point of using __builtin_abort ? Just use abort then. Jakub