Tiramisu Compiler
|
A class to represent functions in Tiramisu. More...
#include <core.h>
Public Member Functions | |
function (std::string name) | |
Construct a function called name . More... | |
void | add_context_constraints (const std::string &new_context) |
Add a set of constraints to the context of the program. More... | |
void | align_schedules () |
Align the schedules of all the computations of this function. More... | |
void | allocate_and_map_buffers_automatically () |
For each computation, allocate a buffer and map the computation to that buffer. More... | |
void | compute_bounds () |
Compute the bounds of each computation. More... | |
void | dump (bool exhaustive) const |
Dump the function on standard output (dump most of the fields of tiramisu::function). More... | |
void | dump_dep_graph () |
Dump the graph of dependences between computations. More... | |
void | dump_halide_stmt () const |
Dump a Halide stmt that represents the function. More... | |
void | dump_iteration_domain () const |
Dump the iteration domain of the function. More... | |
void | dump_schedule () const |
Dump the schedules of the computations of the function. More... | |
void | dump_sched_graph () |
Dumps the graph of scheduling relations set by the higher level scheduling functions (e.g. More... | |
void | dump_time_processor_domain () const |
Dump (on stdout) the time processor domain of the function. More... | |
void | dump_trimmed_time_processor_domain () const |
Dump (on stdout) the trimmed time processor domain of the function. More... | |
void | gen_c_code () const |
Generate C code and print it on stdout. More... | |
void | gen_halide_obj (const std::string &obj_file_name, Halide::Target::OS os, Halide::Target::Arch arch, int bits) const |
Generate an object file that contains the compiled function. More... | |
void | gen_halide_obj (const std::string &obj_file_name) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | gen_halide_stmt () |
Generate a Halide stmt that represents the function. More... | |
void | gen_cuda_stmt () |
void | gen_isl_ast () |
Generate an isl AST that represents the function. More... | |
void | gen_time_space_domain () |
Generate the time-space domain of the function. More... | |
void | set_arguments (const std::vector< tiramisu::buffer * > &buffer_vec) |
Set the arguments of the function. More... | |
void | codegen (const std::vector< tiramisu::buffer * > &arguments, const std::string obj_filename, const bool gen_cuda_stmt=false) |
Wrapper for all the functions required to run code generation of a tiramisu program. More... | |
void | set_context_set (const std::string &context) |
Set the context of the function. More... | |
void | set_context_set (isl_set *context) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function takes an ISL set as input. More... | |
Protected Member Functions | |
void | add_buffer (std::pair< std::string, tiramisu::buffer * > buf) |
Add a buffer to the function. More... | |
void | add_computation (computation *cpt) |
Add a computation to the function. More... | |
void | add_gpu_block_dimensions (std::string stmt_name, int dim0, int dim1=-1, int dim2=-1) |
Tag the dimensions dim0 , dim1 and dim2 of the computation computation_name to be mapped to GPU blocks. More... | |
void | add_gpu_thread_dimensions (std::string stmt_name, int dim0, int dim1=-1, int dim2=-1) |
Tag the dimensions dim0 , dim1 and dim2 of the computation computation_name to be mapped to GPU threads. More... | |
void | add_invariant (tiramisu::constant param) |
Add an invariant to the function. More... | |
void | add_iterator_name (const std::string &it_name) |
Add an iterator to the function. More... | |
isl_union_map * | compute_dep_graph () |
Compute the graph of dependences between the computations of the function. More... | |
const std::vector< tiramisu::buffer * > & | get_arguments () const |
Get the arguments of the function. More... | |
const std::map< std::string, tiramisu::buffer * > & | get_buffers () const |
Return a map that represents the buffers of the function. More... | |
const std::vector< computation * > & | get_computations () const |
Return a vector of the computations of the function. More... | |
std::vector< computation * > | get_computation_by_name (std::string str) const |
Return the computation of the function that has the name str . More... | |
std::string | get_gpu_block_iterator (const std::string &comp, int lev0) const |
Return a string representing the name of the GPU block iterator at dimension lev0 . More... | |
std::string | get_gpu_thread_iterator (const std::string &comp, int lev0) const |
Return a string representing the name of the GPU thread iterator at dimension lev0 . More... | |
isl_ctx * | get_isl_ctx () const |
Return the isl_ctx associated with this function. More... | |
Halide::Internal::Stmt | get_halide_stmt () const |
Return the Halide statement that represents the whole function. More... | |
isl_ast_node * | get_isl_ast () const |
Return an ISL AST that represents this function. More... | |
isl_union_set * | get_iteration_domain () const |
Return the union of all the iteration domains of the computations of the function. More... | |
const std::vector< std::string > & | get_iterator_names () const |
Get the iterator names of the function. More... | |
const std::string & | get_name () const |
Get the name of the function. More... | |
isl_set * | get_program_context () const |
Return a set that represents the parameters of the function (an ISL set that represents the parameters and constraints over the parameters of the functions, a parameter is an invariant of the function). More... | |
isl_union_map * | get_schedule () const |
Return the union of all the schedules of the computations of the function. More... | |
isl_union_map * | get_trimmed_schedule () const |
Return the union of all the trimmed schedules of the function. More... | |
isl_union_set * | get_time_processor_domain () const |
Return the union of time-processor domains of each computation in the function. More... | |
int | get_vector_length (const std::string &comp, int lev) const |
If the computation comp is vectorized, return its vector length at the loop level lev . More... | |
bool | is_sched_graph_tree () |
Return true if the usage of high level scheduling comments is valid; i.e. More... | |
void | gen_ordering_schedules () |
Modify the schedules of the computations of this function to reflect the order specified using the high level scheduling commands. More... | |
void | set_iterator_names (const std::vector< std::string > &it_names) |
Set the iterator names of the function. More... | |
bool | should_map_to_gpu_block (const std::string &comp, int lev0) const |
Return true if the computation comp should be mapped to GPU block at the loop levels lev0 . More... | |
bool | should_map_to_gpu_thread (const std::string &comp, int lev0) const |
Return true if the computation comp should be mapped to GPU thread at the loop levels lev0 . More... | |
bool | should_parallelize (const std::string &comp, int lev) const |
Return true if the computation comp should be parallelized at the loop level lev . More... | |
bool | should_unroll (const std::string &comp, int lev) const |
Return true if the computation comp should be unrolled at the loop level lev . More... | |
bool | should_vectorize (const std::string &comp, int lev) const |
Return true if the computation comp should be vectorized at the loop level lev . More... | |
bool | should_distribute (const std::string &comp, int lev) const |
Return true if the computation comp should be distributed at the loop level lev . More... | |
bool | needs_rank_call () const |
This computation requires a call to the MPI_Comm_rank function. More... | |
void | lift_mpi_comp (tiramisu::computation *comp) |
Lift certain computations for distributed execution to function calls. More... | |
void | lift_dist_comps () |
Lift certain computations for distributed execution to function calls. More... | |
const std::vector< tiramisu::constant > & | get_invariants () const |
Return a vector representing the invariants of the function (symbolic constants or variables that are invariant to the function i.e. More... | |
const std::vector< std::string > | get_invariant_names () const |
Return a vector representing the invariants of the function (symbolic constants or variables that are invariant to the function i.e. More... | |
Protected Attributes | |
std::vector< tiramisu::computation * > | automatically_allocated |
Keeps track of allocation computations created using allocate_and_map_buffer_automatically() to schedule them during gen_ordering_schedules. More... | |
std::unordered_map< tiramisu::computation *, std::unordered_map< tiramisu::computation *, int > > | sched_graph |
Stores all high level scheduling instructions between computations; i.e. More... | |
std::unordered_map< tiramisu::computation *, std::unordered_map< tiramisu::computation *, int > > | sched_graph_reversed |
Same as sched_graph, except in reverse order (from after to before). More... | |
std::unordered_set< tiramisu::computation * > | starting_computations |
The set of all computations that have no computation scheduled before them. More... | |
bool | use_low_level_scheduling_commands |
A boolean set to true if low level scheduling was used in the program. More... | |
A class to represent functions in Tiramisu.
A function in Tiramisu is composed of a set of computations (tiramisu::computation).
tiramisu::function::function | ( | std::string | name | ) |
Construct a function called name
.
Function names should not start with _ (an underscore). Names starting with _ are reserved names.
|
protected |
Add a buffer to the function.
The buffers of the function are either:
|
protected |
Add a computation to the function.
The order in which computations are added to the function is not important. The order of execution is specified using the schedule. This doesn't allow computations with duplicate names.
void tiramisu::function::add_context_constraints | ( | const std::string & | new_context | ) |
Add a set of constraints to the context of the program.
This command is useful for providing constraints over the constants used within a tiramisu function. The context of a function is represented as an ISL set that represents constraints over the parameters of the function (a parameter of a function is a constant used in that function).
For example, if the constants M and N are known to be positive, it is beneficial to provide such an information to the Tiramisu compiler as follows: f.add_context_constraints("[N,M]->{: M>0 and N>0}"); This context set indicates that the two parameters N and M are strictly positive in the function f.
new_context
should have the same space as the context set. This call intersects the set new_context
(input) with the context of the function.
|
protected |
Tag the dimensions dim0
, dim1
and dim2
of the computation computation_name
to be mapped to GPU blocks.
The dimension 0 represents the outermost loop level (it corresponds to the leftmost dimension in the iteration space).
If the user does not want to tag dim1
or dim2
, he can leave their values to default value (i.e., -1). They will not be tagged.
For example
add_gpu_block_dimensions("S0", 1, 2);
Will tag the dimensions 1 and 2 to be transformed to GPU blocks.
|
protected |
Tag the dimensions dim0
, dim1
and dim2
of the computation computation_name
to be mapped to GPU threads.
The dimension 0 represents the outermost loop level (it corresponds to the leftmost dimension in the iteration space).
If the user does not want to tag dim1
or dim2
, he can leave their values to default value (i.e., -1). They will not be tagged.
For example
add_gpu_block_dimensions("S0", 1, -1, -1);
Will tag the dimension 1 to be transformed to GPU threads.
|
protected |
Add an invariant to the function.
|
protected |
Add an iterator to the function.
void tiramisu::function::align_schedules | ( | ) |
Align the schedules of all the computations of this function.
This method applies to the schedule of each computation in the function. It makes the dimensions of the ranges of all the schedules equal. This is done by adding dimensions equal to 0 to the range of each schedule. This function is called automatically when gen_isl_ast() or gen_time_processor_domain() are called.
void tiramisu::function::allocate_and_map_buffers_automatically | ( | ) |
For each computation, allocate a buffer and map the computation to that buffer.
For each computation in the function:
void tiramisu::function::codegen | ( | const std::vector< tiramisu::buffer * > & | arguments, |
const std::string | obj_filename, | ||
const bool | gen_cuda_stmt = false |
||
) |
Wrapper for all the functions required to run code generation of a tiramisu program.
void tiramisu::function::compute_bounds | ( | ) |
Compute the bounds of each computation.
Computing the bounds of each computation means computing the constraints over the iteration domains of each computation in the function.
In order to deduce bounds, Tiramisu first identifies the final consumers in the function (i.e., computations that do not have any consumer). Then, it propagates the bounds over the final consumers to their producers. The bounds of each consumer are used to deduce the bounds over its producer.
To take benefit of bound inference, the user can declare computations without providing constraints on their iteration domains. For example the user can declare the following computations (the left side is the iteration domain, while the right side is the expression attached to each computation)
The user needs only to provide constraints over the domains of the last computations (last consumers), and Tiramisu will propagate these constraints to all the chain of computations that produce for those consumers. In the previous example, constraints over the iteration domain were only provided for the last consumer "D[i]" and no constraints were provided for the other computations. Bound inference would deduce the constraints for the computations A[i], B[i] and C[i].
Note that bound inference is not possible if you have multiple definitions of the same computation. For example, if you have multiple definitions of the same computations, in such a case the user should provide constraints of the iteration domain of the computation. Example:
In this case, constraints over the computations defining C[i] should be provided.
|
protected |
Compute the graph of dependences between the computations of the function.
Example
C[0] = 0 D[1] = C[0] D[2] = C[0] {C[0] -> D[1]; C[0]->D[2]}
void tiramisu::function::dump | ( | bool | exhaustive | ) | const |
Dump the function on standard output (dump most of the fields of tiramisu::function).
This is mainly useful for debugging. If exhaustive
is set to true, all the fields of the function class are printed.
void tiramisu::function::dump_dep_graph | ( | ) |
Dump the graph of dependences between computations.
The graph of dependences is a union of maps (relations) from producers to consumers.
void tiramisu::function::dump_halide_stmt | ( | ) | const |
Dump a Halide stmt that represents the function.
tiramisu::function::gen_halide_stmt should be called before calling this function.
void tiramisu::function::dump_iteration_domain | ( | ) | const |
Dump the iteration domain of the function.
This is mainly useful for debugging.
void tiramisu::function::dump_sched_graph | ( | ) |
Dumps the graph of scheduling relations set by the higher level scheduling functions (e.g.
after, before, compute_at...).
This is mainly useful for debugging. This function can be called at any point during scheduling.
void tiramisu::function::dump_schedule | ( | ) | const |
Dump the schedules of the computations of the function.
This function is mainly useful for debugging. See tiramisu::computations::set_low_level_schedule for details about the schedule.
void tiramisu::function::dump_time_processor_domain | ( | ) | const |
Dump (on stdout) the time processor domain of the function.
The time-processor domain should be generated using tiramisu::function::gen_time_processor_domain before calling this function. This is mainly useful for debugging.
void tiramisu::function::dump_trimmed_time_processor_domain | ( | ) | const |
Dump (on stdout) the trimmed time processor domain of the function.
The time-processor domain should be generated using tiramisu::function::gen_time_processor_domain before calling this function. This is mainly useful for debugging. The difference between the time-processor domain and the trimmed time-processor domain is that the trimmed one does not have the duplicate dimension. We remove it before printing. The trimmed time-processor domain is the domain used for code generation.
void tiramisu::function::gen_c_code | ( | ) | const |
Generate C code and print it on stdout.
Currently C code code generation is very basic and does not support many features compared to the Halide code generator. Use this for debugging only.
void tiramisu::function::gen_cuda_stmt | ( | ) |
void tiramisu::function::gen_halide_obj | ( | const std::string & | obj_file_name, |
Halide::Target::OS | os, | ||
Halide::Target::Arch | arch, | ||
int | bits | ||
) | const |
Generate an object file that contains the compiled function.
This function relies on Halide to generate the object file.
obj_file_name
indicates the name of the generated file.
os
indicates the target operating system (Halide::Target::OS).
arch
indicates the architecture of the target (the instruction set).
bits
indicate the bit-width of the target machine. must be 0 for unknown, or 32 or 64. For a full list of supported values for os
and arch
please check the documentation of Halide::Target (http://halide-lang.org/docs/struct_halide_1_1_target.html). If the machine parameters are not supplied, Halide detects the parameters of the host machine automatically.
void tiramisu::function::gen_halide_obj | ( | const std::string & | obj_file_name | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void tiramisu::function::gen_halide_stmt | ( | ) |
Generate a Halide stmt that represents the function.
void tiramisu::function::gen_isl_ast | ( | ) |
Generate an isl AST that represents the function.
|
protected |
Modify the schedules of the computations of this function to reflect the order specified using the high level scheduling commands.
Commands like .after() and .before() do not directly modify the schedules but rather modify the sched_graph graph.
void tiramisu::function::gen_time_space_domain | ( | ) |
Generate the time-space domain of the function.
In this representation, the logical time of execution and the processor where the computation will be executed are both specified.
|
protected |
Get the arguments of the function.
|
protected |
Return a map that represents the buffers of the function.
The buffers of the function are buffers that are either passed to the function as arguments or are buffers that are declared and allocated within the function itself. The names of the buffers are used as a key for the map.
|
protected |
Return the computation of the function that has the name str
.
|
protected |
Return a vector of the computations of the function.
The order of the computations in the vector does not have any effect on the actual order of execution of the computations. The order of execution of computations is specified through the schedule.
|
protected |
Return a string representing the name of the GPU block iterator at dimension lev0
.
This function only returns a non-empty string if the computation comp
is mapped to a GPU block at the dimension lev0
.
|
protected |
Return a string representing the name of the GPU thread iterator at dimension lev0
.
This function only returns a non-empty string if the computation comp
is mapped to a GPU thread at the dimension lev0
.
|
protected |
Return the Halide statement that represents the whole function.
The Halide statement is generated by the code generator. This function should not be called before calling the code generator.
|
protected |
Return a vector representing the invariants of the function (symbolic constants or variables that are invariant to the function i.e.
do not change their value during the execution of the function).
get_invariant_names() returns the names of the variants.
|
protected |
Return a vector representing the invariants of the function (symbolic constants or variables that are invariant to the function i.e.
do not change their value during the execution of the function).
get_invariant_names() returns the names of the variants.
|
protected |
Return an ISL AST that represents this function.
This function itself does not generate the ISL AST, it just returns it if it already exists. The function gen_isl_ast() should be called before calling this function.
|
protected |
Return the isl_ctx associated with this function.
This is an ISL specific object required when calling certain ISL functions. It does not represent the set of parameters of the function (which should be retrieved by calling get_program_context()).
|
protected |
Return the union of all the iteration domains of the computations of the function.
|
protected |
Get the iterator names of the function.
|
protected |
Get the name of the function.
|
protected |
Return a set that represents the parameters of the function (an ISL set that represents the parameters and constraints over the parameters of the functions, a parameter is an invariant of the function).
This set is also known as the context of the program. An example of a context set is the following: "[N,M]->{: M>0 and N>0}" This context set indicates that the two parameters N and M are strictly positive.
|
protected |
Return the union of all the schedules of the computations of the function.
|
protected |
Return the union of time-processor domains of each computation in the function.
In the time-processor representation, the logical time of execution and the processor where the computation will be executed are both specified.
|
protected |
Return the union of all the trimmed schedules of the function.
A trimmed schedule is the schedule without the duplication dimension (the schedule dimension used to indicate duplicate computations).
|
protected |
If the computation comp
is vectorized, return its vector length at the loop level lev
.
|
protected |
Return true if the usage of high level scheduling comments is valid; i.e.
if the scheduling relations formed using before, after, compute_at, etc.. form a tree.
More specifically, it verifies that:
|
protected |
Lift certain computations for distributed execution to function calls.
|
protected |
Lift certain computations for distributed execution to function calls.
|
protected |
This computation requires a call to the MPI_Comm_rank function.
void tiramisu::function::set_arguments | ( | const std::vector< tiramisu::buffer * > & | buffer_vec | ) |
Set the arguments of the function.
The arguments of the function are provided as a vector of pointers to buffers. Each buffer represents an argument to the function. During code generation, the arguments in the vector will become the arguments of the generated function (with the order of their appearance in the vector).
void tiramisu::function::set_context_set | ( | const std::string & | context | ) |
Set the context of the function.
A context is an ISL set that represents constraints over the parameters of the functions (a parameter is an invariant variable for the function). An example of a context set is the following: "[N,M]->{: M>0 and N>0}" This context set indicates that the two parameters N and M are strictly positive.
This function takes a string that represents and ISL set.
void tiramisu::function::set_context_set | ( | isl_set * | context | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This function takes an ISL set as input.
|
protected |
Set the iterator names of the function.
This function overrides any previously set iterator names.
|
protected |
Return true if the computation comp
should be distributed at the loop level lev
.
|
protected |
Return true if the computation comp
should be mapped to GPU block at the loop levels lev0
.
|
protected |
Return true if the computation comp
should be mapped to GPU thread at the loop levels lev0
.
|
protected |
Return true if the computation comp
should be parallelized at the loop level lev
.
|
protected |
Return true if the computation comp
should be unrolled at the loop level lev
.
|
protected |
Return true if the computation comp
should be vectorized at the loop level lev
.
|
protected |
|
protected |
Stores all high level scheduling instructions between computations; i.e.
if a user calls for example c2.after(c1, L), sched_graph[&c1] would contain the key &c2, and sched_graph[&c1][&c2] = L. At the end of scheduling, the graph should respect the following rules:
|
protected |
|
protected |
|
protected |