OpenACC declare directive updates

James Norris jnorris@codesourcery.com
Wed Nov 4 12:32:00 GMT 2015


     This patch updates the processing of OpenACC declare directive for
     Fortran in the following areas:

         1) module support
         2) device_resident and link clauses
         3) clause checking
         4) directive generation

     Commentary on the changes is included as an attachment (NOTES).

     All of the code is in the gomp-4_0-branch.

     Regtested on x86_64-linux.

     Thanks!
     Jim
-------------- next part --------------
    Background

        The declare directive is used to allocate device memory for the
        entire scope of a variable / array within a program, function,
        or subroutine. Consider the following example.

            module vars
              integer b
              !$acc declare device_resident (b)
              integer c
              !$acc declare link (c)
            end module vars
            
            program main
              use vars
              integer, parameter :: N = 8
              integer :: a(N)
            
              a(:) = 2
              c = 12
            
              !$acc parallel copy (a) present (b) copyin(c)
              do i = 1, N
                b = a(i)
                c = b
                a(i) = c + i
              end do
              !$acc end parallel
            
            end program

        In the example, 'b' will be allocated on the device at the outset
        of device activity and be available for the duration. Whereas the
        allocation of 'c' will be delayed until the parallel region is
        entered. The device memory for 'c' will be deallocated upon exit
        of the parallel region.

    Fortran front-end

        The changes are concentrated into four (4) areas.

        1) module support
            The neccesary functionality has been added to handle the
            reading in and writing out of the appropriate attributes
            for the declare directive. Additional functionality has
            been added at read in time to setup the required declare
            handling.

        2) device_resident and link clauses
            Add the functionality necessary to process the link and
            device_resident clauses.

        3) clause checking
            The clause checking has been cleaned up to better check
            for duplicates and correctness.

        4) directive generation

            Prior to handling the fortran execution body a code
            body is created to handle the clause(s) that accompany
            the declare directive(s). Each clause is examined and
            determined whether the clause need to be modified to 
            perform an action at the beginning of the module, function,
            subroutine, or program. Furthermore, an additional
            clause may be added to the list to perform an action
            at the time the function or subroutine returns.

            Once all the clauses have been handled, the code body
            is added to the chain.

    libgomp

        TODO

    Testing

        New compile and runtime tests have been added. Also some have
        been modified.
-------------- next part --------------
2015-10-29  James Norris  <jnorris@codesourcery.com>
	    Cesar Philippidis  <cesar@codesourcery.com>

	gcc/fortran/
	* dump-parse-tree.c (show_namespace): Reimplement.
	* f95-lang.c (gfc_attribute_table): New entry.
	* gfortran.h (struct symbol_attribute): New fields.
	(enum gfc_omp_map_map): Add OMP_MAP_DEVICE_RESIDENT and OMP_MAP_LINK.
	(OMP_LIST_LINK): New enum.
	(struct gfc_oacc_declare): New structure.
	(gfc_get_oacc_declare): New definition.
	(struct gfc_namespace): Change type.
	(enum gfc_exec_op): Add EXEC_OACC_DECLARE.
	(struct gfc_code): New field.
	* module.c (enum ab_attribute): Add AB_OACC_DECLARE_CREATE,
	AB_OACC_DECLARE_COPYIN, AB_OACC_DECLARE_DEVICEPTR,
	AB_OACC_DECLARE_DEVICE_RESIDENT, AB_OACC_DECLARE_LINK
	(attr_bits): Add new initializers.
	(mio_symbol_attribute): Handle new atributes.
	* openmp.c (gfc_free_oacc_declare_clauses): New.
	(OMP_CLAUSE_LINK): New definition.
	(gfc_match_omp_clauses): Handle OMP_CLAUSE_LINK.
	(OACC_DECLARE_CLAUSES): Add OMP_CLAUSE_LINK
	(gfc_match_oacc_declare): Add checking and module handling.
	(resolve_omp_duplicate_list, resolve_oacc_declare_map): New.
	(gfc_resolve_oacc_declare): Use duplicate detection.
	* parse.c (case_decl): Add ST_OACC_DECLARE.
	(parse_spec): Remove handling.
	(parse_progunit): Remove handling.
	* parse.h (struct gfc_state_data): Change type.
	* resolve.c (gfc_resolve_blocks): Handle EXEC_OACC_DECLARE.
	* st.c (gfc_free_statement): Handle EXEC_OACC_DECLARE.
	* symbol.c (check_conflict): Add conflict checks.
	(gfc_add_oacc_declare_create, gfc_add_oacc_declare_copyin, 
	gfc_add_oacc_declare_deviceptr, gfc_add_oacc_declare_device_resident):
	New functions.
	(gfc_copy_attr): Handle new symbols.
	* trans-decl.c (add_attributes_to_decl): Create identifier.
	(add_clause, find_module_oacc_declare_clauses, finish_oacc_declare):
	New functions.
	(gfc_generate_function_code): Replace with call.
	* trans-openmp.c (gfc_trans_omp_clauses): Add conditional.
	(gfc_trans_oacc_declare): Reimplement.
	(gfc_trans_oacc_directive): Handle EXEC_OACC_DECLARE.
	* trans-stmt.c (gfc_trans_block_construct): Replace with call.
	* trans-stmt.h (gfc_trans_oacc_declare): Remove argument.
	* trans.c (trans_code): Handle EXEC_OACC_DECLARE.
	* types.def (BT_FN_VOID_PTR_INT_UINT): New type.
	gcc/testsuite
	* gfortran.dg/goacc/declare-1.f95: Update test.
	* gfortran.dg/goacc/declare-2.f95: New test.
	libgomp/
	* oacc-parallel (GOACC_enter_exit_data): Handle GOMP_MAP_TO and
	GOMP_MAP_ALLOC.
	* testsuite/libgomp.oacc-fortran/declare-1.f90: New test.
	* testsuite/libgomp.oacc-fortran/declare-2.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/declare-3.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/declare-4.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/declare-5.f90: Likewise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: declare2.patch
Type: text/x-patch
Size: 43734 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20151104/6242539f/attachment.bin>


More information about the Gcc-patches mailing list