[gomp4] OpenACC routine directive

Tobias Burnus tobias.burnus@physik.fu-berlin.de
Tue Sep 16 07:25:00 GMT 2014

Cesar Philippidis wrote:
> This patch adds initial support for the OpenACC routine directive. It's
> not complete just yet because it doesn't implement any of the optional
> clauses, except for the optional function/subroutine name. As such, it
> doesn't go beyond marking functions with the "omp declare target" attribute.

For the Fortran side: As you currently use the OpenMP implementation, it
should work, but if you later add support for clauses, recall that you may
need to store those also in the .mod files (cf. module.c). (That's only needed
if information from the clauses has to be propagated to the the call site.)

> My understanding is 'acc routine' should also be visible at the call site,
> but if it's not the compiler can treat it as a regular function call.

... which means that it has to reject it, unless the compiler can (e.g. via
LTO) inline the function or find out that the function also exist on the

> Furthermore, I've been told that it's not sufficient to place the
> routine directive in an interface block by itself. 

Well, that's also not different to C/C++: If you just use "#pragma acc routine"
in the header file, where you declare the function, it also won't work when
you don't have the pragma for the definition.

> The justification for this is that fortran
> lacks a file scope, so 'acc routine' wouldn't be visible to fact.

True. However,in modern Fortran use, you would use not use an interface
block (unless the function is written in, e.g., C). But you would use
a module - or an internal procedure (nested procedure with "contains").

If you want, you can also check that an omp declare target/acc routine
in an interface block matches the one in a subroutine/function by
adding a check in resolve.c's resolve_global_procedure.

> Is this patch OK for gomp-4_0-branch?

The Fortran part looks good to me.


> 2014-09-15  Cesar Philippidis  <cesar@codesourcery.com>
>	gcc/fortran/
>	* gfortran.h (ST_OACC_ROUTINE): New statement enum.
>	* match.h (gfc_match_oacc_routine): New prototype.
>	* openmp.c (gfc_match_oacc_routine): New function.
>	* parse.c (decode_oacc_directive): Handle the routine directive.
>	(next_statement): Handle ST_OACC_ROUTINE.
>	(gfc_ascii_statement): Likewise.

More information about the Gcc-patches mailing list