From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.133.74]) by sourceware.org (Postfix) with ESMTPS id CEC413858434 for ; Thu, 5 May 2022 09:33:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CEC413858434 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-462-ZDutD-V8NhGhIAkztVXPHg-1; Thu, 05 May 2022 05:33:30 -0400 X-MC-Unique: ZDutD-V8NhGhIAkztVXPHg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E702E10665AC; Thu, 5 May 2022 09:33:29 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A7F5114C1D40; Thu, 5 May 2022 09:33:29 +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 2459XQum1706495 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 5 May 2022 11:33:27 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 2459XPqY1706494; Thu, 5 May 2022 11:33:25 +0200 Date: Thu, 5 May 2022 11:33:25 +0200 From: Jakub Jelinek To: Marcel Vollweiler Cc: Tobias Burnus , gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: Re: [Patch] OpenMP, libgomp: Add new runtime routine omp_target_is_accessible. Message-ID: Reply-To: Jakub Jelinek References: <7fa4a70c-60e7-fa18-0fcd-98301c0b3344@codesourcery.com> <1b53e970-a0a7-66bc-4b2e-828e881cce73@codesourcery.com> <31be8262-626b-e3be-60d8-14bdf2911f64@codesourcery.com> MIME-Version: 1.0 In-Reply-To: <31be8262-626b-e3be-60d8-14bdf2911f64@codesourcery.com> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, 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: Thu, 05 May 2022 09:33:35 -0000 On Mon, Mar 14, 2022 at 04:42:14PM +0100, Marcel Vollweiler wrote: > --- a/libgomp/libgomp.map > +++ b/libgomp/libgomp.map > @@ -226,6 +226,11 @@ OMP_5.1 { > omp_get_teams_thread_limit_; > } OMP_5.0.2; > > +OMP_5.1.1 { > + global: > + omp_target_is_accessible; > +} OMP_5.1; > + You've already added another OMP_5.1.1 symbol, so this hunk will need to be adjusted. Keep the names in there alphabetically sorted. > --- a/libgomp/omp_lib.f90.in > +++ b/libgomp/omp_lib.f90.in > @@ -835,6 +835,16 @@ > end function omp_target_disassociate_ptr > end interface > > + interface > + function omp_target_is_accessible (ptr, size, device_num) bind(c) > + use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t, c_int > + integer(c_int) :: omp_target_is_accessible The function returning integer(c_int) rather than logical seems like a screw up in the standard, but too late to fix that :(. > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -3666,6 +3666,24 @@ omp_target_disassociate_ptr (const void *ptr, int device_num) > } > > int > +omp_target_is_accessible (const void *ptr, size_t size, int device_num) > +{ > + if (device_num < 0 || device_num > gomp_get_num_devices ()) > + return false; > + > + if (device_num == gomp_get_num_devices ()) > + return true; > + > + struct gomp_device_descr *devicep = resolve_device (device_num); > + if (devicep == NULL) > + return false; > + > + /* TODO: Unified shared memory must be handled when available. */ > + > + return devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM; I guess for now it is reasonable, but I wonder if even without GOMP_OFFLOAD_CAP_SHARED_MEM one can't for CUDA or GCN allocate host memory (not all, but just some subset) that will be accessible on the device (I bet that means accessible through the same address on the host and device, aka partial shared mem). So, ok for trunk. OT, tried to look how libomptarget implements it and they don't at least on llvm-project trunk, but while looking at that, noticed that for omp_target_is_present they do return false from omp_target_is_present while we return true. It is unclear if NULL has corresponding storage on the device (NULL always corresponds to NULL on the device) or not. Jakub