LCOV - code coverage report
Current view: top level - include/Module - Module.hxx (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 24 54 44.4 %
Date: 2024-06-12 12:04:18 Functions: 13 41 31.7 %

          Line data    Source code
       1             : #include <algorithm>
       2             : #include <cassert>
       3             : #include <exception>
       4             : #include <sstream>
       5             : 
       6             : #include "Module/Module.hpp"
       7             : 
       8             : namespace spu
       9             : {
      10             : namespace module
      11             : {
      12             : runtime::Task&
      13          70 : Module::operator[](const size_t id)
      14             : {
      15          70 :     assert(id < this->tasks_with_nullptr.size());
      16          70 :     assert(this->tasks_with_nullptr[id] != nullptr);
      17             : 
      18          70 :     return *this->tasks_with_nullptr[id];
      19             : }
      20             : 
      21             : const runtime::Task&
      22         232 : Module::operator[](const size_t id) const
      23             : {
      24         232 :     assert(id < this->tasks_with_nullptr.size());
      25         232 :     assert(this->tasks_with_nullptr[id] != nullptr);
      26             : 
      27         232 :     return *this->tasks_with_nullptr[id];
      28             : }
      29             : 
      30             : runtime::Socket&
      31           0 : Module::operator[](const std::string& tsk_sck)
      32             : {
      33           0 :     size_t pos = tsk_sck.find("::", 0);
      34           0 :     if ((int)pos < 0)
      35             :     {
      36           0 :         std::stringstream message;
      37           0 :         message << "Invalid socket name, it should be of the form task::socket ('tsk_sck' = " << tsk_sck << ").";
      38           0 :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
      39           0 :     }
      40           0 :     std::string tsk_name = tsk_sck.substr(0, pos);
      41           0 :     tsk_name.erase(remove(tsk_name.begin(), tsk_name.end(), ' '), tsk_name.end());
      42           0 :     std::string sck_name = tsk_sck.substr(pos + 2, tsk_sck.size());
      43           0 :     sck_name.erase(remove(sck_name.begin(), sck_name.end(), ' '), sck_name.end());
      44           0 :     auto& cur_tsk = this->operator()(tsk_name);
      45             : 
      46           0 :     auto it = find_if(cur_tsk.sockets.begin(),
      47             :                       cur_tsk.sockets.end(),
      48           0 :                       [sck_name](std::shared_ptr<runtime::Socket> s) { return s->get_name() == sck_name; });
      49             : 
      50           0 :     if (it == cur_tsk.sockets.end())
      51             :     {
      52           0 :         std::stringstream message;
      53           0 :         message << "runtime::Socket '" << sck_name << "' not found for task '" << tsk_name << "'.";
      54           0 :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
      55           0 :     }
      56             : 
      57           0 :     return *it->get();
      58           0 : }
      59             : 
      60             : runtime::Task&
      61           0 : Module::operator()(const std::string& tsk_name)
      62             : {
      63           0 :     auto it = find_if(this->tasks.begin(),
      64             :                       this->tasks.end(),
      65           0 :                       [tsk_name](std::shared_ptr<runtime::Task> t) { return t->get_name() == tsk_name; });
      66             : 
      67           0 :     if (it == this->tasks.end())
      68             :     {
      69           0 :         std::stringstream message;
      70           0 :         message << "runtime::Task '" << tsk_name << "' not found.";
      71           0 :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
      72           0 :     }
      73             : 
      74           0 :     return *it->get();
      75             : }
      76             : 
      77             : template<typename T>
      78             : inline size_t
      79        1170 : Module::create_socket_in(runtime::Task& task, const std::string& name, const size_t n_elmts)
      80             : {
      81        1170 :     return task.template create_2d_socket_in<T>(name, this->n_frames, n_elmts);
      82             : }
      83             : 
      84             : template<typename T>
      85             : inline size_t
      86             : Module::create_sck_in(runtime::Task& task, const std::string& name, const size_t n_elmts)
      87             : {
      88             :     return this->template create_socket_in<T>(task, name, n_elmts);
      89             : }
      90             : 
      91             : template<typename T>
      92             : inline size_t
      93        1053 : Module::create_socket_out(runtime::Task& task, const std::string& name, const size_t n_elmts)
      94             : {
      95        1053 :     return task.template create_2d_socket_out<T>(name, this->n_frames, n_elmts);
      96             : }
      97             : 
      98             : template<typename T>
      99             : inline size_t
     100             : Module::create_sck_out(runtime::Task& task, const std::string& name, const size_t n_elmts)
     101             : {
     102             :     return this->template create_socket_out<T>(task, name, n_elmts);
     103             : }
     104             : 
     105             : template<typename T>
     106             : inline size_t
     107         766 : Module::create_socket_fwd(runtime::Task& task, const std::string& name, const size_t n_elmts)
     108             : {
     109         766 :     return task.template create_2d_socket_fwd<T>(name, this->n_frames, n_elmts);
     110             : }
     111             : 
     112             : template<typename T>
     113             : inline size_t
     114             : Module::create_sck_fwd(runtime::Task& task, const std::string& name, const size_t n_elmts)
     115             : {
     116             :     return this->template create_socket_fwd<T>(task, name, n_elmts);
     117             : }
     118             : 
     119             : template<typename T>
     120             : inline size_t
     121             : Module::create_2d_socket_in(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols)
     122             : {
     123             :     return task.template create_2d_socket_in<T>(name, this->n_frames * n_rows, n_cols);
     124             : }
     125             : 
     126             : template<typename T>
     127             : inline size_t
     128             : Module::create_2d_sck_in(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols)
     129             : {
     130             :     return this->template create_2d_socket_in<T>(task, name, n_rows, n_cols);
     131             : }
     132             : 
     133             : template<typename T>
     134             : inline size_t
     135             : Module::create_2d_socket_out(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols)
     136             : {
     137             :     return task.template create_2d_socket_out<T>(name, this->n_frames * n_rows, n_cols);
     138             : }
     139             : 
     140             : template<typename T>
     141             : inline size_t
     142             : Module::create_2d_sck_out(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols)
     143             : {
     144             :     return this->template create_2d_socket_out<T>(task, name, n_rows, n_cols);
     145             : }
     146             : 
     147             : template<typename T>
     148             : inline size_t
     149             : Module::create_2d_socket_fwd(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols)
     150             : {
     151             :     return task.template create_2d_socket_fwd<T>(name, this->n_frames * n_rows, n_cols);
     152             : }
     153             : 
     154             : template<typename T>
     155             : inline size_t
     156             : Module::create_2d_sck_fwd(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols)
     157             : {
     158             :     return this->template create_2d_socket_fwd<T>(task, name, n_rows, n_cols);
     159             : }
     160             : 
     161             : size_t
     162       41262 : Module::get_n_frames() const
     163             : {
     164       41262 :     return this->n_frames;
     165             : }
     166             : 
     167             : size_t
     168     1589981 : Module::get_n_frames_per_wave() const
     169             : {
     170     1589981 :     return this->n_frames_per_wave;
     171             : }
     172             : 
     173             : size_t
     174     1707926 : Module::get_n_waves() const
     175             : {
     176     1707926 :     return this->n_waves;
     177             : }
     178             : 
     179             : size_t
     180     1442742 : Module::get_n_frames_per_wave_rest() const
     181             : {
     182     1442742 :     return this->n_frames_per_wave_rest;
     183             : }
     184             : 
     185             : bool
     186       53552 : Module::is_single_wave() const
     187             : {
     188       53552 :     return this->single_wave;
     189             : }
     190             : 
     191             : }
     192             : }

Generated by: LCOV version 1.14