This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: OpenACC-Library-Interoperability


Hi Cesar,

Thanks for the pointers.

I tried to use your test case to make one for DGEMM.

program test

  use iso_c_binding

  implicit none

  integer(c_int), parameter :: N = 10
  integer(c_int) :: i, j
  real(c_double) :: x(N, N), y(N, N), z(N, N)
  character(kind=c_char)     :: flag

  interface
     subroutine cublasdgemm(transa, transb, m, n, k, alpha, A, lda, B, &
             ldb, beta, C, ldc) bind(c, name="cublasDgemm")
       use iso_c_binding
       character(kind=c_char)     :: transa, transb
       integer(kind=c_int), value :: m, n, k
       real(c_double), value      :: alpha
       type(*), dimension(*)      :: A
       integer(kind=c_int), value :: lda
       type(*), dimension(*)      :: B
       integer(kind=c_int), value :: ldb
       real(c_double), value      :: beta
       type(*), dimension(*)      :: C
       integer(kind=c_int), value :: ldc

     end subroutine cublasdgemm

  end interface

  do i = 1, N
     do j = 1, N
       x(i, j) = 4.0 * i
       y(i, j) = 3.0 + j
       z(i, j) = 0.0
     end do
  end do

  flag = 'N'
  !$acc data copyin (x, y) copy (z)
  !$acc host_data use_device (x, y, z)
  call cublasdgemm(flag, flag, n, n, n, 1.0_c_double, x, n, y, n,
0.0_c_double, z, n)
  !$acc end host_data

  !$acc update self(z)

  !$acc end data

  write(*, *) z

  call dgemm(flag, flag, n, n, n, 1.0_c_double, x, n, y, n, 0.0_c_double, z, n)

  write(*, *) z

end program test


z from the cublasdgemm call gives 0 everywhere, unlike the actual
dgemm call. The first line of output is

 ** On entry to DGEMM  parameter number 1 had an illegal value

In addition, I looked at your test case. You do not do

 !$acc update self(y)

Does that mean that the host variable is automatically updated in gfortran.

Regards,
Vikram

On Mon, Aug 29, 2016 at 5:34 PM, Cesar Philippidis
<cesar_philippidis@mentor.com> wrote:
> On 08/29/2016 06:58 AM, Vikram Singh wrote:
>
>> It seems to me the data type is not being correctly translated to what
>> DGEMM requires.
>
> Correct. Arrays in gfortran have different representations from those in
> c. See
> <https://gcc.gnu.org/onlinedocs/gfortran/Interoperability-with-C.html>
> for instructions on how to call c functions from gfortran. I recently
> posted a libgomp host_data test case which calls cublas here
> <https://gcc.gnu.org/ml/gcc-patches/2016-08/msg00976.html>.
>
> Cesar


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]