/* Print the effective grid size as a list of the sizes in each * dimension, from innermost to outermost. */ static __isl_give isl_printer *print_grid_size(__isl_take isl_printer *p, struct ppcg_kernel *kernel) { int i; int dim; dim = isl_multi_pw_aff_dim(kernel->grid_size, isl_dim_set); if (dim == 0) return p; p = isl_printer_print_str(p, "("); for (i = dim - 1; i >= 0; --i) { isl_ast_expr *bound; bound = isl_ast_expr_get_op_arg(kernel->grid_size_expr, 1 + i); p = isl_printer_print_ast_expr(p, bound); isl_ast_expr_free(bound); if (i > 0) p = isl_printer_print_str(p, ", "); } p = isl_printer_print_str(p, ")"); return p; }
/* This function prints the i'th block size multiplied by the i'th grid size, * where i (a parameter to this function) is one of the possible dimensions of * grid sizes and block sizes. * If the dimension of block sizes is not equal to the dimension of grid sizes * the output is calculated as follows: * * Suppose that: * block_sizes[dim1] is the list of blocks sizes and it contains dim1 elements. * grid_sizes[dim2] is the list of grid sizes and it contains dim2 elements. * * The output is: * If (i > dim2) then the output is block_sizes[i] * If (i > dim1) then the output is grid_sizes[i] */ static __isl_give isl_printer *opencl_print_total_number_of_work_items_for_dim( __isl_take isl_printer *p, struct ppcg_kernel *kernel, int i) { int grid_dim, block_dim; isl_pw_aff *bound_grid; grid_dim = isl_multi_pw_aff_dim(kernel->grid_size, isl_dim_set); block_dim = kernel->n_block; if (i < min(grid_dim, block_dim)) { bound_grid = isl_multi_pw_aff_get_pw_aff(kernel->grid_size, i); p = isl_printer_print_str(p, "("); p = isl_printer_print_pw_aff(p, bound_grid); p = isl_printer_print_str(p, ") * "); p = isl_printer_print_int(p, kernel->block_dim[i]); isl_pw_aff_free(bound_grid); } else if (i >= grid_dim) p = isl_printer_print_int(p, kernel->block_dim[i]); else { bound_grid = isl_multi_pw_aff_get_pw_aff(kernel->grid_size, i); p = isl_printer_print_pw_aff(p, bound_grid); isl_pw_aff_free(bound_grid); } return p; }
/* Print a list that represents the total number of work items. The list is * constructed by performing an element-wise multiplication of the block sizes * and the grid sizes. To explain how the list is constructed, suppose that: * block_sizes[dim1] is the list of blocks sizes and it contains dim1 elements. * grid_sizes[dim2] is the list of grid sizes and it contains dim2 elements. * * The output of this function is constructed as follows: * If (dim1 > dim2) then the output is the following list: * grid_sizes[0]*block_sizes[0], ..., grid_sizes[dim2-1]*block_sizes[dim2-1], * block_sizes[dim2], ..., block_sizes[dim1-2], block_sizes[dim1-1]. * * If (dim2 > dim1) then the output is the following list: * grid_sizes[0]*block_sizes[0], ..., grid_sizes[dim1-1] * block_sizes[dim1-1], * grid_sizes[dim1], grid_sizes[dim2-2], grid_sizes[dim2-1]. * * To calculate the total number of work items out of the list constructed by * this function, the user should multiply the elements of the list. */ static __isl_give isl_printer *opencl_print_total_number_of_work_items_as_list( __isl_take isl_printer *p, struct ppcg_kernel *kernel) { int i; int grid_dim, block_dim; grid_dim = isl_multi_pw_aff_dim(kernel->grid_size, isl_dim_set); block_dim = kernel->n_block; if ((grid_dim <= 0) || (block_dim <= 0)) { p = isl_printer_print_str(p, "1"); return p; } for (i = 0; i <= max(grid_dim, block_dim) - 1; i++) { if (i > 0) p = isl_printer_print_str(p, ", "); p = opencl_print_total_number_of_work_items_for_dim(p, kernel, i); } return p; }