OpenACC-Library-Interoperability

Thomas Schwinge thomas@codesourcery.com
Fri Apr 15 06:16:00 GMT 2016


Hi!

On Tue, 12 Apr 2016 18:00:02 +0300, Vikram Singh <vikramsingh001@gmail.com> wrote:
> We have a project that is written in gfortran.
> 
> I am trying to see whether we could use OpenACC in our project.

Thanks for your interest!

> I got
> gcc5.2 installed

I will just note that the upcoming GCC 6 releases will offer much
extended support for OpenACC with nvptx offloading.  (If you're building
GCC from sources anyway, you may want to give the current GCC trunk or
gomp-4_0-branch a try, after resolving the problem discussed below.)

> using instructions here.
> 
> https://github.com/olcf/OLCFHack15

Nice.  

> Now I want to do something similar to what is stated here.
> 
> https://gcc.gnu.org/onlinedocs/libgomp/OpenACC-Library-Interoperability.html
> 
> More specifically what is stated in secion 8.3. I am trying to exactly
> reproduce it using gfortran. Unfortunately I don't see how I can do it
> in fortran. In the example,
> 
> d_X = acc_copyin(&h_X[0], N * sizeof (float));
> 
> This allows d_X to be directly used in s = cublasSaxpy(h, N, &alpha,
> d_X, 1, d_Y, 1);
> 
> But in fortran, the acc_copyin does not return anything.

Correct.  I'm not much of a Fortran programmer, but as far as I remember,
Fortran doesn't have a notion of a pointer as C/C++ have.  I suppose
that's why the OpenACC specification defines that in Fortran, acc_copyin
et al. are subroutines (no return value) instead of functions, and why
acc_malloc, acc_deviceptr, acc_map et al. don't even exist in Fortran.

> So how would I replicate the case in Fortran?

You would use the OpenACC host_data construct.  So, instead of:

    [...]
    d_X = acc_copyin(&h_X[0], N * sizeof (float));
    [...]
    s = cublasSaxpy(h, N, &alpha, d_X, 1, d_Y, 1);
    [...]

... you would do something like (notice X instead of d_X and h_X)
(untested):

    [...]
    acc_copyin(X, N * sizeof (float));
    [...]
    #pragma acc host_data use_device(X)
    {
      s = cublasSaxpy(h, N, &alpha, X, 1, d_Y, 1);
    }
    [...]

I'm copying Jim, who is the author of this chapter in the documentation
as well as the libgomp/testsuite/libgomp.oacc-c-c++-common/context-*.c
test cases, and much of the relevant libgomp code, too, and who should
please correct me if I'm wrong.  I'll make a note for later, that we
should translate the libgomp.oacc-c-c++-common/context-*.c test cases to
Fortran, and also replicate them using the OpenACC host_data construct
(like in libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c), and
the same for the documentation you referenced.  (Vikram, please tell if
you're interested to work on these items.)


..., and now that've written all this, I think we have a show-stopper
here: as far as I remember, the OpenACC host_data construct is not yet
supported in the GCC 5 releases, and it's currently broken for Fortran,
too: <https://gcc.gnu.org/PR70598> (Chung-Lin if working on that).


Grüße
 Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20160415/7e51af2a/attachment.sig>


More information about the Fortran mailing list