PIPS
localize_memory.c
Go to the documentation of this file.
1 /*
2 
3  THIS FILE IS NOT COMPILED
4 
5  A simple phase that outline parallel loops onto GPU
6 
7  Ronan.Keryell@hpc-project.com
8 */
9 #ifdef HAVE_CONFIG_H
10  #include "pips_config.h"
11 #endif
12 
13 #include "genC.h"
14 #include "linear.h"
15 #include "ri.h"
16 #include "effects.h"
17 #include "ri-util.h"
18 #include "effects-util.h"
19 #include "misc.h"
20 #include "effects-generic.h"
21 #include "effects-simple.h"
22 #include "control.h"
23 #include "callgraph.h"
24 #include "pipsdbm.h"
25 #include "resources.h"
26 
27 /** Store the loop nests found that meet the spec to be executed on a
28  GPU. Use a list and not a set or hash_map to have always the same
29  order */
31 
32 
33 static bool
35  /* An interesting loop must be parallel first...
36 
37  We recurse on statements instead of loops in order to pick
38  informations on the statement itself, such as pragmas
39  */
40  int parallel_loop_nest_depth = depth_of_parallel_perfect_loop_nest(s);
41  ifdebug(3) {
42  pips_debug(1, "Statement %td with // depth %d\n", statement_number(s),
43  parallel_loop_nest_depth);
44  print_statement(s);
45  }
46  if (parallel_loop_nest_depth > 0) {
47  // Register the loop-nest (note the list is in the reverse order):
49  /* Since we only outline outermost loop-nest, stop digging further in
50  this statement: */
51  pips_debug(1, "Statement %td marked to be outlined\n", statement_number(s));
52  return false;
53  }
54  // This statement is not a parallel loop, go on digging:
55  return true;
56 }
57 
58 
59 static void
61  ifdebug(1) {
62  pips_debug(1, "Parallel loop-nest of depth %d\n", depth);
63  print_statement(s);
64  }
65  /* First outline the innermost code (the kernel itself) to avoid
66  spoiling its memory effects if we start with the outermost code
67  first: */
68  list sk = CONS(STATEMENT,
70  NIL);
71  outliner(build_new_top_level_module_name("kernel_wrapper",false), sk);
72 
73  // Outline the kernel launcher:
74  list sl = CONS(STATEMENT, s, NIL);
75  outliner(build_new_top_level_module_name("kernel_launcher",false), sl);
76 }
77 
78 
79 bool old__gpu_ify(const string module_name) {
80  // Use this module name and this environment variable to set
82  "GPU_IFY_DEBUG_LEVEL");
83 
84  // Get the effects and use them:
86 
87  // Initialize the loop nest set to outline to the empty set yet:
89 
90  // Mark interesting loops:
93 
94  /* Outline the previous marked loop nests.
95  First put the statements to outline in the good order: */
98  // We could have stored the depth, but it complexify the code...
100  }
101 
103 
104  // No longer use effects:
106 
107  // We may have outline some code, so recompute the callees:
108  DB_PUT_MEMORY_RESOURCE(DBR_CALLEES, module_name,
110 
111  // Put back the new statement module
113 }
statement outliner(const char *, list)
outline the statements in statements_to_outline into a module named outline_module_name the outlined ...
Definition: outlining.c:1327
static statement module_statement
Definition: alias_check.c:125
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
void set_cumulated_rw_effects(statement_effects)
void reset_cumulated_rw_effects(void)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
void * gen_identity(const void *x)
Just return the argument.
Definition: genClib.c:2807
statement perfectly_nested_loop_to_body_at_depth(statement s, int depth)
Extract the loop-body of a perfect loop-nest at a given depth.
Definition: loop.c:646
int depth_of_parallel_perfect_loop_nest(statement s)
Compute the depth of a parallel perfect loop-nest.
Definition: loop.c:436
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
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#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
#define PIPS_PHASE_POSTLUDE(new_module_statement)
End a transformation phase by putting back into PIPS the (possibly) modified statement.
#define PIPS_PHASE_PRELUDE(module_name, debug_env_var)
Start a phase that use a module CODE.
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
bool old__gpu_ify(const string module_name)
static void gpu_ify_statement(statement s, int depth)
list loop_nests_to_outline
Store the loop nests found that meet the spec to be executed on a GPU.
static bool mark_loop_to_outline(const statement s)
#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
string build_new_top_level_module_name(const char *prefix, bool prevent_suffix)
Get a new name for a module built from a prefix.
Definition: module.c:55
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define statement_number(x)
Definition: ri.h:2452
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
#define ifdebug(n)
Definition: sg.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
static int depth
la sequence de nids