PIPS
gpu_promote_sequential.c File Reference

Avoid useless data transfert by promoting sequential code on GPU. More...

#include <ctype.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "kernel_memory_mapping.h"
#include "effects.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "semantics.h"
#include "effects-util.h"
#include "text.h"
#include "pipsdbm.h"
#include "resources.h"
#include "properties.h"
#include "misc.h"
#include "control.h"
#include "callgraph.h"
#include "effects-generic.h"
#include "effects-simple.h"
#include "effects-convex.h"
#include "text-util.h"
#include "parser_private.h"
#include "preprocessor.h"
#include "transformer.h"
#include "accel-util.h"
+ Include dependency graph for gpu_promote_sequential.c:

Go to the source code of this file.

Functions

static statement promote_statement (list promoted_stmts, loop l)
 
void gpu_promote_sequential_on_sequence (sequence seq, loop l)
 Operate on a sequence and promote all sequential code in a trivial parallel loop. More...
 
static bool gpu_promote_sequential_walker_in (loop l)
 
void gpu_promote_sequential_on_statement (statement s)
 
bool gpu_promote_sequential (const char *module_name)
 

Detailed Description

Avoid useless data transfert by promoting sequential code on GPU.

Author
Mehdi Amini mehdi.nosp@m..ami.nosp@m.ni@hp.nosp@m.c-pr.nosp@m.oject.nosp@m..com

Definition in file gpu_promote_sequential.c.

Function Documentation

◆ gpu_promote_sequential()

bool gpu_promote_sequential ( const char *  module_name)

Initialize set for each statement

Parameters
module_nameodule_name

Definition at line 143 of file gpu_promote_sequential.c.

143  {
144  statement module_stat = (statement)db_get_memory_resource(DBR_CODE,
145  module_name,
146  true);
147  set_current_module_statement(module_stat);
149 
150  debug_on("GPU_PROMOTE_SEQUENTIAL_DEBUG_LEVEL");
151 
152  /* Initialize set for each statement */
154 
155  debug_off();
156 
157  module_reorder(module_stat);
158 
159  DB_PUT_MEMORY_RESOURCE(DBR_CODE,
160  module_name,
161  module_stat);
162 
163 
166 
167  return true;
168 
169 
170 
171 }
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
void gpu_promote_sequential_on_statement(statement s)
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
Definition: entity.c:1450

References db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, gpu_promote_sequential_on_statement(), local_name_to_top_level_entity(), module_name(), module_reorder(), reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), and set_current_module_statement().

+ Here is the call graph for this function:

◆ gpu_promote_sequential_on_sequence()

void gpu_promote_sequential_on_sequence ( sequence  seq,
loop  l 
)

Operate on a sequence and promote all sequential code in a trivial parallel loop.

gpu_promote_sequential.c

The heuristic that trigger the promotion is quite simple at that time, all sequential code is promoted if a parallel loop is present in the sequence

Parameters
seqis the sequence on which to operate @loop l is an optionnal param that give the enclosing loop
Parameters
seqeq

Definition at line 83 of file gpu_promote_sequential.c.

83  {
84  list stmts = sequence_statements(seq);
85 
86  // Try to find a parallel loop in the sequence
87  bool found_parallel_loop_p = false;
88  FOREACH(statement,s,stmts) {
90  found_parallel_loop_p = true;
91  break;
92  }
93  }
94 
95  if(found_parallel_loop_p) {
96  list new_stmts = NIL;
97  list promoted_stmts = NIL;
98  FOREACH(statement,s,stmts) {
101  ifdebug(2) {
102  pips_debug(2,"Promote statement :");
103  print_statement(s);
104  }
105 
106  promoted_stmts = CONS(statement,s,promoted_stmts);
107  }
108  } else if(promoted_stmts) {
109  promoted_stmts = gen_nreverse(promoted_stmts);
110  statement promoted = promote_statement(promoted_stmts, l);
111  new_stmts = CONS(statement,promoted,CONS(statement,s,new_stmts));
112  promoted_stmts = NIL;
113 
114  ifdebug(2) {
115  pips_debug(2,"Promote statements in loop :");
116  print_statement(promoted);
117  }
118  }
119  }
120  if(promoted_stmts) {
121  promoted_stmts = gen_nreverse(promoted_stmts);
122  statement promoted = promote_statement(promoted_stmts, l);
123  new_stmts = CONS(statement,promoted,new_stmts);
124  }
125  sequence_statements(seq) = gen_nreverse(new_stmts); // FIXME Free old sequence
126  }
127 }
static statement promote_statement(list promoted_stmts, loop l)
bool parallel_loop_statement_p(statement s)
Test if a statement is a parallel loop.
Definition: loop.c:420
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
bool empty_statement_or_continue_p(statement)
Return true if the statement is an empty instruction block or a continue or a recursive combination o...
Definition: statement.c:474
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
#define sequence_statements(x)
Definition: ri.h:2360
#define ifdebug(n)
Definition: sg.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CONS, empty_statement_or_continue_p(), FOREACH, gen_nreverse(), ifdebug, NIL, parallel_loop_statement_p(), pips_debug, print_statement(), promote_statement(), and sequence_statements.

Referenced by gpu_promote_sequential_walker_in().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gpu_promote_sequential_on_statement()

void gpu_promote_sequential_on_statement ( statement  s)

Definition at line 139 of file gpu_promote_sequential.c.

139  {
141 }
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
static bool gpu_promote_sequential_walker_in(loop l)
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752
#define loop_domain
newgen_language_domain_defined
Definition: ri.h:218

References gen_null(), gen_recurse, gpu_promote_sequential_walker_in(), and loop_domain.

Referenced by gpu_promote_sequential().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gpu_promote_sequential_walker_in()

static bool gpu_promote_sequential_walker_in ( loop  l)
static

Definition at line 129 of file gpu_promote_sequential.c.

129  {
130  if(loop_sequential_p(l)) {
131  statement body = loop_body(l);
132  if(statement_sequence_p(body)) {
134  }
135  }
136  return true;
137 }
void gpu_promote_sequential_on_sequence(sequence seq, loop l)
Operate on a sequence and promote all sequential code in a trivial parallel loop.
bool loop_sequential_p(loop l)
Test if a loop is sequential.
Definition: loop.c:404
sequence statement_sequence(statement)
Get the sequence of a statement sequence.
Definition: statement.c:1328
bool statement_sequence_p(statement)
Statement classes induced from instruction type.
Definition: statement.c:335
#define loop_body(x)
Definition: ri.h:1644

References gpu_promote_sequential_on_sequence(), loop_body, loop_sequential_p(), statement_sequence(), and statement_sequence_p().

Referenced by gpu_promote_sequential_on_statement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ promote_statement()

static statement promote_statement ( list  promoted_stmts,
loop  l 
)
static

Definition at line 59 of file gpu_promote_sequential.c.

59  {
60  promoted_stmts = gen_nreverse(promoted_stmts);
62  make_basic(is_basic_int, (void *) 4));
63  statement promoted = make_new_loop_statement(loop_idx,
67  make_block_statement(promoted_stmts),
69  if(!loop_undefined_p(l)) {
70  loop_locals(l) = CONS(entity,loop_idx,loop_locals(l));
71  }
72  return promoted;
73 }
basic make_basic(enum basic_utype tag, void *val)
Definition: ri.c:155
execution make_execution_parallel(void)
Definition: ri.c:844
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
statement make_new_loop_statement(entity i, expression low, expression up, expression inc, statement b, execution e)
This is an ad'hoc function designed for do_loop_unroll_with_epilogue().
Definition: loop.c:839
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
entity make_new_scalar_variable(entity, basic)
Definition: variable.c:741
@ is_basic_int
Definition: ri.h:571
#define loop_undefined_p(x)
Definition: ri.h:1613
#define loop_locals(x)
Definition: ri.h:1650

References CONS, gen_nreverse(), get_current_module_entity(), int_to_expression(), is_basic_int, loop_locals, loop_undefined_p, make_basic(), make_block_statement(), make_execution_parallel(), make_new_loop_statement(), and make_new_scalar_variable().

Referenced by gpu_promote_sequential_on_sequence().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: