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

Generated by: LCOV version 1.14