Implementing OpenACC's Fortran module

Thomas Schwinge thomas@codesourcery.com
Thu Apr 13 17:45:00 GMT 2017


Hi!

The issue discussed here two and a half years ago ;-/ has not yet been
resolved; see below for the old discussion.  I now ran into this, so had
a look myself.  So, there is now a simple patch that seems to work, but I
don't really know what I'm doing there...  ;-| Any comments will be
appreaciated.

On Fri, 10 Oct 2014 12:42:06 +0200, I wrote:
> In the OpenACC Runtime Library, acc_pcopyin and acc_pcreate are to be
> aliases for acc_present_or_copyin and acc_present_or_create,
> respectively.
> 
> This is implemented in openacc.f90 as follows:
> 
> On Tue, 19 Aug 2014 15:34:35 -0500, James Norris <jnorris@codesourcery.com> wrote:
> > module openacc
> >   use openacc_kinds
> >   use openacc_internal
> >   implicit none
> > 
> >   private
> >   public :: openacc_version
> > 
> >   public :: [...], acc_present_or_copyin, acc_pcopyin, acc_create
> >   public :: acc_present_or_create, acc_pcreate, [...]
> 
> >   interface acc_present_or_copyin
> >     procedure :: acc_present_or_copyin_32_h
> >     procedure :: acc_present_or_copyin_64_h
> >     procedure :: acc_present_or_copyin_array_h
> >   end interface
> > 
> >   interface acc_pcopyin
> >     procedure :: acc_present_or_copyin_32_h
> >     procedure :: acc_present_or_copyin_64_h
> >     procedure :: acc_present_or_copyin_array_h
> >   end interface
> 
> >   interface acc_present_or_create
> >     procedure :: acc_present_or_create_32_h
> >     procedure :: acc_present_or_create_64_h
> >     procedure :: acc_present_or_create_array_h
> >   end interface
> > 
> >   interface acc_pcreate
> >     procedure :: acc_present_or_create_32_h
> >     procedure :: acc_present_or_create_64_h
> >     procedure :: acc_present_or_create_array_h
> >   end interface
> 
> Even given my very limited knowledge of Fortran, what I understand this
> to do is defer the acc_pcopyin and acc_pcreate interfaces to the existing
> acc_present_or_copyin_*_h and acc_present_or_create_*_h routines:
> 
> > end module
> 
> > subroutine acc_present_or_copyin_32_h (a, len)
> >   use iso_c_binding, only: c_int32_t, c_size_t
> >   use openacc_internal, only: acc_present_or_copyin_l
> >   !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >   type(*), dimension(*) :: a
> >   integer(c_int32_t) len
> >   call acc_present_or_copyin_l (a, int (len, kind=c_size_t))
> > end subroutine
> > 
> > subroutine acc_present_or_copyin_64_h (a, len)
> >   [...]
> > end subroutine
> > 
> > subroutine acc_present_or_copyin_array_h (a)
> >   [...]
> > end subroutine
> 
> > subroutine acc_present_or_create_32_h (a, len)
> >   use iso_c_binding, only: c_int32_t, c_size_t
> >   use openacc_internal, only: acc_present_or_create_l
> >   !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >   type(*), dimension(*) :: a
> >   integer(c_int32_t) len
> >   call acc_present_or_create_l (a, int (len, kind=c_size_t))
> > end subroutine
> > 
> > subroutine acc_present_or_create_64_h (a, len)
> >   [...]
> > end subroutine
> > 
> > subroutine acc_present_or_create_array_h (a)
> >   [...]
> > end subroutine
> 
> What are we to do in the openacc_lib.h file, however?  Here we currently
> have the acc_pcopyin and acc_pcreate interfaces refer to acc_pcopyin_*_h
> and acc_pcreate_*_h routines -- which don't exist.

(... which results in link-time errors if you call these.)

> Can we have them
> refer to the acc_present_or_copyin_*_h and acc_present_or_create_*_h
> routines instead?
> 
> >       interface acc_present_or_copyin
> >         subroutine acc_present_or_copyin_32_h (a, len)
> >           use iso_c_binding, only: c_int32_t
> >           !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >           type(*), dimension(*) :: a
> >           integer(c_int32_t) len
> >         end subroutine
> >   
> >         subroutine acc_present_or_copyin_64_h (a, len)
> >           use iso_c_binding, only: c_int64_t
> >           !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >           type(*), dimension(*) :: a
> >           integer(c_int64_t) len
> >         end subroutine
> >   
> >         subroutine acc_present_or_copyin_array_h (a)
> >           class(*), dimension(..) :: a
> >           end subroutine
> >       end interface
> > 
> >       interface acc_pcopyin
> >         subroutine acc_pcopyin_32_h (a, len)
> >           use iso_c_binding, only: c_int32_t
> >           !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >           type(*), dimension(*) :: a
> >           integer(c_int32_t) len
> >         end subroutine
> >   
> >         subroutine acc_pcopyin_64_h (a, len)
> >           use iso_c_binding, only: c_int64_t
> >           !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >           type(*), dimension(*) :: a
> >           integer(c_int64_t) len
> >         end subroutine
> >   
> >         subroutine acc_pcopyin_array_h (a)
> >           class(*), dimension(..) :: a
> >           end subroutine
> >       end interface
> 
> >       interface acc_present_or_create
> >         subroutine acc_present_or_create_32_h (a, len)
> >           use iso_c_binding, only: c_int32_t
> >           !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >           type(*), dimension(*) :: a
> >           integer(c_int32_t) len
> >         end subroutine
> >   
> >         subroutine acc_present_or_create_64_h (a, len)
> >           use iso_c_binding, only: c_int64_t
> >           !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >           type(*), dimension(*) :: a
> >           integer(c_int64_t) len
> >         end subroutine
> >   
> >         subroutine acc_present_or_create_array_h (a)
> >           class(*), dimension(..) :: a
> >           end subroutine
> >       end interface
> > 
> >       interface acc_pcreate
> >         subroutine acc_pcreate_32_h (a, len)
> >           use iso_c_binding, only: c_int32_t
> >           !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >           type(*), dimension(*) :: a
> >           integer(c_int32_t) len
> >         end subroutine
> >   
> >         subroutine acc_pcreate_64_h (a, len)
> >           use iso_c_binding, only: c_int64_t
> >           !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
> >           type(*), dimension(*) :: a
> >           integer(c_int64_t) len
> >         end subroutine
> >   
> >         subroutine acc_pcreate_array_h (a)
> >           class(*), dimension(..) :: a
> >           end subroutine
> >       end interface

The following patch seems to do the right thing (that is, "divert" calls
of "acc_pcopyin" to the existing "acc_present_or_copyin_*_h", and
likewise for "acc_pcreate").  Is that the correct way of doing this?

diff --git libgomp/openacc_lib.h libgomp/openacc_lib.h
index 65f47a8..7818bd7 100644
--- libgomp/openacc_lib.h
+++ libgomp/openacc_lib.h
@@ -191,23 +191,9 @@
       end interface
 
       interface acc_pcopyin
-        subroutine acc_pcopyin_32_h (a, len)
-          use iso_c_binding, only: c_int32_t
-          !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
-          type (*), dimension (*) :: a
-          integer (c_int32_t) len
-        end subroutine
-
-        subroutine acc_pcopyin_64_h (a, len)
-          use iso_c_binding, only: c_int64_t
-          !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
-          type (*), dimension (*) :: a
-          integer (c_int64_t) len
-        end subroutine
-
-        subroutine acc_pcopyin_array_h (a)
-          type (*), dimension (..), contiguous :: a
-          end subroutine
+        procedure :: acc_present_or_copyin_32_h
+        procedure :: acc_present_or_copyin_64_h
+        procedure :: acc_present_or_copyin_array_h
       end interface
 
       interface acc_create
@@ -251,23 +237,9 @@
       end interface
 
       interface acc_pcreate
-        subroutine acc_pcreate_32_h (a, len)
-          use iso_c_binding, only: c_int32_t
-          !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
-          type (*), dimension (*) :: a
-          integer (c_int32_t) len
-        end subroutine
-
-        subroutine acc_pcreate_64_h (a, len)
-          use iso_c_binding, only: c_int64_t
-          !GCC$ ATTRIBUTES NO_ARG_CHECK :: a
-          type (*), dimension (*) :: a
-          integer (c_int64_t) len
-        end subroutine
-
-        subroutine acc_pcreate_array_h (a)
-          type (*), dimension (..), contiguous :: a
-          end subroutine
+        procedure :: acc_present_or_create_32_h
+        procedure :: acc_present_or_create_64_h
+        procedure :: acc_present_or_create_array_h
       end interface
 
       interface acc_copyout


Grüße
 Thomas



More information about the Fortran mailing list