Skip to content

Module

A module is a container of tasks. It contains the tasks themselves and their inner data. Inner data can be useful to avoid useless buffers re-allocations each time a task is executed, or a to contain a state that is updated each time a task is triggered. Multiple tasks can be grouped into one module and can share data through the common module (as opposed to the use of sockets). By definition,

  • a stateless task is a task that does not have any inner data (see module::Stateless class),
  • a stateful task is a task that have inner data and, thus, a task that need to be part of a module.

Each time we need to create a stateful task, we will create a new C++ class that inherit from the spu::module::Module class. The Module class provides protected methods to create new tasks and public methods to manipulate the module instances.

Main Attributes

std::vector<std::shared_ptr<runtime::Task>> tasks;
The tasks list of the current module. All the tasks in the vector are allocated (no nullptr).

std::vector<std::shared_ptr<runtime::Task>> tasks_with_nullptr;
The tasks list of the current module where the tasks have a fixed position in the vector. This is useful when a task is conditionally created. In the case of a task that is not created in the current module, its value is set to nullptr.

size_t n_frames;
Number of frames/streams to process each time a task is executed. For instance, if n_frames == 2, all the tasks of the current module will process 2 frames each time they are triggered.

std::string name;
Name of the Module. This name is the same for all the instances of one class.

std::string short_name;
Short name of the Module. This name is the same for all the instances of one class.

std::string custom_name;
Custom name of the Module. This name can be redefined by the user for each instance.

Main Protected Methods

void set_name(const std::string &name);
Sets the module name.

void set_short_name(const std::string &short_name);
Sets the module short name.

runtime::Task& create_task(const std::string &name, const int id = -1);
Creates a new task, two tasks cannot share the same name.

template <typename T>
size_t create_socket_in(runtime::Task& task, const std::string &name, const size_t n_elmts);
Creates an input socket over a given task.

template <typename T>
size_t create_socket_out(runtime::Task& task, const std::string &name, const size_t n_elmts);
Creates an output socket over a given task.

template <typename T>
size_t create_socket_fwd(runtime::Task& task, const std::string &name, const size_t n_elmts);
Creates a forward socket over a given task.

void create_codelet(runtime::Task& task, std::function<int(module::Module &m, runtime::Task &t, onst size_t frame_id)> codelet);
Creates the codelet of the given task.

Main Public Methods

size_t get_n_frames() const;
Returns the number of frames to process in this Module.

void set_n_frames(const size_t n_frames);
Sets the number of frames to process each time a task is executed.

const std::string& get_name() const;
Returns the module name.

const std::string& get_short_name() const;
Returns the module short name.

void set_custom_name(const std::string &custom_name);
Sets the module custom name (each instance can have a different custom name).

const std::string& get_custom_name() const;
Gets the custom name.

runtime::Socket& operator[](const std::string &tsk_sck);
Returns the socket if it exists. The expected string format is "task_name::socket_name".

runtime::Task& operator()(const std::string &tsk_name);
Returns the task if it exists. The input string has to match an existing task name in this module.