PIPS
|
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "boolean.h"
#include "arithmetique.h"
#include "vecteur.h"
#include "contrainte.h"
#include "ray_dte.h"
#include "sommet.h"
#include "sg.h"
#include "sc.h"
#include "polyedre.h"
#include "matrix.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "database.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "constants.h"
#include "misc.h"
#include "control.h"
#include "text-util.h"
#include "pipsdbm.h"
#include "resources.h"
#include "properties.h"
#include "effects-simple.h"
Go to the source code of this file.
Data Structures | |
struct | gpu_lna_context |
In modern PIPS programming, all is passed through a context instead of having a global variable. More... | |
Macros | |
#define | COMMA "," |
Loop nests transformation phase for par4all : More... | |
#define | OPENPAREN "(" |
#define | CLOSEPAREN ")" |
Functions | |
static bool | loop_push (loop l, gpu_lna_context *p) |
Push a loop that matches the criterion for annotation. More... | |
static void | loop_annotate (loop l, gpu_lna_context *p) |
Do the real annotation work on previously marked loops bottom-up. More... | |
bool | gpu_loop_nest_annotate_on_statement (statement s) |
annotates loop nests in the following way : More... | |
bool | gpu_loop_nest_annotate (const char *module_name) |
static bool | parallelize_annotated_loop_nest (statement s) |
Callback for gen_recurse Parallelize perfectly nested loop nest, till we reach the magic comment. More... | |
bool | gpu_parallelize_annotated_loop_nest (const string mod_name) |
Parallelize the launcher based on loop nest annotate sentinels. More... | |
bool | clear_annotated_loop_nest (statement s) |
Callback for gen_recurse Remove annotation on a loop nest. More... | |
bool | gpu_clear_annotations_on_loop_nest (const string mod_name) |
Remove all annotations on a loop nest. More... | |
#define CLOSEPAREN ")" |
Definition at line 104 of file loop_nest_annotate.c.
#define COMMA "," |
Loop nests transformation phase for par4all :
gpu_loop_nest_annotate takes a module that is of the form :
typedef float float_t; void p4a_kernel_wrapper_1(float_t save[501][501], float_t space[501][501], int i, int j); void p4a_kernel_launcher_1(float_t save[501][501], float_t space[501][501]) { int i; int j; kernel2: for(i = 0; i <= 100; i += 1) for(j = 0; j <= 200; j += 1) p4a_kernel_wrapper_1(save, space, i+1, j+1); }
and transforms it into :
typedef float float_t; void p4a_kernel_wrapper_1(float_t save[501][501], float_t space[501][501], int i, int j); void p4a_kernel_launcher_1(float_t save[501][501], float_t space[501][501]) { int i; int j; kernel2: Loop nest P4A begin, 2D(200, 100) for(i = 0; i <= 100; i += 1) for(j = 0; j <= 200; j += 1) Loop nest P4A end if (i <= 100 && j <= 200) p4a_kernel_wrapper_1(save, space, i+1, j+1); }
for further generation of CUDA code. } Ansi includes
Newgen includes Pips includes
Definition at line 102 of file loop_nest_annotate.c.
#define OPENPAREN "(" |
Definition at line 103 of file loop_nest_annotate.c.
Callback for gen_recurse Remove annotation on a loop nest.
Definition at line 465 of file loop_nest_annotate.c.
References comment(), empty_comments_p(), statement_comments, and string_undefined.
Referenced by gpu_clear_annotations_on_loop_nest().
Remove all annotations on a loop nest.
mod_name | od_name |
Definition at line 477 of file loop_nest_annotate.c.
References clear_annotated_loop_nest(), gen_null(), gen_recurse, module_statement, PIPS_PHASE_POSTLUDE, PIPS_PHASE_PRELUDE, and statement_domain.
bool gpu_loop_nest_annotate | ( | const char * | module_name | ) |
module_name | odule_name |
Definition at line 406 of file loop_nest_annotate.c.
References gpu_loop_nest_annotate_on_statement(), module_name(), module_statement, PIPS_PHASE_POSTLUDE, and PIPS_PHASE_PRELUDE.
annotates loop nests in the following way :
for(i=0; i<=100; i++) for(j=0; j<=200; j++) foo();
==>
// Loop nest P4A begin,2D(200, 100) for(i=0; i<=100; i++) for(j=0; j<=200; j++) // Loop nest P4A end if (i<=100&&j<=200) foo();
for loops must have been transformed into loops.
mod_name | name of the module |
Initialize context
Annotate the loop nests of the module.
Clean up things: (hasn't it been done previously in loop_annotate?)
Definition at line 383 of file loop_nest_annotate.c.
References expression_undefined, gpu_lna_context::fail_p, gen_context_recurse, gen_free_list(), get_bool_property(), gpu_lna_context::gpu_loop_nest_annotate_parallel_p, gpu_lna_context::guard_expression, gpu_lna_context::inner_loop, gpu_lna_context::inner_reached, gpu_lna_context::l_enclosing_loops, gpu_lna_context::l_number_iter_exp, loop_annotate(), loop_domain, gpu_lna_context::loop_nest_depth, loop_push(), loop_undefined, gpu_lna_context::max_loop_nest_depth, and NIL.
Referenced by gpu_ify_statement(), and gpu_loop_nest_annotate().
Parallelize the launcher based on loop nest annotate sentinels.
mod_name | od_name |
Definition at line 445 of file loop_nest_annotate.c.
References gen_null(), gen_recurse, module_statement, parallelize_annotated_loop_nest(), PIPS_PHASE_POSTLUDE, PIPS_PHASE_PRELUDE, and statement_domain.
|
static |
Do the real annotation work on previously marked loops bottom-up.
We have to select the operators that are different in C and FORTRAN
The first time we enter this function is when we reach the innermost loop nest level.
We are at the innermost loop nest level
First we build the guard to be added to the loop body statement using the enclosing loops upper bounds. And we push on l_number_iter_exp an expression representing the number of iteration of each loop; currently, we do not check that variables modified inside loops are not used in loop bounds expressions. but we take care of loop indices used in deeper loop bounds.
first check if the lower bound depend on enclosing loop indices
We have to clean the list of effect from any "preference" since the next loop modify the references and can make our "preference" invalid
Keep the number of iterations for the generation of the outermost comment
We will have deepest loop size first:
We are now on our way back in the recursion; we do nothing, unless we are at the uppermost level.
Output inner dimension first:
Concatenate the dimension of the innermost loop:
Idem for other dimensions, but do not forget to insert the ', '
Then we add the comment : // Loop nest P4A end
reset context
Definition at line 153 of file loop_nest_annotate.c.
References AND_OPERATOR_NAME, asprintf, buf, C_AND_OPERATOR_NAME, C_LESS_OR_EQUAL_OPERATOR_NAME, c_loop(), CLOSEPAREN, COMMA, concatenate(), CONS, copy_expression(), effects_read_variable_p(), entity_intrinsic(), EXPRESSION, expression_constant_p(), expression_to_int(), expression_to_string(), expression_undefined, expression_undefined_p, gpu_lna_context::fail_p, FOREACH, free(), free_expression(), gen_free_list(), gen_full_free_list(), gen_get_ancestor(), gen_length(), get_comment_sentinel(), get_prettyprint_language_tag(), gpu_lna_context::guard_expression, gpu_lna_context::inner_loop, int_to_expression(), is_language_c, gpu_lna_context::l_enclosing_loops, gpu_lna_context::l_number_iter_exp, LESS_OR_EQUAL_OPERATOR_NAME, LOOP, loop_body, loop_index, gpu_lna_context::loop_nest_depth, loop_range, loop_undefined, make_empty_block_statement(), make_max_expression(), make_min_expression(), make_op_exp(), make_reference(), make_test(), MakeBinaryCall(), gpu_lna_context::max_loop_nest_depth, MINUS_OPERATOR_NAME, NIL, OPENPAREN, pips_debug, pips_user_warning, PLUS_OPERATOR_NAME, POP, proper_effects_of_expression(), range_increment, range_lower, range_upper, reference_to_expression(), remove_preferences(), replace_entity_by_expression(), simplify_expression(), statement_comments, statement_domain, strdup(), and test_to_statement.
Referenced by gpu_loop_nest_annotate_on_statement().
|
static |
Push a loop that matches the criterion for annotation.
This is the first loop we met in this loop nest
Let's compute the loop_nest_depth
this loop does not belong to the perfectly nested loops
Definition at line 126 of file loop_nest_annotate.c.
References CONS, depth_of_parallel_perfect_loop_nest(), depth_of_perfect_loop_nest(), gen_get_ancestor(), gen_nconc(), gpu_lna_context::gpu_loop_nest_annotate_parallel_p, gpu_lna_context::l_enclosing_loops, LOOP, gpu_lna_context::loop_nest_depth, loop_parallel_p(), gpu_lna_context::max_loop_nest_depth, NIL, and statement_domain.
Referenced by gpu_loop_nest_annotate_on_statement().
Callback for gen_recurse Parallelize perfectly nested loop nest, till we reach the magic comment.
FIXME : should detect the beginning sentinel, but since we use it in launcher, it has no importance at that time
Definition at line 426 of file loop_nest_annotate.c.
References comment(), empty_comments_p(), execution_tag, find_first_statement_comment(), is_execution_parallel, loop_body, loop_execution, statement_loop(), and statement_loop_p().
Referenced by gpu_parallelize_annotated_loop_nest().