PIPS
cost_model.c File Reference
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "boolean.h"
#include <stdbool.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "database.h"
#include "misc.h"
#include "text.h"
#include "text-util.h"
#include "ri-util.h"
#include "effects-util.h"
#include "accel-util.h"
#include "effects-generic.h"
#include "effects-simple.h"
#include "pipsdbm.h"
#include "resources.h"
#include "control.h"
#include "c_syntax.h"
#include "conversion.h"
#include "properties.h"
#include "transformations.h"
#include "effects-convex.h"
#include "complexity_ri.h"
#include "complexity.h"
#include <time.h>
#include "dg.h"
#include "graph.h"
#include "ricedg.h"
#include "chains.h"
#include "task_parallelization.h"
+ Include dependency graph for cost_model.c:

Go to the source code of this file.

Typedefs

typedef dg_arc_label arc_label
 Instantiation of the dependence graph: More...
 
typedef dg_vertex_label vertex_label
 

Functions

bool costly_task (statement st)
 cost_model.c More...
 
double polynomial_to_numerical (Ppolynome poly_amount)
 
double size_of_regions (list l_data)
 
static list used_data (statement(st))
 
static double task_time (statement s)
 
double edge_cost (statement s1, statement s2)
 
double t_level (vertex v, graph dg, gen_array_t annotations)
 First parameter is the top level (earliest start time) for each node. More...
 
void top_level (graph dg, gen_array_t annotations)
 
void bottom_level (graph dg, gen_array_t annotations)
 Second parameter is the bottom level (latest start time) for each node. More...
 
void priorities (gen_array_t annotations)
 
void initialization (graph dg, gen_array_t annotations)
 
void parse_instrumented_file (char *file_name, graph dg, gen_array_t annotations)
 

Typedef Documentation

◆ arc_label

Instantiation of the dependence graph:

Definition at line 44 of file cost_model.c.

◆ vertex_label

Definition at line 45 of file cost_model.c.

Function Documentation

◆ bottom_level()

void bottom_level ( graph  dg,
gen_array_t  annotations 
)

Second parameter is the bottom level (latest start time) for each node.

Parameters
dgg
annotationsnnotations

Definition at line 223 of file cost_model.c.

224 {
225  double max, level;
226  list vertices = (graph_vertices(dg));
227  annotation *an, *anp;
228  FOREACH(VERTEX, v, vertices) {
229  max = 0;
231  FOREACH(VERTEX, pre, (graph_vertices(dg))) {
232  statement parent = vertex_to_statement(pre);
233  anp = gen_array_item(annotations, (int)statement_ordering(parent));
234  FOREACH(SUCCESSOR, su, (vertex_successors(pre))) {
235  vertex s = successor_vertex(su);
236  statement child = vertex_to_statement(s);
237  if(statement_equal_p(child, sv) && gen_array_item(annotations, (int)statement_ordering(parent)) )
238  {
239  double edge_c = *(double *)(gen_array_item(anp->edge_cost,statement_ordering(sv)));
240  level = anp->blevel + edge_c;
241  if(level > max)
242  max = level;
243  }
244  }
245  }
247  an->blevel = an->task_time + max;
249  }
250  return;
251 }
gen_array_t annotations
Global variables.
Definition: SDG.c:62
void gen_array_addto(gen_array_t a, size_t i, void *what)
Definition: array.c:87
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
static graph dg
dg is the dependency graph ; FIXME : should not be static global ?
Definition: chains.c:124
#define max(a, b)
#define successor_vertex(x)
Definition: graph.h:118
#define vertex_successors(x)
Definition: graph.h:154
#define SUCCESSOR(x)
SUCCESSOR.
Definition: graph.h:86
#define graph_vertices(x)
Definition: graph.h:82
#define VERTEX(x)
VERTEX.
Definition: graph.h:122
#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
statement vertex_to_statement(vertex v)
Vertex_to_statement looks for the statement that is pointed to by vertex v.
Definition: util.c:45
static bool statement_equal_p(statement s1, statement s2)
Definition: unstructured.c:55
#define statement_ordering(x)
Definition: ri.h:2454
#define level
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References annotations, annotation::blevel, dg, annotation::edge_cost, FOREACH, gen_array_addto(), gen_array_item(), graph_vertices, level, max, statement_equal_p(), statement_ordering, SUCCESSOR, successor_vertex, annotation::task_time, VERTEX, vertex_successors, and vertex_to_statement().

Referenced by BDSC(), and DSC().

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

◆ costly_task()

bool costly_task ( statement  st)

cost_model.c

Parameters
stt

Definition at line 52 of file cost_model.c.

52  {
53  bool costly_p = false;
56  return true;
57  else{
58  switch(instruction_tag(inst)){
60  MAPL( stmt_ptr,
61  {
62  statement local_stmt = STATEMENT(CAR(stmt_ptr ));
63  costly_p = costly_p || costly_task(local_stmt);
64  },
65  instruction_block(inst));
66  return costly_p;
67  break;
68  }
69  case is_instruction_test :{
70  test t = instruction_test(inst);
71  return costly_task(test_true(t)) ||
73  break;
74  }
75  case is_instruction_loop :{
76  return true;
77  }
79  return true;
80  }
82  return true;
83  }
84  case is_instruction_call:{
85  return user_call_p(statement_call(st));
86  }
87  default:
88  return false;
89  }
90  }
91 }
bool costly_task(statement st)
cost_model.c
Definition: cost_model.c:52
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
call statement_call(statement)
Get the call of a statement.
Definition: statement.c:1406
bool statement_contains_user_call_p(statement)
Definition: statement.c:3939
#define is_instruction_block
soft block->sequence transition
#define instruction_block(i)
bool user_call_p(call c)
Test if a call is a user call.
Definition: expression.c:4361
#define test_false(x)
Definition: ri.h:2837
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_forloop
Definition: ri.h:1477
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define test_true(x)
Definition: ri.h:2835
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_test(x)
Definition: ri.h:1517
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References CAR, instruction_block, instruction_tag, instruction_test, is_instruction_block, is_instruction_call, is_instruction_forloop, is_instruction_loop, is_instruction_test, is_instruction_whileloop, MAPL, STATEMENT, statement_call(), statement_contains_user_call_p(), statement_instruction, test_false, test_true, and user_call_p().

Referenced by cluster_stage_spire(), cluster_stage_spire_generation(), hierarchical_schedule(), and hierarchical_schedule_step().

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

◆ edge_cost()

double edge_cost ( statement  s1,
statement  s2 
)
Parameters
s11
s22

Definition at line 147 of file cost_model.c.

148 {
149  Ppolynome transfer_time = POLYNOME_NUL;
152  list l_communications = RegionsIntersection(regions_dup(l_write), regions_dup(l_read), w_r_combinable_p);
153  FOREACH(REGION,reg,l_communications){
154  Ppolynome reg_footprint = region_enumerate(reg);
155  //reg_footprint = polynome_mult(reg_footprint, expression_to_polynome(int_to_expression(SizeOfElements(variable_basic(type_variable(entity_type(region_entity(reg))))))));
156  //reg_footprint =
157  //polynome_mult(reg_footprint,expression_to_polynome(int_to_expression(2.5)));//\beta= 2.5 on Cmmcluster
158  polynome_add(&transfer_time, reg_footprint);
159  }
160  //polynome_add(&transfer_time, latency);// the latency \alpha = 15000 on Cmmcluster
161  //polynome_fprint(stderr,transfer_time,entity_local_name,default_is_inferior_var);
162  return polynomial_to_numerical(transfer_time);
163 }
double polynomial_to_numerical(Ppolynome poly_amount)
Definition: cost_model.c:93
#define REGION
list RegionsIntersection(list l1, list l2, bool(*intersection_combinable_p)(effect, effect))
list RegionsIntersection(list l1,l2, bool (*intersection_combinable_p)(effect, effect)) input : outpu...
list regions_write_regions(list)
list regions_read_regions(list)
list regions_dup(list)
Ppolynome region_enumerate(effect)
bool w_r_combinable_p(effect, effect)
list load_statement_local_regions(statement)
void polynome_add(Ppolynome *ppp, Ppolynome pp2)
void polynome_add(Ppolynome* ppp, Ppolynome pp2) (*ppp) = (*ppp) + pp2.
Definition: pnome-bin.c:171
#define POLYNOME_NUL
s1
Definition: set.c:247

References FOREACH, load_statement_local_regions(), polynome_add(), POLYNOME_NUL, polynomial_to_numerical(), REGION, region_enumerate(), regions_dup(), regions_read_regions(), regions_write_regions(), RegionsIntersection(), s1, and w_r_combinable_p().

Referenced by initialization().

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

◆ initialization()

void initialization ( graph  dg,
gen_array_t  annotations 
)
Parameters
dgg
annotationsnnotations

Definition at line 267 of file cost_model.c.

268 {
269  list vertices = graph_vertices(dg);
270  int sigma = get_int_property("BDSC_SENSITIVITY");
271  float clock = 1, overhead = 0;
272  srand(time(NULL));
273  FOREACH(VERTEX, v, vertices){
275  annotation *item = (annotation *)malloc(sizeof(annotation));
276  float x = (float)((float)rand()/((float)RAND_MAX) * (float)sigma/100);
277  item->task_time = clock * task_time(stmt) * (1 + x ) + overhead;
279  FOREACH(SUCCESSOR, su, (vertex_successors(v))){//statement_to_vertex(stmt, dg)))) {
280  vertex s = successor_vertex(su);
281  statement child = vertex_to_statement(s);
282  double *ec = (double *)malloc(sizeof(double));
283  *ec = clock * edge_cost(stmt, child) * (1+((float)rand()/(float)RAND_MAX * sigma/100)) + overhead;
284  gen_array_addto(item->edge_cost, statement_ordering(child), ec);
285  }
286  item->scheduled = false;
287  item->order_sched = -1;
288  item->cluster = -1;
289  item->nbclusters = 0;
290  item->data = used_data(stmt);
292  }
293  return;
294 }
int get_int_property(const string)
gen_array_t gen_array_make(size_t size)
declarations...
Definition: array.c:40
static list used_data(statement(st))
Definition: cost_model.c:126
static double task_time(statement s)
Definition: cost_model.c:134
double edge_cost(statement s1, statement s2)
Definition: cost_model.c:147
void * malloc(YYSIZE_T)
size_t gen_length(const list l)
Definition: list.c:150
static char * x
Definition: split_file.c:159
Definition: statement.c:54

References annotations, annotation::cluster, annotation::data, dg, edge_cost(), annotation::edge_cost, FOREACH, gen_array_addto(), gen_array_make(), gen_length(), get_int_property(), graph_vertices, malloc(), annotation::nbclusters, annotation::order_sched, annotation::scheduled, statement_ordering, SUCCESSOR, successor_vertex, task_time(), annotation::task_time, used_data(), VERTEX, vertex_successors, vertex_to_statement(), and x.

Referenced by dsc_code_parallelization(), hbdsc_parallelization(), and make_unstructured_from_loop().

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

◆ parse_instrumented_file()

void parse_instrumented_file ( char *  file_name,
graph  dg,
gen_array_t  annotations 
)
Parameters
file_nameile_name
dgg
annotationsnnotations

Definition at line 296 of file cost_model.c.

297 {
298  FILE *finstrumented;
299  double cost;
300  int ordering, ordering2;
301  finstrumented = fopen(file_name,"r");
302  list vertices = graph_vertices(dg);
303  annotation *item;
304  FOREACH(VERTEX, v, vertices){
306  item = (annotation *)malloc(sizeof(annotation));
307  item->edge_cost = gen_array_make(0);
309  vertex s = successor_vertex(su);
310  statement child = vertex_to_statement(s);
311  double *ec = (double *)malloc(sizeof(double));
312  *ec = 0;
313  gen_array_addto(item->edge_cost, statement_ordering(child), ec);
314  }
316  }
317  while (!feof(finstrumented) && (fscanf(finstrumented,"%d->%d = %lf \n", &ordering,&ordering2, &cost)))
318  {
319  if(ordering2 == -1){
320  item = gen_array_item(annotations, ordering);
321  item->task_time = (double)cost;
322  if(item->edge_cost == NULL)
323  item->edge_cost = gen_array_make(0);
324  gen_array_addto(annotations, ordering, item);
325  }
326  else {
327  item = gen_array_item(annotations, ordering);
328  if(item->edge_cost == NULL)
329  item->edge_cost = gen_array_make(0);
330  double *ec = (double *)malloc(sizeof(double));
331  *ec = cost;
332  gen_array_addto(item->edge_cost, ordering2, ec);
333  gen_array_addto(annotations, ordering, item);
334  }
335 
336  }
337  fclose(finstrumented);
338  return;
339 }
static vertex statement_to_vertex(statement s, graph g)
Definition: impact_check.c:227
static string file_name

References annotations, dg, annotation::edge_cost, file_name, FOREACH, gen_array_addto(), gen_array_item(), gen_array_make(), graph_vertices, malloc(), statement_ordering, statement_to_vertex(), SUCCESSOR, successor_vertex, annotation::task_time, VERTEX, vertex_successors, and vertex_to_statement().

Referenced by dsc_code_parallelization(), and hbdsc_parallelization().

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

◆ polynomial_to_numerical()

double polynomial_to_numerical ( Ppolynome  poly_amount)

if polynomial is not a constant monomial, we use
an heuristic to map it into a numerical constant take the higher degree monomial and decide upon its coefficient

Parameters
poly_amountoly_amount

Definition at line 93 of file cost_model.c.

94 {
95  double size = 0.f;
96  /* if polynomial is not a constant monomial, we use
97  * an heuristic to map it into a numerical constant
98  * take the higher degree monomial
99  * and decide upon its coefficient
100  */
101  if(!POLYNOME_UNDEFINED_P(poly_amount))
102  {
103  int max_degree = polynome_max_degree(poly_amount);
104  for(Ppolynome p = poly_amount; !POLYNOME_NUL_P(p); p = polynome_succ(p)) {
105  int curr_degree = (int)vect_sum(monome_term(polynome_monome(p)));
106  if(curr_degree == max_degree) {
107  size = monome_coeff(polynome_monome(p));
108  break;
109  }
110  }
111  }
112  return size;
113 }
void const char const char const int
Value vect_sum(Pvecteur v)
Value vect_sum(Pvecteur v): somme des coefficients d'un vecteur (i.e.
Definition: reductions.c:261
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
#define POLYNOME_UNDEFINED_P(pp)
#define monome_term(pm)
#define polynome_monome(pp)
#define monome_coeff(pm)
Macros definitions.
#define POLYNOME_NUL_P(pp)
#define polynome_succ(pp)

References int, monome_coeff, monome_term, polynome_max_degree(), polynome_monome, POLYNOME_NUL_P, polynome_succ, POLYNOME_UNDEFINED_P, and vect_sum().

Referenced by edge_cost(), size_of_regions(), and task_time().

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

◆ priorities()

void priorities ( gen_array_t  annotations)
Parameters
annotationsnnotations

Definition at line 253 of file cost_model.c.

254 {
255  size_t i;
256  for(i = 0; i< gen_array_nitems(annotations); i++){
257  if(gen_array_item(annotations, i) != NULL){
259  item->prio = item->tlevel + item->blevel;
260  gen_array_addto(annotations, i, item);
261  }
262  }
263  return;
264 }
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131

References annotations, annotation::blevel, gen_array_addto(), gen_array_item(), gen_array_nitems(), annotation::prio, and annotation::tlevel.

Referenced by BDSC(), and DSC().

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

◆ size_of_regions()

double size_of_regions ( list  l_data)
Parameters
l_data_data

Definition at line 115 of file cost_model.c.

116 {
117  Ppolynome transfer_time = POLYNOME_NUL;
118  FOREACH(REGION,reg,l_data){
119  Ppolynome reg_footprint= region_enumerate(reg);
121  polynome_add(&transfer_time, reg_footprint);
122  }
123  return polynomial_to_numerical(transfer_time);
124 }
#define region_entity(reg)
Ppolynome polynome_mult(Ppolynome pp1, Ppolynome pp2)
Ppolynome polynome_mult(Ppolynome pp1, Ppolynome pp2) returns pp1 * pp2.
Definition: pnome-bin.c:287
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
Ppolynome expression_to_polynome(expression exp)
===========================================================================
Definition: expression.c:3650
_int SizeOfElements(basic)
This function returns the length in bytes of the Fortran or C type represented by a basic,...
Definition: size.c:297
#define type_variable(x)
Definition: ri.h:2949
#define entity_type(x)
Definition: ri.h:2792
#define variable_basic(x)
Definition: ri.h:3120

References entity_type, expression_to_polynome(), FOREACH, int_to_expression(), polynome_add(), polynome_mult(), POLYNOME_NUL, polynomial_to_numerical(), REGION, region_entity, region_enumerate(), SizeOfElements(), type_variable, and variable_basic.

Referenced by MCW(), and transfer_cost().

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

◆ t_level()

double t_level ( vertex  v,
graph  dg,
gen_array_t  annotations 
)

First parameter is the top level (earliest start time) for each node.

intptr_t)

Parameters
dgg
annotationsnnotations

Definition at line 168 of file cost_model.c.

169 {
170  double max = 0, level;
171  list vertices = (graph_vertices(dg));
172  annotation *an,*anp;
174  FOREACH(VERTEX, pre, vertices) {
175  statement parent = vertex_to_statement(pre);
176  FOREACH(SUCCESSOR, su, (vertex_successors(pre))) {
177  vertex s = successor_vertex(su);
178  statement child = vertex_to_statement(s);
179  if(statement_equal_p(child, sv) && !statement_equal_p(child,parent) && gen_array_item(annotations, (int)statement_ordering(parent))){
180  double tl_p;
181  anp = gen_array_item(annotations, (int)statement_ordering(parent));
182  double edge_c = *(double *)/*(intptr_t)*/(gen_array_item(anp->edge_cost, statement_ordering(sv)));
183  if(anp->tlevel != -1)
184  tl_p = anp->tlevel;
185  else
186  tl_p = t_level(pre, dg, annotations);
187  level = tl_p + anp->task_time + edge_c ;
188  if(level > max)
189  max = level;
190  }
191  else {
192  if(statement_equal_p(child, sv) && !statement_equal_p(child,parent) && gen_array_item(annotations, (int)statement_ordering(parent))==NULL )
193  {
194  anp = gen_array_item(annotations, (int)statement_ordering(parent));
195  double edge_c = *(double *)(gen_array_item(anp->edge_cost,statement_ordering(sv)));
196  level = t_level(pre, dg, annotations) + anp->task_time + edge_c;
197  if(level > max)
198  max = level;
199  }
200  }
201  }
202  }
205  else
206  an = (annotation *)malloc(sizeof(annotation));
207  an->tlevel = max;
209  return max;
210 }
size_t gen_array_size(const gen_array_t a)
Definition: array.c:137
double t_level(vertex v, graph dg, gen_array_t annotations)
First parameter is the top level (earliest start time) for each node.
Definition: cost_model.c:168

References annotations, dg, annotation::edge_cost, FOREACH, gen_array_addto(), gen_array_item(), gen_array_size(), graph_vertices, level, malloc(), max, statement_equal_p(), statement_ordering, SUCCESSOR, successor_vertex, annotation::task_time, annotation::tlevel, VERTEX, vertex_successors, and vertex_to_statement().

Referenced by top_level(), and update_priority_values().

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

◆ task_time()

static double task_time ( statement  s)
static

Definition at line 134 of file cost_model.c.

135 {
136  complexity stat_comp = load_statement_complexity(s);
137  Ppolynome poly = complexity_polynome(stat_comp);
138  return polynomial_to_numerical(poly);
139 }
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)

References complexity_polynome(), load_statement_complexity(), and polynomial_to_numerical().

Referenced by hierarchical_schedule_step(), and initialization().

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

◆ top_level()

void top_level ( graph  dg,
gen_array_t  annotations 
)
Parameters
dgg
annotationsnnotations

Definition at line 211 of file cost_model.c.

212 {
213  list vertices = graph_vertices(dg);
214  FOREACH(VERTEX, v, vertices){
215  t_level(v, dg, annotations);
216  }
217  return;
218 }

References annotations, dg, FOREACH, graph_vertices, t_level(), and VERTEX.

Referenced by BDSC(), and DSC().

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

◆ used_data()

static list used_data ( statement(st)  )
static

Definition at line 126 of file cost_model.c.

126  {
127  list l_data = NIL;
130  l_data = RegionsMustUnion(regions_dup(l_read), regions_dup(l_write), r_w_combinable_p);
131  return l_data;
132 }
list RegionsMustUnion(list l1, list l2, bool(*union_combinable_p)(effect, effect))
list RegionsMustUnion(list l1, list l2, union_combinable_p) input : two lists of regions output : a l...
bool r_w_combinable_p(effect, effect)
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47

References load_statement_local_regions(), NIL, r_w_combinable_p(), regions_dup(), regions_read_regions(), regions_write_regions(), and RegionsMustUnion().

Referenced by initialization().

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