/// @brief Create an isl map from a OpenScop matrix. /// /// @param m The OpenScop matrix to translate. /// @param Space The dimensions that are contained in the OpenScop matrix. /// /// @return An isl map representing m. isl_map *mapFromMatrix(scoplib_matrix_p m, __isl_take isl_space *Space, unsigned scatteringDims) { isl_basic_map *bmap = isl_basic_map_universe(isl_space_copy(Space)); for (unsigned i = 0; i < m->NbRows; ++i) { isl_constraint *c; c = constraintFromMatrixRow(m->p[i], isl_space_copy(Space)); mpz_t minusOne; mpz_init(minusOne); mpz_set_si(minusOne, -1); isl_constraint_set_coefficient(c, isl_dim_out, i, minusOne); bmap = isl_basic_map_add_constraint(bmap, c); } for (unsigned i = m->NbRows; i < scatteringDims; i++) { isl_constraint *c; c = isl_equality_alloc(isl_local_space_from_space(isl_space_copy(Space))); mpz_t One; mpz_init(One); mpz_set_si(One, 1); isl_constraint_set_coefficient(c, isl_dim_out, i, One); bmap = isl_basic_map_add_constraint(bmap, c); } isl_space_free(Space); return isl_map_from_basic_map(bmap); }
/* Apply the morphism to the set. */ __isl_give isl_set *isl_morph_set(__isl_take isl_morph *morph, __isl_take isl_set *set) { int i; if (!morph || !set) goto error; isl_assert(set->ctx, isl_space_is_equal(set->dim, morph->dom->dim), goto error); set = isl_set_cow(set); if (!set) goto error; isl_space_free(set->dim); set->dim = isl_space_copy(morph->ran->dim); if (!set->dim) goto error; for (i = 0; i < set->n; ++i) { set->p[i] = isl_morph_basic_set(isl_morph_copy(morph), set->p[i]); if (!set->p[i]) goto error; } isl_morph_free(morph); ISL_F_CLR(set, ISL_SET_NORMALIZED); return set; error: isl_set_free(set); isl_morph_free(morph); return NULL; }
static __isl_give isl_qpolynomial *bound2poly(__isl_take isl_constraint *bound, __isl_take isl_space *space, unsigned pos, int sign) { if (!bound) return signed_infty(space, sign); isl_space_free(space); return isl_qpolynomial_from_constraint(bound, isl_dim_set, pos); }
/* Construct a unique identifier for a group in "grouping". * * The name is of the form G_n, with n the first value starting at * grouping->group_id that does not result in an identifier * that is already in use in the domain of the original schedule * constraints. */ static isl_id *construct_group_id(struct ppcg_grouping *grouping, __isl_take isl_space *space) { isl_ctx *ctx; isl_id *id; isl_bool empty; isl_union_set *domain; if (!space) return NULL; ctx = isl_space_get_ctx(space); domain = isl_schedule_constraints_get_domain(grouping->sc); do { char buffer[20]; isl_id *id; isl_set *set; snprintf(buffer, sizeof(buffer), "G_%d", grouping->group_id); grouping->group_id++; id = isl_id_alloc(ctx, buffer, NULL); space = isl_space_set_tuple_id(space, isl_dim_set, id); set = isl_union_set_extract_set(domain, isl_space_copy(space)); empty = isl_set_plain_is_empty(set); isl_set_free(set); } while (empty >= 0 && !empty); if (empty < 0) space = isl_space_free(space); id = isl_space_get_tuple_id(space, isl_dim_set); isl_space_free(space); isl_union_set_free(domain); return id; }
/// @brief Create an isl map from a OpenScop matrix. /// /// @param m The OpenScop matrix to translate. /// @param Space The dimensions that are contained in the OpenScop matrix. /// /// @return An isl map representing m. isl_map *mapFromMatrix(scoplib_matrix_p m, __isl_take isl_space *Space) { isl_basic_map *bmap = isl_basic_map_universe(isl_space_copy(Space)); for (unsigned i = 0; i < m->NbRows; ++i) { isl_constraint *c; c = constraintFromMatrixRowFull(m->p[i], isl_space_copy(Space)); bmap = isl_basic_map_add_constraint(bmap, c); } isl_space_free(Space); return isl_map_from_basic_map(bmap); }
/* Set the arguments of the OpenCL kernel by printing a call to the OpenCL * clSetKernelArg() function for each kernel argument. */ static __isl_give isl_printer *opencl_set_kernel_arguments( __isl_take isl_printer *p, struct gpu_prog *prog, struct ppcg_kernel *kernel) { int i, n, ro; unsigned nparam; isl_space *space; int arg_index = 0; for (i = 0; i < prog->n_array; ++i) { int required; required = ppcg_kernel_requires_array_argument(kernel, i); if (required < 0) return isl_printer_free(p); if (!required) continue; ro = gpu_array_is_read_only_scalar(&prog->array[i]); opencl_set_kernel_argument(p, kernel->id, prog->array[i].name, arg_index, ro); arg_index++; } space = isl_union_set_get_space(kernel->arrays); nparam = isl_space_dim(space, isl_dim_param); for (i = 0; i < nparam; ++i) { const char *name; name = isl_space_get_dim_name(space, isl_dim_param, i); opencl_set_kernel_argument(p, kernel->id, name, arg_index, 1); arg_index++; } isl_space_free(space); n = isl_space_dim(kernel->space, isl_dim_set); for (i = 0; i < n; ++i) { const char *name; name = isl_space_get_dim_name(kernel->space, isl_dim_set, i); opencl_set_kernel_argument(p, kernel->id, name, arg_index, 1); arg_index++; } return p; }
__isl_give isl_val *FN(UNION,eval)(__isl_take UNION *u, __isl_take isl_point *pnt) { uint32_t hash; struct isl_hash_table_entry *entry; isl_bool is_void; isl_space *space; isl_val *v; if (!u || !pnt) goto error; is_void = isl_point_is_void(pnt); if (is_void < 0) goto error; if (is_void) return FN(UNION,eval_void)(u, pnt); space = isl_space_copy(pnt->dim); if (!space) goto error; hash = isl_space_get_hash(space); entry = isl_hash_table_find(u->space->ctx, &u->table, hash, &FN(UNION,has_domain_space), space, 0); isl_space_free(space); if (!entry) { v = isl_val_zero(isl_point_get_ctx(pnt)); isl_point_free(pnt); } else { v = FN(PART,eval)(FN(PART,copy)(entry->data), pnt); } FN(UNION,free)(u); return v; error: FN(UNION,free)(u); isl_point_free(pnt); return NULL; }
/// @brief Create a new scattering for PollyStmt. /// /// @param m The matrix describing the new scattering. /// @param PollyStmt The statement to create the scattering for. /// /// @return An isl_map describing the scattering. isl_map *scatteringForStmt(scoplib_matrix_p m, ScopStmt *PollyStmt, int scatteringDims) { unsigned NbParam = PollyStmt->getNumParams(); unsigned NbIterators = PollyStmt->getNumIterators(); unsigned NbScattering; if (scatteringDims == -1) NbScattering = m->NbColumns - 2 - NbParam - NbIterators; else NbScattering = scatteringDims; isl_ctx *ctx = PollyStmt->getParent()->getIslCtx(); isl_space *Space = isl_dim_alloc(ctx, NbParam, NbIterators, NbScattering); isl_space *ParamSpace = PollyStmt->getParent()->getParamSpace(); // We need to copy the isl_ids for the parameter dimensions to the new // map. Without doing this the current map would have different // ids then the new one, even though both are named identically. for (unsigned i = 0; i < isl_space_dim(Space, isl_dim_param); i++) { isl_id *id = isl_space_get_dim_id(ParamSpace, isl_dim_param, i); Space = isl_space_set_dim_id(Space, isl_dim_param, i, id); } isl_space_free(ParamSpace); Space = isl_space_set_tuple_name(Space, isl_dim_out, "scattering"); Space = isl_space_set_tuple_id(Space, isl_dim_in, PollyStmt->getDomainId()); if (scatteringDims == -1) return mapFromMatrix(m, Space); return mapFromMatrix(m, Space, scatteringDims); }
/* Print the arguments to a kernel declaration or call. If "types" is set, * then print a declaration (including the types of the arguments). * * The arguments are printed in the following order * - the arrays accessed by the kernel * - the parameters * - the host loop iterators */ static __isl_give isl_printer *print_kernel_arguments(__isl_take isl_printer *p, struct gpu_prog *prog, struct ppcg_kernel *kernel, int types) { int i, n; int first = 1; unsigned nparam; isl_space *space; const char *type; for (i = 0; i < prog->n_array; ++i) { int required; required = ppcg_kernel_requires_array_argument(kernel, i); if (required < 0) return isl_printer_free(p); if (!required) continue; if(!print_device_arrays_or_not(&prog->array[i])) continue; if (!first) p = isl_printer_print_str(p, ", "); if (types) p = gpu_array_info_print_declaration_argument(p, &prog->array[i], NULL); else p = gpu_array_info_print_call_argument(p, &prog->array[i]); first = 0; } space = isl_union_set_get_space(kernel->arrays); nparam = isl_space_dim(space, isl_dim_param); for (i = 0; i < nparam; ++i) { const char *name; name = isl_space_get_dim_name(space, isl_dim_param, i); if (!first) p = isl_printer_print_str(p, ", "); if (types) p = isl_printer_print_str(p, "int "); p = isl_printer_print_str(p, name); first = 0; } isl_space_free(space); n = isl_space_dim(kernel->space, isl_dim_set); type = isl_options_get_ast_iterator_type(prog->ctx); for (i = 0; i < n; ++i) { const char *name; if (!first) p = isl_printer_print_str(p, ", "); name = isl_space_get_dim_name(kernel->space, isl_dim_set, i); if (types) { p = isl_printer_print_str(p, type); p = isl_printer_print_str(p, " "); } p = isl_printer_print_str(p, name); first = 0; } return p; }