LCOV - code coverage report
Current view: top level - include/Runtime/Task - Task.hpp (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 1 1 100.0 %
Date: 2025-07-17 17:04:07 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*!
       2             :  * \file
       3             :  * \brief Class runtime::Task.
       4             :  */
       5             : #ifndef TASK_HPP_
       6             : #define TASK_HPP_
       7             : 
       8             : #include <chrono>
       9             : #include <cstddef>
      10             : #include <functional>
      11             : #include <limits>
      12             : #include <memory>
      13             : #include <string>
      14             : #include <typeindex>
      15             : #include <unordered_map>
      16             : #include <vector>
      17             : 
      18             : #include "Tools/Interface/Interface_clone.hpp"
      19             : #include "Tools/Interface/Interface_reset.hpp"
      20             : #include "Tools/System/memory.hpp"
      21             : 
      22             : namespace spu
      23             : {
      24             : namespace module
      25             : {
      26             : class Module;
      27             : }
      28             : 
      29             : namespace tools
      30             : {
      31             : class Buffer_allocator;
      32             : };
      33             : 
      34             : namespace runtime
      35             : {
      36             : class Socket;
      37             : class Pipeline;
      38             : 
      39             : enum status_t : int
      40             : {
      41             :     SUCCESS = 0,
      42             :     FAILURE = 1,
      43             :     FAILURE_STOP = -1,
      44             :     UNKNOWN = -2
      45             : };
      46             : 
      47             : enum class socket_t : uint8_t
      48             : {
      49             :     SIN,
      50             :     SOUT,
      51             :     SFWD
      52             : };
      53             : 
      54             : enum class datatype_t : uint8_t
      55             : {
      56             :     F64,
      57             :     F32,
      58             :     S64,
      59             :     S32,
      60             :     S16,
      61             :     S8,
      62             :     U64,
      63             :     U32,
      64             :     U16,
      65             :     U8
      66             : };
      67             : 
      68             : static std::unordered_map<int, std::string> status_t_to_string = { { 0, "SUCCESS" },
      69             :                                                                    { 1, "FAILURE" },
      70             :                                                                    { -1, "FAILURE_STOP" },
      71             :                                                                    { -2, "UNKNOWN" },
      72             :                                                                    { std::numeric_limits<int>::min(), "SKIPPED" } };
      73             : 
      74             : class Task
      75             :   : public tools::Interface_clone
      76             :   , public tools::Interface_reset
      77             : {
      78             : #ifndef DOXYGEN_SHOULD_SKIP_THIS
      79             :     friend Socket;
      80             :     friend Pipeline;
      81             :     friend module::Module;
      82             :     friend tools::Buffer_allocator;
      83             : #endif
      84             : 
      85             :   protected:
      86             :     module::Module* module;
      87             :     const std::string name;
      88             :     bool stats;
      89             :     bool fast;
      90             :     bool debug;
      91             :     bool outbuffers_allocated;
      92             :     bool debug_hex;
      93             :     bool replicable;
      94             :     int32_t debug_limit;
      95             :     uint8_t debug_precision;
      96             :     int32_t debug_frame_max;
      97             :     std::function<int(module::Module& m, Task& t, const size_t frame_id)> codelet;
      98             :     size_t n_input_sockets;
      99             :     size_t n_output_sockets;
     100             :     size_t n_fwd_sockets;
     101             : 
     102             :     std::vector<int> status;
     103             : 
     104             :     // stats
     105             :     uint32_t n_calls;
     106             :     std::chrono::nanoseconds duration_total;
     107             :     std::chrono::nanoseconds duration_min;
     108             :     std::chrono::nanoseconds duration_max;
     109             : 
     110             :     std::vector<std::string> timers_name;
     111             :     std::vector<uint32_t> timers_n_calls;
     112             :     std::vector<std::chrono::nanoseconds> timers_total;
     113             :     std::vector<std::chrono::nanoseconds> timers_min;
     114             :     std::vector<std::chrono::nanoseconds> timers_max;
     115             : 
     116             :     Socket* last_input_socket;
     117             : 
     118             :     // precomputed values to speedup the task execution
     119             :     std::vector<int8_t*> sockets_dataptr_init;
     120             :     std::vector<size_t> sockets_databytes_per_frame;
     121             :     std::vector<std::vector<int8_t>> sockets_data;
     122             : 
     123             :   public:
     124             :     std::vector<std::shared_ptr<Socket>> fake_input_sockets;
     125             :     std::vector<std::shared_ptr<Socket>> sockets;
     126             : 
     127             :     Task(module::Module& module,
     128             :          const std::string& name,
     129             :          const bool stats = false,
     130             :          const bool fast = false,
     131             :          const bool debug = false,
     132             :          const bool outbuffers_allocated = false);
     133             : 
     134      170109 :     virtual ~Task() = default;
     135             : 
     136             :     void reset();
     137             : 
     138             :     void set_stats(const bool stats);
     139             :     void set_fast(const bool fast);
     140             :     void set_debug(const bool debug);
     141             :     void set_debug_hex(const bool debug_hex);
     142             :     void set_debug_limit(const uint32_t limit);
     143             :     void set_debug_precision(const uint8_t prec);
     144             :     void set_debug_frame_max(const uint32_t limit);
     145             :     void set_replicability(const bool replicable);
     146             :     void set_outbuffers_allocated(const bool outbuffers_allocated);
     147             : 
     148             :     inline bool is_stats() const;
     149             :     inline bool is_fast() const;
     150             :     inline bool is_debug() const;
     151             :     inline bool is_debug_hex() const;
     152             :     inline bool is_last_input_socket(const Socket& s_in) const;
     153             :     inline bool is_outbuffers_allocated() const;
     154             :     bool is_stateless() const;
     155             :     bool is_stateful() const;
     156             :     bool is_replicable() const;
     157             :     bool can_exec() const;
     158             : 
     159             :     inline module::Module& get_module() const;
     160             :     inline std::string get_name() const;
     161             :     inline uint32_t get_n_calls() const;
     162             : 
     163             :     // get stats
     164             :     std::chrono::nanoseconds get_duration_total() const;
     165             :     std::chrono::nanoseconds get_duration_avg() const;
     166             :     std::chrono::nanoseconds get_duration_min() const;
     167             :     std::chrono::nanoseconds get_duration_max() const;
     168             :     const std::vector<std::string>& get_timers_name() const;
     169             :     const std::vector<uint32_t>& get_timers_n_calls() const;
     170             :     const std::vector<std::chrono::nanoseconds>& get_timers_total() const;
     171             :     const std::vector<std::chrono::nanoseconds>& get_timers_min() const;
     172             :     const std::vector<std::chrono::nanoseconds>& get_timers_max() const;
     173             : 
     174             :     size_t get_n_input_sockets() const;
     175             :     size_t get_n_output_sockets() const;
     176             :     size_t get_n_fwd_sockets() const;
     177             :     size_t get_n_static_input_sockets() const;
     178             : 
     179             :     const std::vector<int>& exec(const int frame_id = -1, const bool managed_memory = true);
     180             : 
     181             :     inline Socket& operator[](const size_t id);
     182             :     Socket& operator[](const std::string& sck_name);
     183             : 
     184             :     inline void update_timer(const size_t id, const std::chrono::nanoseconds& duration);
     185             : 
     186             :     Task* clone() const;
     187             : 
     188             :     inline const std::vector<int>& get_status() const;
     189             : 
     190             :     void bind(Socket& s_out, const int priority = -1); // deprecated
     191             :     void operator=(Socket& s_out);
     192             :     size_t unbind(Socket& s_out);
     193             : 
     194             :     void bind(Task& t_out, const int priority = -1); // deprecated
     195             :     void operator=(Task& t_out);
     196             :     size_t unbind(Task& t_out);
     197             : 
     198             :   protected:
     199             :     void _bind(Socket& s_out, const int priority = -1);
     200             :     void _bind(Task& t_out, const int priority = -1);
     201             : 
     202             :     void _exec(const int frame_id = -1, const bool managed_memory = true);
     203             : 
     204             :     void register_timer(const std::string& key);
     205             : 
     206             :     template<typename T>
     207             :     size_t create_2d_socket_in(const std::string& name, const size_t n_rows, const size_t n_cols);
     208             :     size_t create_2d_socket_in(const std::string& name,
     209             :                                const size_t n_rows,
     210             :                                const size_t n_cols,
     211             :                                const std::type_index& datatype);
     212             :     size_t create_2d_socket_in(const std::string& name,
     213             :                                const size_t n_rows,
     214             :                                const size_t n_cols,
     215             :                                const datatype_t datatype);
     216             : 
     217             :     template<typename T>
     218             :     size_t create_2d_socket_out(const std::string& name,
     219             :                                 const size_t n_rows,
     220             :                                 const size_t n_cols,
     221             :                                 const bool hack_status = false);
     222             :     size_t create_2d_socket_out(const std::string& name,
     223             :                                 const size_t n_rows,
     224             :                                 const size_t n_cols,
     225             :                                 const std::type_index& datatype,
     226             :                                 const bool hack_status = false);
     227             :     size_t create_2d_socket_out(const std::string& name,
     228             :                                 const size_t n_rows,
     229             :                                 const size_t n_cols,
     230             :                                 const datatype_t datatype,
     231             :                                 const bool hack_status = false);
     232             : 
     233             :     template<typename T>
     234             :     size_t create_2d_socket_fwd(const std::string& name, const size_t n_rows, const size_t n_cols);
     235             :     size_t create_2d_socket_fwd(const std::string& name,
     236             :                                 const size_t n_rows,
     237             :                                 const size_t n_cols,
     238             :                                 const std::type_index& datatype);
     239             :     size_t create_2d_socket_fwd(const std::string& name,
     240             :                                 const size_t n_rows,
     241             :                                 const size_t n_cols,
     242             :                                 const datatype_t datatype);
     243             : 
     244             :     void create_codelet(std::function<int(module::Module& m, Task& t, const size_t frame_id)>& codelet);
     245             : 
     246             :     void update_n_frames(const size_t old_n_frames, const size_t new_n_frames);
     247             : 
     248             :     void update_n_frames_per_wave(const size_t old_n_frames_per_wave, const size_t new_n_frames_per_wave);
     249             : 
     250             :     // Function to allocate task's out sockets
     251             :     void allocate_outbuffers();
     252             :     // Function to deallocate all tasks out buffers
     253             :     void deallocate_outbuffers();
     254             : 
     255             :   private:
     256             :     template<typename T>
     257             :     inline Socket& create_2d_socket(const std::string& name,
     258             :                                     const size_t n_rows,
     259             :                                     const size_t n_cols,
     260             :                                     const socket_t type,
     261             :                                     const bool hack_status = false);
     262             : };
     263             : }
     264             : }
     265             : 
     266             : #ifndef DOXYGEN_SHOULD_SKIP_THIS
     267             : #include "Runtime/Task/Task.hxx"
     268             : #endif
     269             : 
     270             : #endif /* TASK_HPP_ */

Generated by: LCOV version 1.14