From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1386 invoked by alias); 27 Jan 2020 14:27:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 1288 invoked by uid 89); 27 Jan 2020 14:27:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT autolearn=ham version=3.3.1 spammy=H*f:sk:1c2e2d5, H*f:sk:2019111, H*f:sk:87imp01, 2019-12-20T17 X-HELO: esa3.mentor.iphmx.com Received: from esa3.mentor.iphmx.com (HELO esa3.mentor.iphmx.com) (68.232.137.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Jan 2020 14:27:23 +0000 IronPort-SDR: AdcA1JUixb1rMtPX9kGxWW37L0TH3MB9jcqdZC+yfgQckVQbRSZfOUuvMgSjSn1OFjyuvY8m5d vibHidmwyq+MLH8T6Z+eCB3SDe4FFp2m24xj7PBYT+7Y6KbmrUvnFiUURIMlNNM3h0YhQyg1Us blnPyfH31ZdoUZ1SLMfZFGrOn8rIjlgv5WRSC0sgRmPXhK5Iyuyt5s0Tg67h4qvnHwqT/HQVAO lKtt6xoZfzRNTeX7xORV6JAySRA434lsDDxUUwYdenR8A8NZAzDSGHS0v9x8Pkc3az+xxU3c1V L7o= Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 27 Jan 2020 06:27:21 -0800 IronPort-SDR: 7+uOR/S/NMY5HwgwTNS2I5wcOOS2OwZSsosrV2d6B9PjhJhYUNdCQCgy27k65P66o34LSVxYcL NsqoUrLjroZA== From: Thomas Schwinge To: Frederik Harwath , Tobias Burnus , CC: , Jakub Jelinek Subject: Fortran 'acc_get_property' return type (was: [PATCH] Add OpenACC 2.6 `acc_get_property' support) In-Reply-To: <1c2e2d57-31ce-8e4d-c8b9-c2fbc7091e86@codesourcery.com> References: <20191113153215.17750-1-frederik@codesourcery.com> <87imp01jr3.fsf@euler.schwinge.homeip.net> <20191114153531.7493-1-frederik@codesourcery.com> <87v9qfyiyz.fsf@euler.schwinge.homeip.net> <1c2e2d57-31ce-8e4d-c8b9-c2fbc7091e86@codesourcery.com> User-Agent: Notmuch/0.29.1+93~g67ed7df (https://notmuchmail.org) Emacs/26.1 (x86_64-pc-linux-gnu) Date: Mon, 27 Jan 2020 14:57:00 -0000 Message-ID: <87wo9drn45.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Return-Path: tschwing@mentor.com X-SW-Source: 2020-01/txt/msg01746.txt.bz2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-length: 9129 Hi! On 2019-12-20T17:46:57+0100, "Harwath, Frederik" wrote: >> > --- a/libgomp/libgomp-plugin.h >> > +++ b/libgomp/libgomp-plugin.h >> > @@ -54,6 +54,13 @@ enum offload_target_type >> > OFFLOAD_TARGET_TYPE_GCN =3D3D 8 >> > }; >> >=3D20=3D20 >> > +/* Container type for passing device properties. */ >> > +union gomp_device_property_value >> > +{ >> > + void *ptr; >> > + uintmax_t val; >> > +}; >> >> Why wouldn't that be 'size_t', 'const char *', as the actual data types >> used? (Maybe I'm missing something.) > > I do not see a reason for this either. Changed. For reference: C/C++ has 'size_t' ('acc_get_property'), or 'const char*' ('acc_get_property_string') return types. >> > --- a/libgomp/openacc.f90 >> > +++ b/libgomp/openacc.f90 >> > @@ -28,7 +28,7 @@ >> > ! . >> >=3D20=3D20 >> > module openacc_kinds >> > - use iso_fortran_env, only: int32 >> > + use iso_fortran_env, only: int32, int64 >> > implicit none >> >=3D20=3D20 >> > private :: int32 >> > @@ -47,6 +47,21 @@ module openacc_kinds >> > integer (acc_device_kind), parameter :: acc_device_not_host =3D3D 4 >> > integer (acc_device_kind), parameter :: acc_device_nvidia =3D3D 5 >> > integer (acc_device_kind), parameter :: acc_device_gcn =3D3D 8 >> > + integer (acc_device_kind), parameter :: acc_device_current =3D3D -3 >> > + >> > + public :: acc_device_property >> > + >> > + integer, parameter :: acc_device_property =3D3D int64 >> >> Why 'int64'? I changed this to 'int32', but please tell if there's a >> reason for 'int64'. > > int32 is too narrow as - conforming to the OpenACC spec - acc_device_prop= erty > is also used for the return type of acc_get_property (a bit strang, isn't= it?). > int64 also did not seem quite right. I have changed the type of acc_devic= e_property > to c_size_t to match the type that is used internally and as the return t= ype of the > corresponding C function. I filed "Fortran 'acc_get_property' return type": | During review/implementation of `acc_get_property` in GCC, @frederik-h | found that for Fortran `function acc_get_property`, the return type is | specified as `integer(acc_device_property) :: acc_get_property`, | whereas in C/C++, it is `size_t`. For avoidance of doubt: it's correct | to map the C/C++ `acc_device_property_t property` formal parameter to | Fortran `integer(acc_device_property), value :: property`, but it's not | clear why `integer(acc_device_property)` is also used as the function's | return type -- the return type/values don't actually (conceptually) | relate to the `integer(acc_device_property)` data type. |=20 | Should we use `c_size_t` for Fortran `acc_get_property` return type to | explicitly match C/C++, or use plain `integer` (as used in all other | interfaces taking `size_t` in C/C++ -- currently only as input formal | parameters though)? Gr=C3=BC=C3=9Fe Thomas > --- a/libgomp/libgomp.texi > +++ b/libgomp/libgomp.texi > +@node acc_get_property > +@section @code{acc_get_property} -- Get device property. > +@cindex acc_get_property > +@cindex acc_get_property_string > +@table @asis > +@item @emph{Description} > +These routines return the value of the specified @var{property} for the > +device being queried according to @var{devicenum} and @var{devicetype}. > +Integer-valued and string-valued properties are returned by > +@code{acc_get_property} and @code{acc_get_property_string} respectively. > +The Fortran @code{acc_get_property_string} subroutine returns the string > +retrieved in its fourth argument while the remaining entry points are > +functions, which pass the return value as their result. > + > +@item @emph{C/C++}: > +@multitable @columnfractions .20 .80 > +@item @emph{Prototype}: @tab @code{size_t acc_get_property(int devicenum= , acc_device_t devicetype, acc_device_property_t property);} > +@item @emph{Prototype}: @tab @code{const char *acc_get_property_string(i= nt devicenum, acc_device_t devicetype, acc_device_property_t property);} > +@end multitable > + > +@item @emph{Fortran}: > +@multitable @columnfractions .20 .80 > +@item @emph{Interface}: @tab @code{function acc_get_property(devicenum, = devicetype, property)} > +@item @emph{Interface}: @tab @code{subroutine acc_get_property_string(de= vicenum, devicetype, property, string)} > +@item @tab @code{integer devicenum} > +@item @tab @code{integer(kind=3Dacc_device_kind) devic= etype} > +@item @tab @code{integer(kind=3Dacc_device_property) p= roperty} > +@item @tab @code{integer(kind=3Dacc_device_property) a= cc_get_property} > +@item @tab @code{character(*) string} > +@end multitable > + > +@item @emph{Reference}: > +@uref{https://www.openacc.org, OpenACC specification v2.6}, section > +3.2.6. > +@end table > --- a/libgomp/openacc.f90 > +++ b/libgomp/openacc.f90 > @@ -31,16 +31,18 @@ >=20=20 > module openacc_kinds > use iso_fortran_env, only: int32 > + use iso_c_binding, only: c_size_t > implicit none >=20=20 > public > - private :: int32 > + private :: int32, c_size_t >=20=20 > @@ -89,6 +100,24 @@ module openacc_internal > integer (acc_device_kind) d > end function >=20=20 > + function acc_get_property_h (n, d, p) > + import > + implicit none (type, external) > + integer (acc_device_property) :: acc_get_property_h > + integer, value :: n > + integer (acc_device_kind), value :: d > + integer (acc_device_property), value :: p > + end function > + > + subroutine acc_get_property_string_h (n, d, p, s) > + import > + implicit none (type, external) > + integer, value :: n > + integer (acc_device_kind), value :: d > + integer (acc_device_property), value :: p > + character (*) :: s > + end subroutine > + > function acc_async_test_h (a) > logical acc_async_test_h > integer a > @@ -508,6 +537,26 @@ module openacc_internal > integer (c_int), value :: d > end function >=20=20 > + function acc_get_property_l (n, d, p) & > + bind (C, name =3D "acc_get_property") > + use iso_c_binding, only: c_int, c_size_t > + implicit none (type, external) > + integer (c_size_t) :: acc_get_property_l > + integer (c_int), value :: n > + integer (c_int), value :: d > + integer (c_int), value :: p > + end function > + > + function acc_get_property_string_l (n, d, p) & > + bind (C, name =3D "acc_get_property_string") > + use iso_c_binding, only: c_int, c_ptr > + implicit none (type, external) > + type (c_ptr) :: acc_get_property_string_l > + integer (c_int), value :: n > + integer (c_int), value :: d > + integer (c_int), value :: p > + end function > @@ -758,6 +814,14 @@ module openacc > procedure :: acc_get_device_num_h > end interface >=20=20 > + interface acc_get_property > + procedure :: acc_get_property_h > + end interface > + > + interface acc_get_property_string > + procedure :: acc_get_property_string_h > + end interface > + > interface acc_async_test > procedure :: acc_async_test_h > end interface > @@ -976,6 +1040,63 @@ function acc_get_device_num_h (d) > acc_get_device_num_h =3D acc_get_device_num_l (d) > end function >=20=20 > +function acc_get_property_h (n, d, p) > + use iso_c_binding, only: c_int, c_size_t > + use openacc_internal, only: acc_get_property_l > + use openacc_kinds > + implicit none (type, external) > + integer (acc_device_property) :: acc_get_property_h > + integer, value :: n > + integer (acc_device_kind), value :: d > + integer (acc_device_property), value :: p > + > + integer (c_int) :: pint > + > + pint =3D int (p, c_int) > + acc_get_property_h =3D acc_get_property_l (n, d, pint) > +end function > + > +subroutine acc_get_property_string_h (n, d, p, s) > + use iso_c_binding, only: c_char, c_int, c_ptr, c_f_pointer, c_associat= ed > + use openacc_internal, only: acc_get_property_string_l > + use openacc_kinds > + implicit none (type, external) > + integer, value :: n > + integer (acc_device_kind), value :: d > + integer (acc_device_property), value :: p > + character (*) :: s > + > + integer (c_int) :: pint > + type (c_ptr) :: cptr > + integer :: clen > + character (kind=3Dc_char, len=3D1), pointer, contiguous :: sptr (:) > + integer :: slen > + integer :: i > + > + interface > + function strlen (s) bind (C, name =3D "strlen") > + use iso_c_binding, only: c_ptr, c_size_t > + type (c_ptr), intent(in), value :: s > + integer (c_size_t) :: strlen > + end function strlen > + end interface > + > + pint =3D int (p, c_int) > + cptr =3D acc_get_property_string_l (n, d, pint) > + s =3D "" > + if (.not. c_associated (cptr)) then > + return > + end if > + > + clen =3D int (strlen (cptr)) > + call c_f_pointer (cptr, sptr, [clen]) > + > + slen =3D min (clen, len (s)) > + do i =3D 1, slen > + s (i:i) =3D sptr (i) > + end do > +end subroutine --=-=-= Content-Type: application/pgp-signature; name="signature.asc" Content-length: 658 -----BEGIN PGP SIGNATURE----- iQGzBAEBCgAdFiEEU9WEfWKGQazCmycCAKI7+41Q4XkFAl4u8zoACgkQAKI7+41Q 4XkMrAv/ZGdcJpaNC7WHXVOVRfUIt756BH0esb+J8eaJjE+Rv/oREo34FUIb4Byc mkbnAoC1PS8l0T3X4fEpQfxEFPHbhjOqWUUS3KkgNo+b6LLXByztOHNy5GuURQ5o gYdrB2xtjOwS+/rGDhg5nmrhwiGrorbyL8z8ih8yKtlL7HtNwL+cOnfEHKOT0QpY /+i/Y+wO4Gk2VAE9B0In0sqnyV9rc0wy1TpQmQONP4wpIq2MVzpkMh+9D0f2PrbL GgNlnvhjEwG6wlrN0BxDYB2EZgAGXpubeFJ0HHNwW41b0nB66ukh984Fd5KlLyb3 lMjA4Seh5hDX36dhzn7i6xu5t9pIpqvFQ8hKZQpAV8nRofXdT1plIFLwt7qr9VRG AnxomEEMsyiw5gYiA7zPzQwO7gIDbhrX/L2iKBe7fZgws3yDBF5y9t5JSPRSuucV tDGdF7bMcUgUYxiacDVjFLf+r+4hpTI6AeaTgjmU/luFUYd4nkHoxpUSk8dEMaNR bhOEDNZb =4Y5A -----END PGP SIGNATURE----- --=-=-=--