Skip to content

Task

A task represents the code executed by a node in the data flow graph. In other languages, a task can be referred to as a job or a filter. A task is defined by its input and output data and the code to execute when triggered. In other words, a task comes with a set of data called sockets (not to be confused with network and system sockets). The sockets model the data that are consumed (input socket) and produced (output socket) by the current task. Finally, the code to execute is stored in a so-called codelet.

A task is a C++ object of the spu::runtime::Task class. The following sections try to give an overview of the most important attributes and methods to facilitate the code understanding.

Main Attributes

std::vector<std::shared_ptr<runtime::Socket>> sockets;
The list of sockets that are attached to this task.

std::vector<std::vector<uint8_t>> out_buffers;
The allocated data of the output sockets of this task. If the autoalloc attribute is set to true (see below) then the data are allocated here, otherwise this vector is left empty.

std::function<int(module::Module &m, runtime::Task& t, const size_t frame_id)> codelet;
The function called by _exec() method (see below), thus dictating the task's behavior. Usually set in the module's constructor and should return a status_t.

std::shared_ptr<runtime::Socket> fake_input_sockets;
Fake input sockets are used when specifying dependencies between tasks directly. Thus, internally, these dependencies are managed through "fake input sockets" that are created on-the-fly over the current task. The data of these sockets are ignored during the codelet execution.

bool autoalloc;
If set to true, let StreamPU allocate and reallocate memory needed by the task. Data are only allocated in the output sockets. By default this attribute is set to true.

bool stats;
If true, records statistics regarding the task's execution, such as the duration. By default this attribute is set to false.

bool fast;
If true, skips can_exec() runtime check, thus, improving performance. Sockets bound to this task will also be set to fast. By default this attribute is set to false.

bool debug;
If set to true, displays the task's sockets data and its status upon execution (on the standard output). By default this attribute is set to false.

module::Module *module;
A pointer to the corresponding module. See the Module section for more information about what is a module.

const std::string name;
A name to identify the task. This name is unique in the module.

Main Methods

const std::vector<int>& exec(const int frame_id = -1, const bool managed_memory = true);
Calls _exec() method, records execution statistics (if stats == true) and prints the debug logs (if debug == true).

void _exec(const int frame_id = -1, const bool managed_memory = true);
Executes the task's codelet and sets the status for this specific call. Called by exec() (see the above method).

bool can_exec() const;
Returns true if all the sockets are associated to an allocated buffer, otherwise returns false. Called by exec() method if fast is set to false, skipped otherwise.

void bind(runtime::Task &t_out, const int priority = -1);
Add a fake input socket to the current task (see above fake_input_sockets attribute) and binds it to the output status socket of the t_out task in parameter. The new socket's datatype and databytes match the output status socket of t_out. fake_input_sockets is always fast. This method has to be manually called by the user.

size_t unbind(runtime::Task &t_out);
Unbinds and deletes the corresponding input socket in the fake_input_sockets attribute. Can be called by Sequence::set_n_frames() or manually by the user.

void reset();
Resets the task's statistics. Not to be confused with Module::reset(). Manually called by the user.