Esempio n. 1
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);
}
Esempio n. 2
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;
}
Esempio n. 3
0
PlutoMatrix *pluto_matrix_input(FILE *fp)
{
    int i, j, nrows, ncols;
    fscanf(fp, "%d %d", &nrows, &ncols);

    PlutoMatrix *mat = pluto_matrix_alloc(nrows, ncols);

    for (i=0; i<mat->nrows; i++)
        for (j=0; j<mat->ncols; j++)
            fscanf(fp, "%lld", &mat->val[i][j]);

    return mat;
}
Esempio n. 4
0
/* Return an identity matrix of size: size x size */
PlutoMatrix *pluto_matrix_identity(int size)
{
    int i;

    PlutoMatrix *mat = pluto_matrix_alloc(size, size);
    pluto_matrix_set(mat, 0);

    for (i=0; i<size; i++)  {
        mat->val[i][i] = 1;
    }

    return mat;
}
Esempio n. 5
0
PlutoMatrix *polylib_matrix_to_pluto(Matrix *pmat)
{
    PlutoMatrix *mat;
    int r, c;

    mat = pluto_matrix_alloc(pmat->NbRows, pmat->NbColumns);

    for (r=0; r<mat->nrows; r++)    {
        for (c=0; c<mat->ncols; c++)    {
            mat->val[r][c] = pmat->p[r][c];
        }

    }

    return mat;
}
Esempio n. 6
0
/*
 * Construct a PlutoMatrix with the same content as the given isl_mat.
 */
PlutoMatrix *pluto_matrix_from_isl_mat(__isl_keep isl_mat *mat)
{
    int i, j;
    int rows, cols;
    PlutoMatrix *pluto;

    rows = isl_mat_rows(mat);
    cols = isl_mat_cols(mat);
    pluto = pluto_matrix_alloc(rows, cols);

    for (i = 0; i < rows; ++i)
        for (j = 0; j < cols; ++j) {
            isl_val *v = isl_mat_get_element_val(mat, i, j);
            pluto->val[i][j] = isl_val_get_num_si(v);
            isl_val_free(v);
        }

    return pluto;
}
Esempio n. 7
0
PlutoMatrix *pluto_matrix_product(const PlutoMatrix *mat1, 
        const PlutoMatrix *mat2)
{
    assert(mat1->ncols == mat2->nrows);

    int i, j, k;

    PlutoMatrix *mat3 = pluto_matrix_alloc(mat1->nrows, mat2->ncols);

    for (i=0; i<mat1->nrows; i++)   {
        for (j=0; j<mat2->ncols; j++)   {
            mat3->val[i][j] = 0;
            for (k=0; k<mat1->ncols; k++)   {
                mat3->val[i][j] += mat1->val[i][k]*mat2->val[k][j];
            }
        }
    }
    return mat3;
}
Esempio n. 8
0
/* Return a duplicate of src */
PlutoMatrix *pluto_matrix_dup(const PlutoMatrix *src)
{
    int i, j;

    assert(src != NULL);

    PlutoMatrix *dup = pluto_matrix_alloc(src->alloc_nrows, src->alloc_ncols);

    for (i=0; i<src->nrows; i++)    {
        for (j=0; j<src->ncols; j++)    {
            dup->val[i][j] = src->val[i][j];
        }
    }

    dup->nrows = src->nrows;
    dup->ncols = src->ncols;

    return dup;
}