Tiramisu Compiler
|
A class that represents buffers. More...
#include <core.h>
Public Member Functions | |
buffer (std::string name, std::vector< tiramisu::expr > dim_sizes, tiramisu::primitive_t type, tiramisu::argument_t argt, tiramisu::function *fct=global::get_implicit_function()) | |
Create a tiramisu buffer. More... | |
void | dump (bool exhaustive) const |
Dump the function on standard output. More... | |
tiramisu::argument_t | get_argument_type () const |
If this buffer is an argument to a tiramisu::function, return the type of the argument. More... | |
const std::string & | get_name () const |
Return the name of the buffer. More... | |
int | get_n_dims () const |
Get the number of dimensions of the buffer. More... | |
tiramisu::primitive_t | get_elements_type () const |
Return the type of the elements of the buffer. More... | |
const std::vector< tiramisu::expr > & | get_dim_sizes () const |
Return the sizes of the dimensions of the buffer. More... | |
void | set_auto_allocate (bool auto_allocation) |
Set whether the buffer should be allocated automatically. More... | |
bool | has_constant_extents () |
Return true if all extents of the buffer are literal integer contants (e.g., 4, 10, 100, ...). More... | |
const bool | is_allocated () const |
Return true if a statement that allocates the buffer was already generated. More... | |
void | mark_as_allocated () |
Mark an array as already allocated. More... | |
void | tag_gpu_global () |
void | tag_gpu_register () |
Tag the buffer as located in the GPU register memory. More... | |
void | tag_gpu_shared () |
void | tag_gpu_local () |
void | tag_gpu_constant () |
tiramisu::computation * | allocate_at (tiramisu::computation &C, tiramisu::var level) |
Indicate when to allocate the buffer (i.e., the schedule). More... | |
tiramisu::computation * | allocate_at (tiramisu::computation &C, int level) |
Indicate when to allocate the buffer (i.e., the schedule). More... | |
Protected Member Functions | |
void | set_argument_type (tiramisu::argument_t type) |
Set the type of the argument. More... | |
bool | get_auto_allocate () |
Return whether the buffer should be allocated automatically. More... | |
void | set_dim_size (int dim, int size) |
Set the size of a dimension of the buffer. More... | |
A class that represents buffers.
Buffers have two use cases:
tiramisu::buffer::buffer | ( | std::string | name, |
std::vector< tiramisu::expr > | dim_sizes, | ||
tiramisu::primitive_t | type, | ||
tiramisu::argument_t | argt, | ||
tiramisu::function * | fct = global::get_implicit_function() |
||
) |
Create a tiramisu buffer.
A Tiramisu buffer is equivalent to an array in C.
Buffers have two use cases:
name
is the name of the buffer.
dim_sizes
is a vector of tiramisu expressions that represent the size of each dimension in the buffer. Assuming we want to declare the buffer buf[N0][N1][N2], then the vector of sizes should be {N0, N1, N2}. Buffer dimensions in Tiramisu have the same semantics as in C/C++.
type
is the type of the elements of the buffer. It must be a primitive type (i.e. p_uint8, p_uint16, ...). Possible types are declared in tiramisu::primitive_t (in type.h).
argt
indicates whether this buffer is an input or an output buffer and whether it should be allocated automatically by Tiramisu. The possible types (tiramisu::argument_t) are:
fct
is a pointer to a Tiramisu function where the buffer is declared or used. If this argument is not provided (which is the common case), the function that was created automatically during Tiramisu initialization will be used (we call that function the "implicit function").
Buffer names should not start with _ (an underscore). Names starting with _ are reserved names.
tiramisu::computation* tiramisu::buffer::allocate_at | ( | tiramisu::computation & | C, |
tiramisu::var | level | ||
) |
Indicate when to allocate the buffer (i.e., the schedule).
The buffer is allocated in the same loop of the computation C
at the loop level level
(but the order between the two is not specified).
For example, let's assume that buf0 is a buffer, and let's assume that we have three computations C1, C2 and C3 scheduled as follow
The following Tiramisu code
would allocate buf0 in the loop surrounding C2 at the loop level 0. The allocation computation is called C4, where C4 is scheduled to execute before C2 at the loop level 1. The generated code would look like the following code:
tiramisu::computation* tiramisu::buffer::allocate_at | ( | tiramisu::computation & | C, |
int | level | ||
) |
Indicate when to allocate the buffer (i.e., the schedule).
The buffer is allocated in the same loop of the computation C
at the loop level level
(but the order between the two is not specified).
For example, let's assume that buf0 is a buffer, and let's assume that we have three computations C1, C2 and C3 scheduled as follow
The following Tiramisu code
would allocate buf0 in the loop surrounding C2 at the loop level 0. The allocation computation is called C4, where C4 is scheduled to execute before C2 at the loop level 1. The generated code would look like the following code:
void tiramisu::buffer::dump | ( | bool | exhaustive | ) | const |
Dump the function on standard output.
This functions dumps most of the fields of the buffer class but not all of them. It is mainly useful for debugging. If exhaustive
is set to true, all the fields of the buffer class are printed.
tiramisu::argument_t tiramisu::buffer::get_argument_type | ( | ) | const |
If this buffer is an argument to a tiramisu::function, return the type of the argument.
Three possible types exist:
|
protected |
Return whether the buffer should be allocated automatically.
const std::vector<tiramisu::expr>& tiramisu::buffer::get_dim_sizes | ( | ) | const |
Return the sizes of the dimensions of the buffer.
tiramisu::primitive_t tiramisu::buffer::get_elements_type | ( | ) | const |
Return the type of the elements of the buffer.
int tiramisu::buffer::get_n_dims | ( | ) | const |
Get the number of dimensions of the buffer.
const std::string& tiramisu::buffer::get_name | ( | ) | const |
Return the name of the buffer.
bool tiramisu::buffer::has_constant_extents | ( | ) |
Return true if all extents of the buffer are literal integer contants (e.g., 4, 10, 100, ...).
const bool tiramisu::buffer::is_allocated | ( | ) | const |
Return true if a statement that allocates the buffer was already generated.
void tiramisu::buffer::mark_as_allocated | ( | ) |
Mark an array as already allocated.
|
protected |
Set the type of the argument.
Three possible types exist:
void tiramisu::buffer::set_auto_allocate | ( | bool | auto_allocation | ) |
Set whether the buffer should be allocated automatically.
|
protected |
Set the size of a dimension of the buffer.
void tiramisu::buffer::tag_gpu_constant | ( | ) |
void tiramisu::buffer::tag_gpu_global | ( | ) |
void tiramisu::buffer::tag_gpu_local | ( | ) |
void tiramisu::buffer::tag_gpu_register | ( | ) |
Tag the buffer as located in the GPU register memory.
The buffer needs to have a unique dimension of size 1 (i.e. needs to be a scalar).
void tiramisu::buffer::tag_gpu_shared | ( | ) |