PIPS
computation_intensity.c
Go to the documentation of this file.
1 /*
2 
3  $Id: computation_intensity.c 23495 2018-10-24 09:19:47Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include <stdlib.h>
32 
33 #include "genC.h"
34 #include "linear.h"
35 #include "ri.h"
36 #include "effects.h"
37 #include "complexity_ri.h"
38 #include "text.h"
39 
40 #include "ri-util.h"
41 #include "effects-util.h"
42 #include "effects-generic.h"
43 #include "effects-convex.h"
44 #include "text-util.h"
45 #include "database.h"
46 #include "pipsdbm.h"
47 #include "resources.h"
48 
49 #include "properties.h"
50 
51 #include "complexity.h"
52 #include "accel-util.h"
53 
54 typedef struct {
56  int bandwidth;
57  int frequency;
58  const char *pragma;
60 
61 /* read properties to initialize cost model */
63  p->startup_overhead=get_int_property("COMPUTATION_INTENSITY_STARTUP_OVERHEAD");
64  p->bandwidth=get_int_property("COMPUTATION_INTENSITY_BANDWIDTH");
65  p->frequency=get_int_property("COMPUTATION_INTENSITY_FREQUENCY");
66  p->pragma=get_string_property("COMPUTATION_INTENSITY_PRAGMA");
67 }
68 
69 /* a loop statement is considered as compute intensive if
70  * transfer costs a re greater than execution cost
71  */
73  if(statement_loop_p(s)) {
76  /* compute instruction contribution to execution time */
77  Ppolynome instruction_time = polynome_dup(complexity_polynome(comp));
78  polynome_scalar_mult(&instruction_time,1.f/p->frequency);
79 
80  /* compute transfer contribution to execution time */
81  Ppolynome transfer_time = POLYNOME_NUL;
82  FOREACH(REGION,reg,regions) {
83  Ppolynome reg_footprint= region_enumerate(reg); // may be we should use the rectangular hull ?
84  polynome_add(&transfer_time,reg_footprint);
85  polynome_rm(&reg_footprint);
86  }
87  polynome_scalar_mult(&transfer_time,1.f/p->bandwidth);
88  polynome_scalar_add(&transfer_time,p->startup_overhead);
89 
90  /* now let's compare them, using their difference */
91  polynome_negate(&transfer_time);
92  polynome_add(&instruction_time,transfer_time);
93  polynome_rm(&transfer_time);
94  /* heuristic to check the behavior at the infinite:
95  * assumes all variables are positives,
96  * take the higher degree monomial
97  * and decide upon its coefficient
98  */
99  int max_degree = polynome_max_degree(instruction_time);
100  float coeff=-1.f;
101  for(Ppolynome p = instruction_time; !POLYNOME_NUL_P(p); p = polynome_succ(p)) {
102  int curr_degree = (int)vect_sum(monome_term(polynome_monome(p)));
103  if(curr_degree == max_degree) {
104  coeff = monome_coeff(polynome_monome(p));
105  break;
106  }
107  }
108  polynome_rm(&instruction_time);
109  /* seems a computation intensive loop ! */
110  if(coeff> 0) {
112  return false;
113  }
114  }
115  return true;
116 }
117 
118 /* mark all loops (do / for /while) that have sufficient computation intensity
119  * with a pragma, suitable for treatment by other phases.
120  * The computation intensity is derived from the complexity and the memory footprint.
121  * It assumes the cost model: execution_time = startup_overhead + memory_footprint / bandwidth + complexity / frequency
122  */
124  /* init stuff */
129 
132 
133  /* do it now ! */
136 
137  /* validate changes */
139 
140  /* reset */
145 
146  return true;
147 }
int get_int_property(const string)
void const char const char const int
Ppolynome complexity_polynome(complexity comp)
Because complexity is composed of two elements, we use this function to get the first element : polyn...
Definition: comp_math.c:506
complexity load_statement_complexity(statement)
void reset_complexity_map(void)
void set_complexity_map(statement_mapping)
bool computation_intensity(const char *module_name)
mark all loops (do / for /while) that have sufficient computation intensity with a pragma,...
static void init_computation_intensity_param(computation_intensity_param *p)
read properties to initialize cost model
static bool do_computation_intensity(statement s, computation_intensity_param *p)
a loop statement is considered as compute intensive if transfer costs a re greater than execution cos...
#define REGION
Ppolynome region_enumerate(effect)
void set_cumulated_rw_effects(statement_effects)
list load_cumulated_rw_effects_list(statement)
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
char * get_string_property(const char *)
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
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
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758
#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
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 statement_loop_p(statement)
Definition: statement.c:349
Value vect_sum(Pvecteur v)
Value vect_sum(Pvecteur v): somme des coefficients d'un vecteur (i.e.
Definition: reductions.c:261
Ppolynome polynome_dup(Ppolynome pp)
Ppolynome polynome_dup(Ppolynome pp) creates and returns a copy of pp.
Definition: pnome-alloc.c:211
void polynome_rm(Ppolynome *ppp)
void polynome_rm(Ppolynome* ppp) frees space occupied by polynomial *ppp returns *ppp pointing to POL...
Definition: pnome-alloc.c:170
void polynome_add(Ppolynome *ppp, Ppolynome pp2)
void polynome_add(Ppolynome* ppp, Ppolynome pp2) (*ppp) = (*ppp) + pp2.
Definition: pnome-bin.c:171
int polynome_max_degree(Ppolynome pp)
int polynome_max_degree(Ppolynome pp) returns the degree of polynomial pp Let's hope there aren't too...
Definition: pnome-reduc.c:113
void polynome_scalar_add(Ppolynome *ppp, float term)
void polynome_scalar_add(Ppolynome* ppp, float term) (*ppp) = (*ppp) + term !usage: polynome_scalar_a...
Definition: pnome-scal.c:86
void polynome_scalar_mult(Ppolynome *ppp, float factor)
void polynome_scalar_mult(Ppolynome* ppp, float factor) (*ppp) = factor * (*ppp) !...
Definition: pnome-scal.c:46
void polynome_negate(Ppolynome *ppp)
void polynome_negate(Ppolynome *ppp); changes sign of polynomial *ppp.
Definition: pnome-unaires.c:45
#define POLYNOME_NUL
#define monome_term(pm)
#define polynome_monome(pp)
#define monome_coeff(pm)
Macros definitions.
#define POLYNOME_NUL_P(pp)
#define polynome_succ(pp)
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
void add_pragma_str_to_statement(statement st, const char *s, bool copy_flag)
Add a string as a pragma to a statement.
Definition: pragma.c:425
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
The structure used to build lists in NewGen.
Definition: newgen_list.h:41