Tiramisu Compiler
tiramisu::buffer Class Reference

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::computationallocate_at (tiramisu::computation &C, tiramisu::var level)
 Indicate when to allocate the buffer (i.e., the schedule). More...
 
tiramisu::computationallocate_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...
 

Detailed Description

A class that represents buffers.

Buffers have two use cases:

  • used to store the results of computations, and
  • used to represent input arguments to functions.

Definition at line 1017 of file core.h.

Constructor & Destructor Documentation

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:

  • Used to store the results of computations, and
  • Used to represent input arguments to functions.

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:

  • tiramisu::a_input: indicates that the buffer is supposed to be passed as input to the function generated by Tiramisu.
  • tiramisu::a_output: indicates that the buffer is supposed to be passed as output to the function generated by Tiramisu. Input an output buffers should be allocated by the user before calling the Tiramisu generated function. Tiramisu does not allocated memory for input and output buffers.
  • tiramisu::a_temporary: this buffer is not supposed to be passed to the function as an argument. It will be allocated automatically by the Tiramisu compiler at the beginning of the function and deallocated at the end of the function. The user can also allocate the buffer "manually" by setting the automatic allocation to false for this buffer.

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.

Member Function Documentation

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

for (i=0; i<N; i++)
for (j=0; j<N; j++)
for (k=0; k<N; k++)
C1;
for (i=0; i<N; i++) // level 0
for (j=0; j<N; j++) // level 1
for (k=0; k<N; k++) // level 2
{
C2;
C3;
}

The following Tiramisu code

tiramisu::computation *C4 = buf0.allocate_at(C2, j);
C4->before(C2, j);

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:

for (i=0; i<N; i++)
for (j=0; j<N; j++)
for (k=0; k<N; k++)
C1;
for (i=0; i<N; i++) // level 0
for (j=0; j<N; j++) // level 1
{
allocate(buf0, buffer_size, buffer_type);
for (k=0; k<N; k++) // level 2
{
C2;
C3;
}
}
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

for (i=0; i<N; i++)
for (j=0; j<N; j++)
for (k=0; k<N; k++)
C1;
for (i=0; i<N; i++) // level 0
for (j=0; j<N; j++) // level 1
for (k=0; k<N; k++) // level 2
{
C2;
C3;
}

The following Tiramisu code

tiramisu::computation *C4 = buf0.allocate_at(C2, j);
C4->before(C2, j);

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:

for (i=0; i<N; i++)
for (j=0; j<N; j++)
for (k=0; k<N; k++)
C1;
for (i=0; i<N; i++) // level 0
for (j=0; j<N; j++) // level 1
{
allocate(buf0, buffer_size, buffer_type);
for (k=0; k<N; k++) // level 2
{
C2;
C3;
}
}
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:

  • tiramisu::a_input: for inputs of the function,
  • tiramisu::a_output: for outputs of the function,
  • tiramisu::a_temporary: for buffers used as temporary buffers within the function (any temporary buffer is allocated automatically by the Tiramisu runtime at the entry of the function and is deallocated at the exit of the function).
bool tiramisu::buffer::get_auto_allocate ( )
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.

void tiramisu::buffer::set_argument_type ( tiramisu::argument_t  type)
protected

Set the type of the argument.

Three possible types exist:

  • a_input: for inputs of the function,
  • a_output: for outputs of the function,
  • a_temporary: for buffers used as temporary buffers within the function (any temporary buffer is allocated automatically by the Tiramisu runtime at the entry of the function and is deallocated at the exit of the function).
void tiramisu::buffer::set_auto_allocate ( bool  auto_allocation)

Set whether the buffer should be allocated automatically.

void tiramisu::buffer::set_dim_size ( int  dim,
int  size 
)
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 ( )

The documentation for this class was generated from the following file: