This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [PATCH] _Cilk_for for C and C++



> -----Original Message-----
> From: Iyer, Balaji V
> Sent: Tuesday, December 3, 2013 8:26 AM
> To: Jeff Law; Jason Merrill; Aldy Hernandez
> Cc: gcc-patches@gcc.gnu.org; rth@redhat.com; Jakub Jelinek
> Subject: RE: [PATCH] _Cilk_for for C and C++
> 
> 
> 
> > -----Original Message-----
> > From: Jeff Law [mailto:law@redhat.com]
> > Sent: Tuesday, December 3, 2013 1:30 AM
> > To: Jason Merrill; Iyer, Balaji V; Aldy Hernandez
> > Cc: gcc-patches@gcc.gnu.org; rth@redhat.com; Jakub Jelinek
> > Subject: Re: [PATCH] _Cilk_for for C and C++
> >
> > On 11/27/13 17:52, Jason Merrill wrote:
> > > On 11/27/2013 04:14 PM, Iyer, Balaji V wrote:
> > >>     I completely agree with you that there are certain parts of
> > >> Cilk Plus that is similar to OMP4, namely #pragma simd and
> > >> SIMD-enabled functions (formerly called elemental functions). But,
> > >> the Cilk keywords is almost completely orthogonal to OpenMP. They
> > >> are semantically different  and one cannot be transformed to another.
> > >> Cilk uses automatically load-balanced work-stealing using the Cilk
> > >> runtime, whereas OMP uses work sharing via OMP runtime. There are a
> > >> number of other semantic differences but this is the core-issue.
> > >> #pragma simd and #pragma omp have converged in several places but
> > >> the Cilk part has always been different from OpenMP.
> > >
> > > Yes, Cilk for loops will use the Cilk runtime and OMP for loops will
> > > use the OMP runtime, but that doesn't mean they can't share a lot of
> > > the middle end code along the way.
> > >
> > > We already have several different varieties of parallel/simd loops
> > > all represented by GIMPLE_OMP_FOR, and I think this could be another
> > > GP_OMP_FOR_KIND_.
> > Right.  It's not a question of what runtime they call back into, but
> > that both share a common overall structure.
> >
> > Conceptually I look at a for loop as having 4 main components.
> >
> > Initializer, test condition, increment and the body.
> >
> > I'd like to hope things like the syntatic & semantic analysis of the
> > first three would be largely the same.  Most of the Cilk specific bits
> > would be in the handling of the body -- but there may be some
> > significant code sharing that can happen there too.
> >
> >
> > >
> > > ...
> > >> As you can tell, this is not how openmp handles a #pragma omp for
> loop.
> > >
> > > It's different in detail, but #pragma omp parallel for works very
> > > similarly: it creates a separate function for the body of the loop
> > > and then passes that to GOMP_parallel along with any shared data.
> > My thoughts exactly.
> 
> I understand you both now. Let me look into the OMP routines and see what
> it is doing and see how I can port it to _Cilk_for.
> 

Hello Jeff and Jason,
	Attached, please find a patch that will implement _Cilk_for using OMP routines. Jason, this patch only handles C but there are a lot of middle-end changes (front-end C only changes is minimal) in omp-low.c that will affect the C++ patch also.  

	It passes all the tests on my x86_64 SUSE box for -m64 and -m32 mode. Is this OK for trunk?

	The C++ patch is coming up shortly.

Here are the ChangeLog entries:

Gcc/ChangeLog
2013-12-15  Balaji V. Iyer  <balaji.v.iyer@intel.com>

        * cilk-builtins.def: Added two new builtin functions called
        __cilkrts_cilk_for_32 and __cilkrts_cilk_for_64.
        * cilk-common.c (cilk_init_builtins): Likewise.
        (cilk_declare_looper): New function.
        * cilk.h (enum cilk_tree_index): Added two new fields called
        CILK_TI_F_LOOP_32 and CILK_TI_F_LOOP_64.
        (cilk_for_32_fndecl): New #define.
        (cilk_for_64_fndecl): Likewise.
        * gimple-pretty-print.c (dump_gimple_omp_for): Added a new case for
        GF_OMP_FOR_KIND_CILKFOR.  Also emitted "_Cilk_for" instead of "for ("
        for when the gimple kind is GF_OMP_FOR_KIND_CILKFOR.
        * gimple.h (enum gf_mask): Added a new field GF_OMP_FOR_KIND_CILKFOR.
        Re-arranged couple other fields to make them all in ascending order.
        (struct gimple_omp_for_iter): Added 2 new fields: loop_count, grain.
        (gimple_statement_omp_parallel_layout): Likewise.
        (gimple_omp_for_combined_p): Added a check for combined instead of
        an logical and.
        (gimple_cilk_for_set_count): New function.
        (gimple_cilk_for_set_grain): Likewise.
        (set_cilk_for_parallel_loop_count): Likewise.
        (set_cilk_for_parallel_grain): Likewise.
        (gimple_cilk_for_parallel_get_loop_count): Likewise.
        (gimple_cilk_for_parallel_get_grain): Likewise.
        (gimple_cilk_for_induction_var): Likewise.
        (gimple_cilk_for_loop_count): Likewise.
        (gimple_cilk_for_grain): Likewise.
        * gimplify.c (cilk_for_compute_set_count_grain): Likewise.
        (gimplify_omp_for): Added code to handle gimplification of a _Cilk_for
        statement.
        * omp-low.c (struct cilk_for_information): New structure.
        (create_omp_child_function_name): Added a new bool parameter called
        is_cilk_for.  If this is set, then use a different suffix.
        (find_cilk_for_stmt): New function.
        (is_cilk_for_stmt): Likewise.
        (cilk_for_check_loop_diff_type): Likewise.
        (expand_cilk_for_call): Likewise.
        (expand_cilk_for): Likewise.
        (create_omp_child_function): Added a check to see the statment is a
        _Cilk_for.  If so, then create a child function with different
        number of parameters.
        (expand_omp_taskreg): Added code to extract the high and low parameters
        from the child function and then insert it in the appropriate location.
        Added a call to expand_cilk_for_call to insert _Cilk_for's builtin
        function call.
        (expand_omp_for): Added a check for GF_OMP_FOR_KIND_CILKFOR for the
        for statement's kind.  If so then call expand_cilk_for.
        * tree-core.h (enum omp_clause_schedule_kind): Added a new field
        OMP_CLAUSE_SCHEDULE_CILK_FOR.
        * tree.def (CILK_FOR): New tree.

Gcc/c-family/ChangeLog
2013-12-15  Balaji V. Iyer  <balaji.v.iyer@intel.com>

        * c-omp.c (c_finish_omp_for): Added a check for CILK_FOR along with
        CILK_SIMD.
        * c-common.h (enum rid): Added new value called "RID_CILK_FOR."
        * c-common.c (c_common_reswords[]): Added a new field "_Cilk_for."
        * c-pragma.c (init_pragma): Added cilk grainsize pragma.
        * c-pragma.h (enum pragma_kind): Added PRAGMA_CILK_GRAINSIZE.

Gcc/c/ChangeLog
2013-12-15  Balaji V. Iyer  <balaji.v.iyer@intel.com>

        * c-parser.c (c_parser_statement_after_labels): Added a RID_CILK_FOR
        case.
        (c_parser_pragma): Added a PRAGMA_CILK_GRAINSIZE case.
        (c_parser_omp_for_loop): Renamed the "clauses" parameter to
        "clauses_or_grain."  Added handling for _Cilk_for statements.  Set
        the grain value to the clauses location.
        (c_parser_cilk_grainsize): New function.
        (c_parser_cilk_simd): Added a new parameter called grain.  Also added
        support to parse _Cilk_for statements.

Gcc/testsuite/ChangeLog
2013-12-15  Balaji V. Iyer  <balaji.v.iyer@intel.com>

        * c-c++-common/cilk-plus/CK/cilk-fors.c: New testcase.
        * c-c++-common/cilk-plus/CK/nested_cilk_for.c: Likewise.
        * c-c++-common/cilk-plus/CK/cilk_for_grain.c: Likewise.
        * c-c++-common/cilk-plus/CK/cilk_for_grain_errors.c: Likewise.
        * c-c++-common/cilk-plus/CK/cilk_for_errors.c: Likewise.
        * c-c++-common/cilk-plus/CK/cilk_for_ptr_iter.c: Likewise.

Thanks,

Balaji V. Iyer.


Attachment: diff.txt
Description: diff.txt


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]