예제 #1
0
int has_spatial_reuse(Stmt *stmt, PlutoAccess *acc, int depth)
{
    int i, *divs;
    PlutoMatrix *newacc = pluto_get_new_access_func(stmt, acc->mat, &divs);
    assert(depth <= newacc->ncols-1);

    /* Scalars */
    if (newacc->nrows == 0) return 0;

    for (i=0; i<newacc->nrows-1; i++) {
        /* No spatial reuse when the func is varying at a non-innermost dim */
        if (newacc->val[i][depth] != 0) {
            pluto_matrix_free(newacc);
            free(divs);
            return 0;
        }
    }

    if (newacc->val[newacc->nrows-1][depth] >= 1 &&
            newacc->val[newacc->nrows-1][depth] <= SHORT_STRIDE) {
        pluto_matrix_free(newacc);
        free(divs);
        return 1;
    }

    pluto_matrix_free(newacc);
    free(divs);

    return 0;
}
예제 #2
0
/* 
 * Project out from a single element list of constraints
 * start: 0-indexed 
 * */
void pluto_constraints_project_out_single(
        PlutoConstraints *cst, 
        int start, 
        int num)
{
    int i, end;

    assert(num>= 0);

    if (num == 0)   return;

    end = start + num - 1;

    assert(start >= 0 && end <= cst->ncols-2);

    PlutoMatrix *func = pluto_matrix_alloc(cst->ncols-num, cst->ncols);
    pluto_matrix_initialize(func, 0);
    for (i=0; i<start; i++) {
        func->val[i][i] = 1;
    }
    for (i=end+1; i<cst->ncols; i++) {
        func->val[i-num][i] = 1;
    }

    PlutoConstraints *img =  pluto_constraints_image(cst, func);
    pluto_constraints_copy_single(cst, img);

    pluto_constraints_free(img);
    pluto_matrix_free(func);
}
예제 #3
0
/* Used by libpluto interface */
static int extract_stmt(__isl_take isl_set *set, void *user)
{
    int r;
    Stmt **stmts;
    int id, i;

    stmts = (Stmt **) user;

    int dim = isl_set_dim(set, isl_dim_all);
    int npar = isl_set_dim(set, isl_dim_param);
    PlutoMatrix *trans = pluto_matrix_alloc(dim-npar, dim+1);
    pluto_matrix_set(trans, 0);
    trans->nrows = 0;

    /* A statement's domain (isl_set) should be named S_%d */
    const char *name = isl_set_get_tuple_name(set);
    assert(name);
    assert(strlen(name) >= 3);
    assert(name[0] == 'S');
    assert(name[1] == '_');
    assert(isdigit(name[2]));
    id = atoi(isl_set_get_tuple_name(set)+2);

    stmts[id] = pluto_stmt_alloc(dim-npar, NULL, trans);

    Stmt *stmt = stmts[id];
    stmt->type = ORIG;
    stmt->id = id;

    for (i=0; i<stmt->dim; i++) {
        char *iter = malloc(5);
        sprintf(iter, "i%d",  i);
        stmt->iterators[i] = iter;
    }

    struct pluto_extra_stmt_info info = {stmts, id};
    r = isl_set_foreach_basic_set(set, &extract_basic_set, &info);

    pluto_constraints_set_names_range(stmt->domain, stmt->iterators, 0, 0, stmt->dim);

    for (i=0; i<npar; i++) {
        char *param = malloc(5);
        sprintf(param, "p%d", i);
        stmt->domain->names[stmt->dim+i] = param;
    }

    pluto_matrix_free(trans);

    int j;
    for (j=0; j<stmt->dim; j++)  {
        stmt->is_orig_loop[j] = true;
    }

    isl_set_free(set);

    return r;
}
예제 #4
0
int has_spatial_reuse(Stmt *stmt, PlutoAccess *acc, int depth)
{
    int i, *divs;
    PlutoMatrix *newacc = pluto_get_new_access_func(stmt, acc->mat, &divs);
    assert(depth <= newacc->ncols-1);
    for (i=0; i<newacc->nrows-1; i++) {
        if (newacc->val[i][depth] != 0) {
            pluto_matrix_free(newacc);
            return 0;
        }
    }
    if (newacc->val[newacc->nrows-1][depth] >= 1 &&
            newacc->val[newacc->nrows-1][depth] <= SHORT_STRIDE) {
        pluto_matrix_free(newacc);
        return 1;
    }

    pluto_matrix_free(newacc);

    return 0;
}
예제 #5
0
int is_invariant(Stmt *stmt, PlutoAccess *acc, int depth)
{
    int i, *divs;
    PlutoMatrix *newacc = pluto_get_new_access_func(stmt, acc->mat, &divs);
    assert(depth <= newacc->ncols-1);
    for (i=0; i<newacc->nrows; i++) {
        if (newacc->val[i][depth] != 0) break;
    }
    int is_invariant = (i==newacc->nrows);
    pluto_matrix_free(newacc);
    return is_invariant;
}
예제 #6
0
/* Rank of the matrix */
int pluto_matrix_get_rank(const PlutoMatrix *mat)
{
    int i, j, null, rank;

    PlutoMatrix *re = pluto_matrix_to_row_echelon(pluto_matrix_dup(mat));

    // pluto_matrix_print(stdout, re);

    null = 0;
    for (i=0; i<re->nrows; i++) {
        int sum = 0;
        for (j=0; j<re->ncols; j++) {
            sum += llabs(re->val[i][j]);
        }
        if (sum==0) null++;
    }
    rank = re->nrows - null;
    pluto_matrix_free(re);
    return rank;
}
예제 #7
0
/* Converts to a polylib polyhedron */
Polyhedron *pluto_constraints_to_polylib(const PlutoConstraints *cst)
{
    Polyhedron *pol;
    PlutoMatrix *mat;
    Matrix *polymat;

    mat = pluto_constraints_to_matrix(cst);

    polymat = pluto_matrix_to_polylib(mat);

    pol = Constraints2Polyhedron(polymat, 50);

    Matrix_Free(polymat);
    pluto_matrix_free(mat);

    if (cst->next != NULL)  {
        pol->next = pluto_constraints_to_polylib(cst->next);
    }

    return pol;
}