This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: OpenACC-Library-Interoperability
- From: Vikram Singh <vikramsingh001 at gmail dot com>
- To: Cesar Philippidis <cesar_philippidis at mentor dot com>
- Cc: Thomas Schwinge <thomas at codesourcery dot com>, Salvatore Filippone <filippone dot salvatore at gmail dot com>, Vladimír Fuka <vladimir dot fuka at gmail dot com>, James Norris <jnorris at codesourcery dot com>, Chung-Lin Tang <cltang at codesourcery dot com>, Fortran List <fortran at gcc dot gnu dot org>
- Date: Mon, 29 Aug 2016 18:38:25 +0300
- Subject: Re: OpenACC-Library-Interoperability
- Authentication-results: sourceware.org; auth=none
- References: <CAD0gq3XehzKyOqvqWfmSErNiy8CKkHqNvqAg5nU5eCyV5gQ4RA@mail.gmail.com> <8737qn5rd4.fsf@kepler.schwinge.homeip.net> <CAD0gq3XgHLLWfY8BJWCc2vPC6S4E2tHBvBfdok0yK5Gs4K5Qzw@mail.gmail.com> <8760vj45bi.fsf@hertz.schwinge.homeip.net> <CAKe2itfWOXb11iRpVtJXsU9Eh-3RpdK4dt_WX+WRO6bLvgd-NQ@mail.gmail.com> <CANSzZf4vnc23kHpSGQ4mW8RmuAYeytZu8dYvPQ3xi_v9V9Q7iQ@mail.gmail.com> <2b4f59d5-be38-2814-27bb-73aa7ffb4b8f@codesourcery.com> <878u0o6wwj.fsf@kepler.schwinge.homeip.net> <CAD0gq3VX0x6qCkMWLJBqK=9WRYk0O_38yCctwaQRcmqdWU0jiQ@mail.gmail.com> <87inyjuw6b.fsf@kepler.schwinge.homeip.net> <CAD0gq3VoRWCiXRkgi-bnGLBfSjR-bFc0Mzp19LRr+yWP4MrYLg@mail.gmail.com> <CAD0gq3WmRfe7g-F-=imZMZg9zNE=sJ8xTcveb-H9F7_92wSjVA@mail.gmail.com> <CAD0gq3VN5h4e5QGOAJe9kes554P3yeXekY3sacy86B1RwuKJGQ@mail.gmail.com> <5c27828e-6b7b-bdde-1fb2-0d0984e4123b@mentor.com>
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