Re: update acc routines in fortran
On 11/20/2015 02:18 AM, Jakub Jelinek wrote: > On Thu, Nov 19, 2015 at 08:26:45AM -0800, Cesar Philippidis wrote: >> (gfc_oacc_routine_name): New struct; > > Full stop instead of semicolon. Fixed. >> diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c >> index 1f6311c..e321072 100644 >> --- a/gcc/tree-nested.c >> +++ b/gcc/tree-nested.c >> @@ -1106,6 +1106,9 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct >> walk_stmt_info *wi) >> case OMP_CLAUSE_NUM_TASKS: >> case OMP_CLAUSE_HINT: >> case OMP_CLAUSE__CILK_FOR_COUNT_: >> +case OMP_CLAUSE_NUM_GANGS: >> +case OMP_CLAUSE_NUM_WORKERS: >> +case OMP_CLAUSE_VECTOR_LENGTH: >>wi->val_only = true; >>wi->is_lhs = false; >>convert_nonlocal_reference_op (_CLAUSE_OPERAND (clause, 0), >> @@ -1173,6 +1176,10 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct >> walk_stmt_info *wi) >> case OMP_CLAUSE_THREADS: >> case OMP_CLAUSE_SIMD: >> case OMP_CLAUSE_DEFAULTMAP: >> +case OMP_CLAUSE_GANG: >> +case OMP_CLAUSE_WORKER: >> +case OMP_CLAUSE_VECTOR: > > This looks wrong. OMP_CLAUSE_GANG has 2 arguments, OMP_CLAUSE_WORKER and > OMP_CLAUSE_VECTOR one argument, if you use a non-local decl or local decl > that is referenced by a nested routine in those operands, it won't be > handled properly. Yeah, you're right. This didn't get updated when we added support for the loop shape arguments. I fixed that in this patch. >> @@ -1830,6 +1840,10 @@ convert_local_omp_clauses (tree *pclauses, struct >> walk_stmt_info *wi) >> case OMP_CLAUSE_THREADS: >> case OMP_CLAUSE_SIMD: >> case OMP_CLAUSE_DEFAULTMAP: >> +case OMP_CLAUSE_GANG: >> +case OMP_CLAUSE_WORKER: >> +case OMP_CLAUSE_VECTOR: >> +case OMP_CLAUSE_SEQ: > > Ditto. > > Otherwise LGTM. Are the tree-nested changes ok? Cesar 2015-11-24 Cesar Philippidisgcc/ * tree-nested.c (convert_nonlocal_omp_clauses): Add support for OMP_CLAUSE_{NUM_GANGS,NUM_VECTORS,VECTOR_LENGTH,SEQ}. (convert_local_omp_clauses): Likewise. 2015-11-24 Cesar Philippidis James Norris Nathan Sidwell gcc/fortran/ * f95-lang.c (gfc_attribute_table): Add an "oacc function" attribute. * gfortran.h (symbol_attribute): Add an oacc_function bit-field. (gfc_oacc_routine_name): New struct; (gfc_get_oacc_routine_name): New macro. (gfc_namespace): Add oacc_routine_clauses, oacc_routine_names and oacc_routine fields. (gfc_exec_op): Add EXEC_OACC_ROUTINE. * openmp.c (OACC_ROUTINE_CLAUSES): New mask. (gfc_oacc_routine_dims): New function. (gfc_match_oacc_routine): Add support for named routines and the gang, worker vector and seq clauses. * parse.c (is_oacc): Add EXEC_OACC_ROUTINE. * resolve.c (gfc_resolve_blocks): Likewise. * st.c (gfc_free_statement): Likewise. * trans-decl.c (add_attributes_to_decl): Attach an 'oacc function' attribute and shape geometry for acc routine. 2015-11-24 Cesar Philippidis Nathan Sidwell gcc/testsuite/ * gfortran.dg/goacc/routine-3.f90: New test. * gfortran.dg/goacc/routine-4.f90: New test. * gfortran.dg/goacc/routine-5.f90: New test. * gfortran.dg/goacc/routine-6.f90: New test. * gfortran.dg/goacc/subroutines: New test. 2015-11-24 James Norris Cesar Philippidis libgomp/ * libgomp.oacc-fortran/routine-5.f90: New test. * libgomp.oacc-fortran/routine-7.f90: New test. * libgomp.oacc-fortran/routine-9.f90: New test. diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c index 605c2ab..8556b70 100644 --- a/gcc/fortran/f95-lang.c +++ b/gcc/fortran/f95-lang.c @@ -93,6 +93,8 @@ static const struct attribute_spec gfc_attribute_table[] = affects_type_identity } */ { "omp declare target", 0, 0, true, false, false, gfc_handle_omp_declare_target_attribute, false }, + { "oacc function", 0, -1, true, false, false, +gfc_handle_omp_declare_target_attribute, false }, { NULL, 0, 0, false, false, false, NULL, false } }; diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 5487c93..0628e86 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -848,6 +848,9 @@ typedef struct unsigned oacc_declare_device_resident:1; unsigned oacc_declare_link:1; + /* This is an OpenACC acclerator function at level N - 1 */ + unsigned oacc_function:3; + /* Attributes set by compiler extensions (!GCC$ ATTRIBUTES). */ unsigned ext_attr:EXT_ATTR_NUM; @@ -1606,6 +1609,16 @@ gfc_dt_list; /* A list of all derived types. */ extern gfc_dt_list *gfc_derived_types; +typedef struct gfc_oacc_routine_name +{ + struct gfc_symbol *sym; + struct gfc_omp_clauses *clauses; + struct gfc_oacc_routine_name *next; +} +gfc_oacc_routine_name; + +#define gfc_get_oacc_routine_name() XCNEW (gfc_oacc_routine_name)
Re: update acc routines in fortran
On Thu, Nov 19, 2015 at 08:26:45AM -0800, Cesar Philippidis wrote: > (gfc_oacc_routine_name): New struct; Full stop instead of semicolon. > diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c > index 1f6311c..e321072 100644 > --- a/gcc/tree-nested.c > +++ b/gcc/tree-nested.c > @@ -1106,6 +1106,9 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct > walk_stmt_info *wi) > case OMP_CLAUSE_NUM_TASKS: > case OMP_CLAUSE_HINT: > case OMP_CLAUSE__CILK_FOR_COUNT_: > + case OMP_CLAUSE_NUM_GANGS: > + case OMP_CLAUSE_NUM_WORKERS: > + case OMP_CLAUSE_VECTOR_LENGTH: > wi->val_only = true; > wi->is_lhs = false; > convert_nonlocal_reference_op (_CLAUSE_OPERAND (clause, 0), > @@ -1173,6 +1176,10 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct > walk_stmt_info *wi) > case OMP_CLAUSE_THREADS: > case OMP_CLAUSE_SIMD: > case OMP_CLAUSE_DEFAULTMAP: > + case OMP_CLAUSE_GANG: > + case OMP_CLAUSE_WORKER: > + case OMP_CLAUSE_VECTOR: This looks wrong. OMP_CLAUSE_GANG has 2 arguments, OMP_CLAUSE_WORKER and OMP_CLAUSE_VECTOR one argument, if you use a non-local decl or local decl that is referenced by a nested routine in those operands, it won't be handled properly. > @@ -1830,6 +1840,10 @@ convert_local_omp_clauses (tree *pclauses, struct > walk_stmt_info *wi) > case OMP_CLAUSE_THREADS: > case OMP_CLAUSE_SIMD: > case OMP_CLAUSE_DEFAULTMAP: > + case OMP_CLAUSE_GANG: > + case OMP_CLAUSE_WORKER: > + case OMP_CLAUSE_VECTOR: > + case OMP_CLAUSE_SEQ: Ditto. Otherwise LGTM. Jakub
update acc routines in fortran
This patch extends the existing support for acc routines in fortran. It's a little bit more invasive than what I remembered, but it's still fairly straightforward. Basically, it adds support for the following: - name routines - gang, worker, vector and seq clauses In addition, I've also taught tree-nested to be aware of the aforementioned clauses. Without those tree-nested changes, a lot of the new test cases would fail. If you observe the changelog closely, you'll noticed that I didn't include libgomp.oacc-fortran/routine-[48].f90. The reason is, we don't have support for the bind and nohost clauses on trunk yet. Thomas posted a patch right before stage1 closed. So if that patch gets accepted, I'll create a follow up patch for routines in fortran. This this OK for trunk? Cesar 2015-11-19 Cesar Philippidisgcc/ * tree-nested.c (convert_nonlocal_omp_clauses): Add support for OMP_CLAUSE_{NUM_GANGS,NUM_VECTORS,VECTOR_LENGTH,SEQ}. (convert_local_omp_clauses): Likewise. 2015-11-19 Cesar Philippidis James Norris Nathan Sidwell gcc/fortran/ * f95-lang.c (gfc_attribute_table): Add an "oacc function" attribute. * gfortran.h (symbol_attribute): Add an oacc_function bit-field. (gfc_oacc_routine_name): New struct; (gfc_get_oacc_routine_name): New macro. (gfc_namespace): Add oacc_routine_clauses, oacc_routine_names and oacc_routine fields. (gfc_exec_op): Add EXEC_OACC_ROUTINE. * openmp.c (OACC_ROUTINE_CLAUSES): New mask. (gfc_oacc_routine_dims): New function. (gfc_match_oacc_routine): Add support for named routines and the gang, worker vector and seq clauses. * parse.c (is_oacc): Add EXEC_OACC_ROUTINE. * resolve.c (gfc_resolve_blocks): Likewise. * st.c (gfc_free_statement): Likewise. * trans-decl.c (add_attributes_to_decl): Attach an 'oacc function' attribute and shape geometry for acc routine. 2015-11-19 Cesar Philippidis Nathan Sidwell gcc/testsuite/ * gfortran.dg/goacc/routine-3.f90: New test. * gfortran.dg/goacc/routine-4.f90: New test. * gfortran.dg/goacc/routine-5.f90: New test. * gfortran.dg/goacc/routine-6.f90: New test. 2015-11-19 James Norris Cesar Philippidis libgomp/ * libgomp.oacc-fortran/routine-5.f90: New test. * libgomp.oacc-fortran/routine-7.f90: New test. * libgomp.oacc-fortran/routine-9.f90: New test. diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c index 605c2ab..8556b70 100644 --- a/gcc/fortran/f95-lang.c +++ b/gcc/fortran/f95-lang.c @@ -93,6 +93,8 @@ static const struct attribute_spec gfc_attribute_table[] = affects_type_identity } */ { "omp declare target", 0, 0, true, false, false, gfc_handle_omp_declare_target_attribute, false }, + { "oacc function", 0, -1, true, false, false, +gfc_handle_omp_declare_target_attribute, false }, { NULL, 0, 0, false, false, false, NULL, false } }; diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index e13b4d4..3dbcd96 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -841,6 +841,9 @@ typedef struct /* Mentioned in OMP DECLARE TARGET. */ unsigned omp_declare_target:1; + /* This is an OpenACC acclerator function at level N - 1 */ + unsigned oacc_function:3; + /* Attributes set by compiler extensions (!GCC$ ATTRIBUTES). */ unsigned ext_attr:EXT_ATTR_NUM; @@ -1582,6 +1585,16 @@ gfc_dt_list; /* A list of all derived types. */ extern gfc_dt_list *gfc_derived_types; +typedef struct gfc_oacc_routine_name +{ + struct gfc_symbol *sym; + struct gfc_omp_clauses *clauses; + struct gfc_oacc_routine_name *next; +} +gfc_oacc_routine_name; + +#define gfc_get_oacc_routine_name() XCNEW (gfc_oacc_routine_name) + /* A namespace describes the contents of procedure, module, interface block or BLOCK construct. */ /* ??? Anything else use these? */ @@ -1648,6 +1661,12 @@ typedef struct gfc_namespace /* !$ACC DECLARE clauses. */ gfc_omp_clauses *oacc_declare_clauses; + /* !$ACC ROUTINE clauses. */ + gfc_omp_clauses *oacc_routine_clauses; + + /* !$ACC ROUTINE names. */ + gfc_oacc_routine_name *oacc_routine_names; + gfc_charlen *cl_list, *old_cl_list; gfc_dt_list *derived_types; @@ -1693,6 +1712,9 @@ typedef struct gfc_namespace /* Set to 1 for !$OMP DECLARE REDUCTION namespaces. */ unsigned omp_udr_ns:1; + + /* Set to 1 for !$ACC ROUTINE namespaces. */ + unsigned oacc_routine:1; } gfc_namespace; @@ -2320,7 +2342,7 @@ enum gfc_exec_op EXEC_READ, EXEC_WRITE, EXEC_IOLENGTH, EXEC_TRANSFER, EXEC_DT_END, EXEC_BACKSPACE, EXEC_ENDFILE, EXEC_INQUIRE, EXEC_REWIND, EXEC_FLUSH, EXEC_LOCK, EXEC_UNLOCK, - EXEC_OACC_KERNELS_LOOP, EXEC_OACC_PARALLEL_LOOP, + EXEC_OACC_KERNELS_LOOP, EXEC_OACC_PARALLEL_LOOP, EXEC_OACC_ROUTINE, EXEC_OACC_PARALLEL, EXEC_OACC_KERNELS,