Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bondhugula/pluto
Browse files Browse the repository at this point in the history
  • Loading branch information
bondhugula committed Jul 29, 2019
2 parents 2ecc1a8 + ddba52b commit 6118e7f
Show file tree
Hide file tree
Showing 23 changed files with 1,965 additions and 1,360 deletions.
4 changes: 4 additions & 0 deletions include/pluto/pluto.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ struct plutoOptions {
* one dimension. */
int diamondtile;

/* Use per connected component u and w instead of single u and w for the whole
* program. */
int per_cc_obj;

/* Extract scop information from libpet*/
int pet;

Expand Down
140 changes: 91 additions & 49 deletions src/ast_transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,70 +28,109 @@

#include "cloog/cloog.h"

/*
* Clast-based parallel loop marking */
/// Clast-based parallel loop marking.
void pluto_mark_parallel(struct clast_stmt *root, const PlutoProg *prog,
CloogOptions *cloogOptions) {
unsigned i, j, nloops, nstmts, nploops;
struct clast_for **loops;
int *stmts;
assert(root != NULL);

unsigned nploops;
Ploop **ploops = pluto_get_dom_parallel_loops(prog, &nploops);
Band **pbands = (Band **)malloc(nploops * sizeof(Band *));

IF_DEBUG(printf("[pluto_mark_parallel] parallel loops\n"););
IF_DEBUG(pluto_loops_print(ploops, nploops););

for (i = 0; i < nploops; i++) {
char iter[13];
sprintf(iter, "t%d", ploops[i]->depth + 1);
int *stmtids = (int *)malloc(ploops[i]->nstmts * sizeof(int));
unsigned max_depth = 0;
for (j = 0; j < ploops[i]->nstmts; j++) {
Stmt *stmt = ploops[i]->stmts[j];
if (stmt->trans->nrows > max_depth)
max_depth = stmt->trans->nrows;
stmtids[j] = stmt->id + 1;
}

IF_DEBUG(printf("\tLooking for loop\n"););
IF_DEBUG(pluto_loop_print(ploops[i]););
// IF_DEBUG(clast_pprint(stdout, root, 0, cloogOptions););

ClastFilter filter = {iter, stmtids, (int)ploops[i]->nstmts, subset};
clast_filter(root, filter, &loops, (int *)&nloops, &stmts, (int *)&nstmts);
for (unsigned i = 0; i < nploops; i++) {
int innermost_split_level;
pbands[i] =
pluto_get_parallel_band(ploops[i], prog, &innermost_split_level);
assert(pbands[i]->width > 0);
}
unsigned npbands = nploops;

/* Iterate over bands and for each loop in the band mark it as parallel. If
* the loop is removed by the clast, then recursively mark the inner loop in
* the given band until atleast one loop is marked or no parallel loops are
* found. Note that the number of bands is equal to the number of dominating
* parallel loops. */
for (unsigned k = 0; k < npbands; k++) {
/* Iterate over loops in a band */
Band *band = pbands[k];
Ploop *curr_loop = pbands[k]->loop;
do {
char iter[13];
sprintf(iter, "t%d", curr_loop->depth + 1);
int *stmtids = (int *)malloc(curr_loop->nstmts * sizeof(int));
unsigned max_depth = 0;
for (unsigned j = 0; j < curr_loop->nstmts; j++) {
Stmt *stmt = curr_loop->stmts[j];
if (stmt->trans->nrows > max_depth)
max_depth = stmt->trans->nrows;
stmtids[j] = stmt->id + 1;
}

/* There should be at least one */
if (nloops == 0) {
/* Sometimes loops may disappear (1) tile size larger than trip count
* 2) it's a scalar dimension but can't be determined from the
* trans matrix */
printf("Warning: parallel poly loop not found in AST\n");
continue;
} else {
for (j = 0; j < nloops; j++) {
loops[j]->parallel = CLAST_PARALLEL_NOT;
char *private_vars = (char *)malloc(512);
strcpy(private_vars, "lbv,ubv");
if (options->parallel) {
IF_DEBUG(printf("Marking %s parallel\n", loops[j]->iterator););
loops[j]->parallel = CLAST_PARALLEL_OMP;
unsigned depth = ploops[i]->depth + 1;
depth++;
for (; depth <= max_depth; depth++) {
sprintf(private_vars + strlen(private_vars), ",t%u", depth);
IF_DEBUG(printf("\tLooking for loop\n"););
IF_DEBUG(pluto_loop_print(curr_loop););

unsigned nloops, nstmts;
int *stmts;
struct clast_for **loops;
ClastFilter filter = {iter, stmtids, (int)curr_loop->nstmts, subset};
clast_filter(root, filter, &loops, (int *)&nloops, &stmts,
(int *)&nstmts);

/* There should be at least one loop.*/
if (nloops == 0) {
/* Sometimes loops may disappear (1) tile size larger than trip count
* 2) it's a scalar dimension but can't be determined from the
* trans matrix. */

/* Reiterate over inner loops in the band. */
unsigned ninloops;
Ploop **inloops =
pluto_get_loops_immediately_inner(curr_loop, prog, &ninloops);

/* TODO: Replace this. Ideally a cloog clast has to be created for each
* loop till it succeeds. Hence a worklist based algrithm is necessary.
*/
if (ninloops == 0 ||
inloops[0]->depth > band->loop->depth + band->width) {
/* No parallel loops in this band. */
printf("Warning: parallel poly loop not found in AST\n");
curr_loop = NULL;
} else {
curr_loop = inloops[0];
}
} else {
for (unsigned j = 0; j < nloops; j++) {
loops[j]->parallel = CLAST_PARALLEL_NOT;
char *private_vars = (char *)malloc(512);
strcpy(private_vars, "lbv,ubv");
if (options->parallel) {
IF_DEBUG(printf("Marking %s parallel\n", loops[j]->iterator););
loops[j]->parallel = CLAST_PARALLEL_OMP;
unsigned depth = curr_loop->depth + 1;
depth++;
for (; depth <= max_depth; depth++) {
sprintf(private_vars + strlen(private_vars), ",t%u", depth);
}
}
loops[j]->private_vars = strdup(private_vars);
free(private_vars);
}
loops[j]->private_vars = strdup(private_vars);
free(private_vars);
/* A loop has been marked parallel. Move to the next band. */
free(stmtids);
free(loops);
free(stmts);
break;
}
}
free(stmtids);
free(loops);
free(stmts);
free(stmtids);
free(loops);
free(stmts);
} while (curr_loop != NULL);
}

pluto_loops_free(ploops, nploops);
pluto_bands_free(pbands, npbands);
}

/*
Expand Down Expand Up @@ -132,6 +171,9 @@ void pluto_mark_vector(struct clast_stmt *root, const PlutoProg *prog,
* trans matrix */
printf("[pluto] pluto_mark_vector: WARNING: vectorizable poly loop not "
"found in AST\n");
free(stmtids);
free(loops);
free(stmts);
continue;
}
for (j = 0; j < nloops; j++) {
Expand Down
21 changes: 16 additions & 5 deletions src/constraints.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,8 @@ int64_t *pluto_prog_constraints_lexmin_glpk(const PlutoConstraints *cst,
}
}

for (j = 0; j < npar + 1; j++) {
sol[j] = max_scale_factor;
for (int j = 0; j < npar + 1; j++) {
sol[j] = max_scale_factor * (int64_t)round(fpsol[j]);
}

int col_iter = num_ccs;
Expand Down Expand Up @@ -1633,6 +1633,16 @@ void pluto_constraints_add_dim(PlutoConstraints *cst, int pos,
}
}

/// Adds dimensions to the constraints at the beginning. The corresponding
/// coefficients of the new variables are nitialized to zero. This is a very
/// inefficient implemetation of the routine. The constraints can be resized at
/// one go and the initialization of these dimensions can be done to zero
/// instead of calling pluto_constraints_add_dim num_dims times
void pluto_constraints_add_leading_dims(PlutoConstraints *cst, int num_dims) {
for (int i = 0; i < num_dims; i++) {
pluto_constraints_add_dim(cst, 0, NULL);
}
}
/* Add a lower bound for 'varnum' variable: varnum: 0-indexed */
void pluto_constraints_add_lb(PlutoConstraints *cst, int varnum, int64_t lb) {
assert(varnum >= 0 && varnum <= cst->ncols - 2);
Expand Down Expand Up @@ -1810,10 +1820,11 @@ void pluto_constraints_project_out(PlutoConstraints *cst, int start, int num) {

void pluto_constraints_interchange_cols(PlutoConstraints *cst, int col1,
int col2) {
int r, tmp;
if (col1 == col2)
return;

for (r = 0; r < cst->nrows; r++) {
tmp = cst->val[r][col1];
for (unsigned r = 0; r < cst->nrows; r++) {
int64_t tmp = cst->val[r][col1];
cst->val[r][col1] = cst->val[r][col2];
cst->val[r][col2] = tmp;
}
Expand Down
10 changes: 6 additions & 4 deletions src/constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void pluto_constraints_add_equality(PlutoConstraints *cst);
void pluto_constraints_add_constraint(PlutoConstraints *cst, int is_eq);
void pluto_constraints_add_dim(PlutoConstraints *cst, int pos,
const char *name);
void pluto_constraints_add_leading_dims(PlutoConstraints *cst, int num_dims);
void pluto_constraints_remove_row(PlutoConstraints *, unsigned);
void pluto_constraints_remove_dim(PlutoConstraints *, int);

Expand Down Expand Up @@ -222,16 +223,17 @@ void pluto_constraints_gaussian_eliminate(PlutoConstraints *cst, int pos);
int pluto_constraints_get_num_non_zero_coeffs(const PlutoConstraints *cst);
#ifdef GLPK
int64_t *pluto_prog_constraints_lexmin_glpk(const PlutoConstraints *cst,
PlutoMatrix *obj, double **val,
int **index, int npar, int num_ccs);
PlutoMatrix *obj, double **val,
int **index, int npar, int num_ccs);
double *pluto_fcg_constraints_lexmin_glpk(const PlutoConstraints *cst,
PlutoMatrix *obj);
#endif

#ifdef GUROBI
int64_t *pluto_prog_constraints_lexmin_gurobi(const PlutoConstraints *cst,
PlutoMatrix *obj, double **val,
int **index, int npar, int num_ccs);
PlutoMatrix *obj, double **val,
int **index, int npar,
int num_ccs);
double *pluto_fcg_constraints_lexmin_gurobi(const PlutoConstraints *cst,
PlutoMatrix *obj);
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/ddg.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ void compute_scc_vertices(Graph *ddg) {
}
}

void print_scc_vertices(int j, Graph *g) {
void print_scc_vertices(int scc_id, Graph *g) {
int i;
for (i = 0; i < g->sccs[j].size; i++) {
printf("S%d, ", g->sccs[j].vertices[i]);
for (i = 0; i < g->sccs[scc_id].size; i++) {
printf("S%d, ", g->sccs[scc_id].vertices[i]);
}
printf("\n");
}
Expand Down
2 changes: 1 addition & 1 deletion src/ddg.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Vertex *ddg_get_vertex_by_id(Graph *g, int id);
bool is_adjecent(Graph *, int, int);
int *get_ssc_topological_order(Graph *ddg);
void compute_scc_vertices(Graph *ddg);
void print_scc_vertices(int j, Graph *g);
void print_scc_vertices(int scc_id, Graph *g);
void free_scc_vertices(Graph *ddg);

#if defined(__cplusplus)
Expand Down

0 comments on commit 6118e7f

Please sign in to comment.