/* * Output schedules are isl relations that have dims in the order * isl_dim_out, isl_dim_in, div, param, const */ __isl_give isl_union_map *pluto_schedule(isl_union_set *domains, isl_union_map *dependences, PlutoOptions *options_l) { int i, j, nbands, n_ibands, retval; isl_ctx *ctx; isl_space *space; ctx = isl_union_set_get_ctx(domains); space = isl_union_set_get_space(domains); // isl_union_set_dump(domains); // isl_union_map_dump(dependences); options = options_l; PlutoProg *prog = pluto_prog_alloc(); prog->nvar = -1; prog->nstmts = isl_union_set_n_set(domains); if (prog->nstmts >= 1) { prog->stmts = (Stmt **)malloc(prog->nstmts * sizeof(Stmt *)); }else{ prog->stmts = NULL; } for (i=0; i<prog->nstmts; i++) { prog->stmts[i] = NULL; } extract_stmts(domains, prog->stmts); for (i=0; i<prog->nstmts; i++) { prog->nvar = PLMAX(prog->nvar, prog->stmts[i]->dim); } if (prog->nstmts >= 1) { Stmt *stmt = prog->stmts[0]; prog->npar = stmt->domain->ncols - stmt->dim - 1; prog->params = (char **) malloc(sizeof(char *)*prog->npar); }else prog->npar = 0; for (i=0; i<prog->npar; i++) { prog->params[i] = NULL; } prog->ndeps = 0; isl_union_map_foreach_map(dependences, &isl_map_count, &prog->ndeps); prog->deps = (Dep **)malloc(prog->ndeps * sizeof(Dep *)); for (i=0; i<prog->ndeps; i++) { prog->deps[i] = pluto_dep_alloc(); } extract_deps(prog->deps, 0, prog->stmts, dependences, OSL_DEPENDENCE_RAW); IF_DEBUG(pluto_prog_print(prog););
/* 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; }
/* 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; }