LCOV - code coverage report
Current view: top level - src/Module/Finalizer - Finalizer.cpp (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 41 55 74.5 %
Date: 2024-06-12 12:04:18 Functions: 12 100 12.0 %

          Line data    Source code
       1             : #include <sstream>
       2             : #include <string>
       3             : 
       4             : #include "Module/Finalizer/Finalizer.hpp"
       5             : 
       6             : using namespace spu;
       7             : using namespace spu::module;
       8             : 
       9             : template<typename T>
      10         121 : Finalizer<T>::Finalizer(const size_t n_elmts, const size_t history_size)
      11             :   : Module()
      12         121 :   , data(history_size, std::vector<std::vector<T>>(this->get_n_frames(), std::vector<T>(n_elmts, 0)))
      13         121 :   , next_stream_id(0)
      14             : {
      15         121 :     const std::string name = "Finalizer";
      16         121 :     this->set_name(name);
      17         121 :     this->set_short_name(name);
      18             : 
      19         121 :     if (n_elmts == 0)
      20             :     {
      21           0 :         std::stringstream message;
      22           0 :         message << "'n_elmts' has to be greater than 0.";
      23           0 :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
      24           0 :     }
      25             : 
      26         121 :     if (history_size == 0)
      27             :     {
      28           0 :         std::stringstream message;
      29           0 :         message << "'history_size' has to be greater than 0.";
      30           0 :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
      31           0 :     }
      32             : 
      33         121 :     auto& p = this->create_task("finalize");
      34         121 :     auto ps_in = this->template create_socket_in<T>(p, "in", n_elmts);
      35         121 :     this->create_codelet(p,
      36      187152 :                          [ps_in](Module& m, runtime::Task& t, const size_t frame_id) -> int
      37             :                          {
      38      187152 :                              auto& fin = static_cast<Finalizer&>(m);
      39      187152 :                              fin._finalize(t[ps_in].template get_dataptr<const T>(), frame_id);
      40      188436 :                              return runtime::status_t::SUCCESS;
      41             :                          });
      42         121 : }
      43             : 
      44             : template<typename T>
      45             : Finalizer<T>*
      46        2520 : Finalizer<T>::clone() const
      47             : {
      48        2520 :     auto m = new Finalizer(*this);
      49        2520 :     m->deep_copy(*this);
      50        2520 :     return m;
      51             : }
      52             : 
      53             : template<typename T>
      54             : const std::vector<std::vector<T>>&
      55       24273 : Finalizer<T>::get_final_data() const
      56             : {
      57       24273 :     auto last_stream_id = this->next_stream_id ? this->next_stream_id - 1 : this->data.size() - 1;
      58       24273 :     return this->data[last_stream_id];
      59             : }
      60             : 
      61             : template<typename T>
      62             : const std::vector<std::vector<std::vector<T>>>&
      63        4590 : Finalizer<T>::get_histo_data() const
      64             : {
      65        4590 :     return this->data;
      66             : }
      67             : 
      68             : template<typename T>
      69             : size_t
      70           0 : Finalizer<T>::get_next_stream_id() const
      71             : {
      72           0 :     return this->next_stream_id;
      73             : }
      74             : 
      75             : template<typename T>
      76             : void
      77        3720 : Finalizer<T>::set_n_frames(const size_t n_frames)
      78             : {
      79        3720 :     const auto old_n_frames = this->get_n_frames();
      80        3720 :     if (old_n_frames != n_frames)
      81             :     {
      82        3720 :         Module::set_n_frames(n_frames);
      83        9234 :         for (size_t s = 0; s < this->data.size(); s++)
      84             :         {
      85        5514 :             this->data[s].resize(n_frames);
      86       30752 :             for (size_t f = old_n_frames; f < n_frames; f++)
      87       25238 :                 this->data[s][f].resize(this->data[s][0].size());
      88             :         }
      89             :     }
      90        3720 : }
      91             : 
      92             : template<typename T>
      93             : void
      94           0 : Finalizer<T>::finalize(const T* in, const int frame_id, const bool managed_memory)
      95             : {
      96           0 :     (*this)[fin::sck::finalize::in].bind(in);
      97           0 :     (*this)[fin::tsk::finalize].exec(frame_id, managed_memory);
      98           0 : }
      99             : 
     100             : template<typename T>
     101             : void
     102      187140 : Finalizer<T>::_finalize(const T* in, const size_t frame_id)
     103             : {
     104      187140 :     std::copy(in, in + this->data[this->next_stream_id][0].size(), this->data[this->next_stream_id][frame_id].begin());
     105             : 
     106      188550 :     if (frame_id == this->get_n_frames() - 1) this->next_stream_id = (this->next_stream_id + 1) % this->data.size();
     107      188445 : }
     108             : 
     109             : template<typename T>
     110             : void
     111        1024 : Finalizer<T>::reset()
     112             : {
     113        1024 :     this->next_stream_id = 0;
     114        1024 : }
     115             : 
     116             : // ==================================================================================== explicit template instantiation
     117             : template class spu::module::Finalizer<int8_t>;
     118             : template class spu::module::Finalizer<uint8_t>;
     119             : template class spu::module::Finalizer<int16_t>;
     120             : template class spu::module::Finalizer<uint16_t>;
     121             : template class spu::module::Finalizer<int32_t>;
     122             : template class spu::module::Finalizer<uint32_t>;
     123             : template class spu::module::Finalizer<int64_t>;
     124             : template class spu::module::Finalizer<uint64_t>;
     125             : template class spu::module::Finalizer<float>;
     126             : template class spu::module::Finalizer<double>;
     127             : // ==================================================================================== explicit template instantiation

Generated by: LCOV version 1.14