Пример #1
0
/* 
 * Each test case should name statements S_0, S_1, ...
 */
int test2() 
{
    printf("TEST 2\n");
    isl_ctx *ctx = isl_ctx_alloc();
    isl_union_set *domains = isl_union_set_read_from_str(ctx,
            "[p_0, p_1, p_2, p_3, p_4, p_5, p_7] -> { S_1[i0, i1] : i0 >= 0 and i0 <= p_0 and i1 >= 0 and i1 <= p_3 and p_2 >= 0; S_0[i0] : i0 >= 0 and i0 <= p_0}");
    isl_union_map *deps = isl_union_map_read_from_str(ctx, "[p_0, p_1, p_2, p_3, p_4, p_5, p_7] -> { S_0[i0] -> S_1[o0, o1] : (exists (e0 = [(p_7)/8]: 8o1 = -p_5 + p_7 + 8192i0 - 8192o0 and 8e0 = p_7 and i0 >= 0 and o0 <= p_0 and 8192o0 >= -8p_3 - p_5 + p_7 + 8192i0 and 8192o0 <= -p_5 + p_7 + 8192i0 and p_2 >= 0 and o0 >= 1 + i0)); S_1[i0, i1] -> S_0[o0] : (exists (e0 = [(p_1)/8], e1 = [(p_4)/8], e2 = [(-p_1 + p_7)/8184]: 8192o0 = p_5 - p_7 + 8192i0 + 8i1 and 8e0 = p_1 and 8e1 = p_4 and 8184e2 = -p_1 + p_7 and i1 >= 0 and 8i1 <= 8192p_0 - p_5 + p_7 - 8192i0 and 8184i1 >= 1024 + 1024p_1 - 1023p_5 - p_7 - 8380416i0 and p_2 >= 0 and p_7 <= -1 + p_5 and 8i1 >= 1 + 8p_3 + p_4 - p_5 - 8192i0 and i1 <= p_3 and i0 >= 0 and 8i1 >= 8192 - p_5 + p_7))}");

    isl_union_map *schedule = pluto_schedule(domains, deps, options);

    if (schedule) {
        isl_printer *printer = isl_printer_to_file(ctx, stdout);
        isl_printer_print_union_map(printer, schedule);
        printf("\n");
        isl_printer_free(printer);

        // Check if the schedule can be applied to the domain.
        domains = isl_union_set_apply(domains, schedule);
    }else{
        printf("No schedule\n");
    }


    isl_union_set_free(domains);
    isl_union_map_free(deps);

    isl_ctx_free(ctx);
}
Пример #2
0
int main()
{
  isl_ctx* ctx = isl_ctx_alloc();
  isl_ctx_free(ctx);

  return 0;
}
Пример #3
0
			// Init
			void init_solver (void) {
				context = isl_ctx_alloc ();
				isl_space * vars = isl_space_set_alloc (context, 0, v_nb ());
				ls = isl_local_space_from_space (isl_space_copy (vars));
				solutions = isl_set_universe (vars);
				solution = 0;
				next_max_var = 0;
			}
Пример #4
0
enum lp_result isl_constraints_opt(Matrix *C, Value *obj, Value denom,
				    enum lp_dir dir, Value *opt)
{
	int i;
	isl_ctx *ctx = isl_ctx_alloc();
	isl_space *dim;
	isl_local_space *ls;
	isl_mat *eq, *ineq;
	isl_basic_set *bset;
	isl_aff *aff;
	isl_val *v;
	enum isl_lp_result res;
	int max = dir == lp_max;

	eq = extract_equalities(ctx, C);
	ineq = extract_inequalities(ctx, C);
	dim = isl_space_set_alloc(ctx, 0, C->NbColumns - 2);
	ls = isl_local_space_from_space(isl_space_copy(dim));
	bset = isl_basic_set_from_constraint_matrices(dim, eq, ineq,
			isl_dim_set, isl_dim_div, isl_dim_param, isl_dim_cst);
	aff = isl_aff_zero_on_domain(ls);
	for (i = 0; i < C->NbColumns - 2; ++i) {
		v = isl_val_int_from_gmp(ctx, obj[i]);
		aff = isl_aff_set_coefficient_val(aff, isl_dim_in, i, v);
	}
	v = isl_val_int_from_gmp(ctx, obj[C->NbColumns - 2]);
	aff = isl_aff_set_constant_val(aff, v);
	v = isl_val_int_from_gmp(ctx, denom);
	aff = isl_aff_scale_down_val(aff, v);

	if (max)
		v = isl_val_floor(isl_basic_set_max_lp_val(bset, aff));
	else
		v = isl_val_ceil(isl_basic_set_min_lp_val(bset, aff));
	if (!v)
		res = isl_lp_error;
	else if (isl_val_is_nan(v))
		res = isl_lp_empty;
	else if (!isl_val_is_rat(v))
		res = isl_lp_unbounded;
	else {
		res = isl_lp_ok;
		isl_val_get_num_gmp(v, *opt);
	}

	isl_val_free(v);
	isl_aff_free(aff);
	isl_basic_set_free(bset);
	isl_ctx_free(ctx);

	return isl_lp_result2lp_result(res);
}
int main(int argc, char **argv)
{
	struct isl_ctx *ctx = isl_ctx_alloc();
	struct isl_basic_set *bset;

	bset = isl_basic_set_read_from_file(ctx, stdin);
	bset = isl_basic_set_detect_equalities(bset);
	isl_basic_set_print(bset, stdout, 0, "", "", ISL_FORMAT_POLYLIB);
	isl_basic_set_free(bset);
	isl_ctx_free(ctx);

	return 0;
}
Пример #6
0
int main(int argc, char **argv)
{
	struct isl_ctx *ctx = isl_ctx_alloc();
	struct isl_basic_set *bset;
	struct isl_mat *samples;

	bset = isl_basic_set_read_from_file(ctx, stdin);
	samples = isl_basic_set_samples(bset);
	isl_mat_print_internal(samples, stdout, 0);
	isl_mat_free(samples);
	isl_ctx_free(ctx);

	return 0;
}
Пример #7
0
void
graphite_transform_loops (void)
{
  int i;
  scop_p scop;
  bool need_cfg_cleanup_p = false;
  vec<scop_p> scops = vNULL;
  bb_pbb_htab_type bb_pbb_mapping;
  isl_ctx *ctx;

  /* If a function is parallel it was most probably already run through graphite
     once. No need to run again.  */
  if (parallelized_function_p (cfun->decl))
    return;

  ctx = isl_ctx_alloc ();
  isl_options_set_on_error (ctx, ISL_ON_ERROR_ABORT);
  if (!graphite_initialize (ctx))
    return;

  the_isl_ctx = ctx;
  build_scops (&scops);

  if (dump_file && (dump_flags & TDF_DETAILS))
    {
      print_graphite_statistics (dump_file, scops);
      print_global_statistics (dump_file);
    }

  bb_pbb_mapping.create (10);

  FOR_EACH_VEC_ELT (scops, i, scop)
    if (dbg_cnt (graphite_scop))
      {
	scop->ctx = ctx;
	build_poly_scop (scop);

	if (POLY_SCOP_P (scop)
	    && apply_poly_transforms (scop)
	    && gloog (scop, bb_pbb_mapping))
	  need_cfg_cleanup_p = true;
      }

  bb_pbb_mapping.dispose ();
  free_scops (scops);
  graphite_finalize (need_cfg_cleanup_p);
  the_isl_ctx = NULL;
  isl_ctx_free (ctx);
}
int main(int argc, char **argv)
{
	struct isl_ctx *ctx = isl_ctx_alloc();
	struct isl_basic_set *bset;
	struct isl_vec *obj;
	struct isl_vec *sol;
	isl_int opt;
	unsigned dim;
	enum isl_lp_result res;
	isl_printer *p;

	isl_int_init(opt);
	bset = isl_basic_set_read_from_file(ctx, stdin);
	assert(bset);
	obj = isl_vec_read_from_file(ctx, stdin);
	assert(obj);
	dim = isl_basic_set_total_dim(bset);
	assert(obj->size >= dim && obj->size <= dim + 1);
	if (obj->size != dim + 1)
		obj = isl_vec_lin_to_aff(obj);
	else
		obj = vec_ror(obj);
	res = isl_basic_set_solve_ilp(bset, 0, obj->el, &opt, &sol);
	switch (res) {
	case isl_lp_error:
		fprintf(stderr, "error\n");
		return -1;
	case isl_lp_empty:
		fprintf(stdout, "empty\n");
		break;
	case isl_lp_unbounded:
		fprintf(stdout, "unbounded\n");
		break;
	case isl_lp_ok:
		p = isl_printer_to_file(ctx, stdout);
		p = isl_printer_print_vec(p, sol);
		p = isl_printer_end_line(p);
		p = isl_printer_print_isl_int(p, opt);
		p = isl_printer_end_line(p);
		isl_printer_free(p);
	}
	isl_basic_set_free(bset);
	isl_vec_free(obj);
	isl_vec_free(sol);
	isl_ctx_free(ctx);
	isl_int_clear(opt);

	return 0;
}
Пример #9
0
Param_Polyhedron *ISL_P2PP(Polyhedron *P, Polyhedron *C,
			  struct barvinok_options *options)
{
	int i, j;
	isl_ctx *ctx = isl_ctx_alloc();
	isl_space *dim;
	isl_basic_set *bset, *context;
	isl_vertices *vertices;
	unsigned nparam = C->Dimension;
	unsigned nvar = P->Dimension - nparam;
	Param_Polyhedron *PP = isl_calloc_type(ctx, Param_Polyhedron);
	Param_Vertices **next_V;
	struct bv_add_chamber_data data;

	dim = isl_space_set_alloc(ctx, nparam, nvar);
	bset = isl_basic_set_new_from_polylib(P, dim);
	dim = isl_space_set_alloc(ctx, nparam, 0);
	context = isl_basic_set_new_from_polylib(C, dim);

	bset = isl_basic_set_intersect(bset, context);

	vertices = isl_basic_set_compute_vertices(bset);
	isl_basic_set_free(bset);

	PP->Rays = NULL;
	PP->nbV = isl_vertices_get_n_vertices(vertices);
	PP->Constraints = Polyhedron2Constraints(P);

	next_V = &PP->V;
	isl_vertices_foreach_vertex(vertices, &add_vertex, &next_V);

	data.next_D = &PP->D;
	data.vertex_len = (PP->nbV + INT_BITS - 1)/INT_BITS;
	isl_vertices_foreach_cell(vertices, &add_chamber, &data);

	isl_vertices_free(vertices);

	isl_ctx_free(ctx);

	return PP;
}
Пример #10
0
int main(int argc, char **argv)
{
    struct isl_ctx *ctx = isl_ctx_alloc();
    struct isl_basic_set *bset;
    struct isl_vec *sample;
    isl_printer *p;

    bset = isl_basic_set_read_from_file(ctx, stdin);
    sample = isl_basic_set_sample_vec(isl_basic_set_copy(bset));
    p = isl_printer_to_file(ctx, stdout);
    p = isl_printer_print_vec(p, sample);
    p = isl_printer_end_line(p);
    isl_printer_free(p);
    assert(sample);
    if (sample->size > 0)
        assert(isl_basic_set_contains(bset, sample));
    isl_basic_set_free(bset);
    isl_vec_free(sample);
    isl_ctx_free(ctx);

    return 0;
}
Пример #11
0
void test1()
{
    isl_ctx *ctx = isl_ctx_alloc();
    isl_union_set *domains = isl_union_set_read_from_str(ctx,
            "[n] -> {S_1[i0, i1] : i0 >= 0 and i0 <= 99 and i1 >= 0 and i1 <= 99; S_0[i0] : i0 >= 0 and i0 <= 99; S_2[i0] : i0 >= 0 and i0 <= 99 }");
    isl_union_map *deps = isl_union_map_read_from_str(ctx, "[n] -> {S_1[i0, 99] -> S_0[1 + i0] : i0 >= 0 and i0 <= 98; S_1[i0, i1] -> S_1[i0, 1 + i1] : i0 >= 0 and i0 <= 99 and i1 >= 0 and i1 <= 98; S_1[i0, 99] -> S_1[1 + i0, 0] : i0 >= 0 and i0 <= 98; S_0[i0] -> S_1[i0, 0] : i0 >= 0 and i0 <= 99; S_2[i0] -> S_1[1 + i0, 0] : i0 >= 0 and i0 <= 98; S_0[i0] -> S_2[i0] : i0 >= 0 and i0 <= 99; S_1[i0, 99] -> S_2[i0] : i0 >= 0 and i0 <= 99 }");

    isl_union_map *schedule = pluto_schedule(domains, deps, options);

    isl_printer *printer = isl_printer_to_file(ctx, stdout);
    isl_printer_print_union_map(printer, schedule);
    printf("\n");
    isl_printer_free(printer);

    // Check if the schedule can be applied to the domain.
    domains = isl_union_set_apply(domains, schedule);

    isl_union_set_free(domains);
    isl_union_map_free(deps);


    isl_ctx_free(ctx);
}
/**
 * Converts a SCoP as extracted by PolyOpt's auto-scop detection
 * into ISL representation.
 *
 * bugs/limitations:
 *    (a) not robust to union of iteration domains in scoplib
 *    (b) code is leaking, need proper copy constructor that duplicates all
 *          ISL structures.
 */
int
PolyOptISLRepresentation::convertScoplibToISL (scoplib_scop_p scop)
{
  int i;
  isl_union_map* all_reads = NULL;
  isl_union_map* all_writes = NULL;
  isl_union_map* all_scheds = NULL;
  isl_ctx* ctxt = isl_ctx_alloc();

  // 1. Prepare the arrays of unique names for statements and arrays.
  char buffer[32];
  int nb_statements;
  scoplib_statement_p s;
  for (nb_statements = 0, s = scop->statement; s; s = s->next, nb_statements++)
    ;
  char* stmt_names[nb_statements];
  for (i = 0; i < nb_statements; ++i)
    {
      sprintf (buffer, "S_%d", i);
      stmt_names[i] = strdup (buffer);
    }
  char* array_names[scop->nb_arrays];
  for (i = 0; i < scop->nb_arrays; ++i)
    array_names[i] =
      strdup (((SgVariableSymbol*)(scop->arrays[i]))->get_name().str());

  isl_union_map* umap;
  int stmt_id;
  for (s = scop->statement, stmt_id = 0; s; s = s->next, ++stmt_id)
    {
      isl_union_map* all_reads_stmt = NULL;
      isl_union_map* all_writes_stmt = NULL;
      isl_space* sp = NULL;
      for (i = 0; i < scop->nb_arrays; ++i)
	{
	  sp = build_isl_space (scop, s, i+1, ctxt);

	  // 1. Handle access matrices.
	  scoplib_matrix_p m;
	  int k;
	  for (k = 0, m = s->read, umap = all_reads_stmt; k < 2;
	       k++, m = s->write, umap = all_writes_stmt)
	    {
	      isl_map* acc_map = NULL;
	      int row_pos = 0;
	      do
		{
		  acc_map = build_access_function
		    (scop, s, m, sp, ctxt, &row_pos, i+1);
		  if (acc_map)
		    {
		      acc_map = isl_map_set_tuple_name
			(acc_map, isl_dim_in, stmt_names[stmt_id]);
		      acc_map = isl_map_set_tuple_name
			(acc_map, isl_dim_out, array_names[i]);
		      if (umap == NULL)
			umap = isl_union_map_from_map (isl_map_copy (acc_map));
		      else
			umap = isl_union_map_union
			  (umap, isl_union_map_from_map (isl_map_copy (acc_map)));
		      isl_map_free (acc_map);
		    }
		}
	      while (acc_map != NULL);
	      if (k == 0)
		all_reads_stmt = umap;
	      else
		all_writes_stmt = umap;
	    }
	}
      // Store the union of access functions of statement i.
      stmt_accfunc_read.push_back (all_reads_stmt);
      stmt_accfunc_write.push_back (all_writes_stmt);

      // 2. Handle iteration domains.
      isl_set* dom = build_iteration_domain (scop, s, sp, ctxt);
      dom = isl_set_set_tuple_name (dom, stmt_names[stmt_id]);
      if (all_reads_stmt != NULL)
	all_reads_stmt = isl_union_map_intersect_domain
	  (isl_union_map_copy (all_reads_stmt),
	   isl_union_set_from_set (isl_set_copy (dom)));
      if (all_writes_stmt != NULL)
	all_writes_stmt = isl_union_map_intersect_domain
	  (all_writes_stmt, isl_union_set_from_set (isl_set_copy (dom)));

      // Store the iteration domain of statement i.
      stmt_iterdom.push_back (dom);
      // Store the union of access functions of statement i after intersection by domain.
      stmt_read_domain.push_back (all_reads_stmt);
      stmt_write_domain.push_back (all_writes_stmt);

      // Unionize the result.
      if (all_reads == NULL)
	all_reads = isl_union_map_copy (all_reads_stmt);
      else
	all_reads = isl_union_map_union
	  (all_reads, isl_union_map_copy (all_reads_stmt));
      if (all_writes == NULL)
	all_writes = isl_union_map_copy (all_writes_stmt);
      else
	all_writes = isl_union_map_union
	  (all_writes, isl_union_map_copy (all_writes_stmt));
      // isl_union_map_free (all_reads_stmt);
      // isl_union_map_free (all_writes_stmt);

      // 3. Handle schedules.
      isl_map* sched = build_schedule (scop, s, sp, ctxt);
      sched = isl_map_set_tuple_name (sched, isl_dim_in, stmt_names[stmt_id]);
      if (all_scheds == NULL)
	all_scheds = isl_union_map_from_map (isl_map_copy (sched));
      else
	all_scheds = isl_union_map_union
	  (all_scheds, isl_union_map_from_map (isl_map_copy (sched)));
      // Store the schedule of statement i.
      stmt_schedule.push_back (sched);

      // 4. Finalize info about the statement.
      stmt_body.push_back (((SgNode*)(s->body))->unparseToCompleteString());
      stmt_body_ir.push_back ((SgNode*)(s->body));
    }

  // // Debug.
  // isl_printer* pr = isl_printer_to_file (ctxt, stdout);
  // std::cout << "UNION MAP READS" << std::endl;
  // isl_printer_print_union_map(pr, all_reads);
  // printf ("\n");
  // std::cout << "UNION MAP WRITES" << std::endl;
  // isl_printer_print_union_map(pr, all_writes);
  // printf ("\n");
  // std::cout << "UNION MAP SCHEDULES" << std::endl;
  // isl_printer_print_union_map(pr, all_scheds);
  // printf ("\n");
  for (std::vector<std::string>::iterator i = stmt_body.begin();
       i != stmt_body.end(); ++i)
    std::cout << "stmt body: " << *i << std::endl;
  // Finalize SCoP representation.
  scop_nb_arrays = scop->nb_arrays;
  scop_nb_statements = stmt_schedule.size();
  scop_reads = all_reads;
  scop_writes = all_writes;
  scop_scheds = all_scheds;

  return EXIT_SUCCESS;
}
Пример #13
0
enum order_sign isl_polyhedron_affine_sign(Polyhedron *D, Matrix *T,
					    struct barvinok_options *options)
{
	int i;
	isl_ctx *ctx = isl_ctx_alloc();
	isl_space *dim;
	isl_local_space *ls;
	isl_aff *aff;
	isl_basic_set *bset;
	isl_val *min, *max = NULL;
	isl_val *v;
	enum order_sign sign = order_undefined;

	assert(D->Dimension == T->NbColumns - 1);

	dim = isl_space_set_alloc(ctx, 0, D->Dimension);
	ls = isl_local_space_from_space(isl_space_copy(dim));
	bset = isl_basic_set_new_from_polylib(D, dim);
	aff = isl_aff_zero_on_domain(ls);
	for (i = 0; i < D->Dimension; ++i) {
		v = isl_val_int_from_gmp(ctx, T->p[0][i]);
		aff = isl_aff_set_coefficient_val(aff, isl_dim_in, i, v);
	}
	v = isl_val_int_from_gmp(ctx, T->p[0][D->Dimension]);
	aff = isl_aff_set_constant_val(aff, v);
	v = isl_val_int_from_gmp(ctx, T->p[1][D->Dimension]);
	aff = isl_aff_scale_down_val(aff, v);

	min = isl_basic_set_min_lp_val(bset, aff);
	min = isl_val_ceil(min);
	assert(min);

	if (isl_val_is_nan(min))
		sign = order_undefined;
	else if (isl_val_is_pos(min))
		sign = order_gt;
	else {
		max = isl_basic_set_max_lp_val(bset, aff);
		max = isl_val_floor(max);
		assert(max);

		if (isl_val_is_neg(max))
			sign = order_lt;
		else if (isl_val_is_zero(min) && isl_val_is_zero(max))
			sign = order_eq;
		else if (isl_val_is_zero(min))
			sign = order_ge;
		else if (isl_val_is_zero(max))
			sign = order_le;
		else
			sign = order_unknown;
	}

	isl_basic_set_free(bset);
	isl_aff_free(aff);
	isl_val_free(min);
	isl_val_free(max);
	isl_ctx_free(ctx);

	return sign;
}