LCOV - code coverage report
Current view: top level - src/Module/Stateful/Incrementer - Incrementer.cpp (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 42 53 79.2 %
Date: 2025-03-14 12:33:06 Functions: 11 90 12.2 %

          Line data    Source code
       1             : #include <chrono>
       2             : #include <sstream>
       3             : 
       4             : #include "Module/Stateful/Incrementer/Incrementer.hpp"
       5             : 
       6             : using namespace spu;
       7             : using namespace spu::module;
       8             : 
       9             : template<typename T>
      10         556 : Incrementer<T>::Incrementer(const size_t n_elmts, const size_t ns)
      11             :   : Stateful()
      12         556 :   , n_elmts(n_elmts)
      13         556 :   , ns(ns)
      14             : {
      15         556 :     const std::string name = "Incrementer";
      16         556 :     this->set_name(name);
      17         556 :     this->set_short_name(name);
      18             : 
      19         556 :     if (n_elmts == 0)
      20             :     {
      21           0 :         std::stringstream message;
      22           0 :         message << "'n_elmts' has to be greater than 0 ('n_elmts' = " << n_elmts << ").";
      23           0 :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
      24           0 :     }
      25             : 
      26         556 :     auto& p1 = this->create_task("increment");
      27         556 :     auto p1s_in = this->template create_socket_in<T>(p1, "in", this->n_elmts);
      28         556 :     auto p1s_out = this->template create_socket_out<T>(p1, "out", this->n_elmts);
      29         556 :     this->create_codelet(
      30             :       p1,
      31     4304636 :       [p1s_in, p1s_out](Module& m, runtime::Task& t, const size_t frame_id) -> int
      32             :       {
      33     2153183 :           auto& inc = static_cast<Incrementer&>(m);
      34     2153183 :           inc._increment(t[p1s_in].template get_dataptr<const T>(), t[p1s_out].template get_dataptr<T>(), frame_id);
      35     2123823 :           return runtime::status_t::SUCCESS;
      36             :       });
      37             : 
      38         556 :     auto& p2 = this->create_task("incrementf");
      39         556 :     auto p2s_fwd = this->template create_socket_fwd<T>(p2, "fwd", this->n_elmts);
      40         556 :     this->create_codelet(
      41             :       p2,
      42      655076 :       [p2s_fwd](Module& m, runtime::Task& t, const size_t frame_id) -> int
      43             :       {
      44      328044 :           auto& inc = static_cast<Incrementer&>(m);
      45      328044 :           inc._increment(t[p2s_fwd].template get_dataptr<const T>(), t[p2s_fwd].template get_dataptr<T>(), frame_id);
      46      331165 :           return runtime::status_t::SUCCESS;
      47             :       });
      48         556 : }
      49             : 
      50             : template<typename T>
      51             : Incrementer<T>*
      52       17599 : Incrementer<T>::clone() const
      53             : {
      54       17599 :     auto m = new Incrementer(*this);
      55       17599 :     m->deep_copy(*this);
      56       17599 :     return m;
      57             : }
      58             : 
      59             : template<typename T>
      60             : size_t
      61         324 : Incrementer<T>::get_ns() const
      62             : {
      63         324 :     return this->ns;
      64             : }
      65             : 
      66             : template<typename T>
      67             : size_t
      68           0 : Incrementer<T>::get_n_elmts() const
      69             : {
      70           0 :     return this->n_elmts;
      71             : }
      72             : 
      73             : template<typename T>
      74             : void
      75         545 : Incrementer<T>::set_ns(const size_t ns)
      76             : {
      77         545 :     this->ns = ns;
      78         545 : }
      79             : 
      80             : template<typename T>
      81             : void
      82           0 : Incrementer<T>::increment(const T* in, T* out, const int frame_id, const bool managed_memory)
      83             : {
      84           0 :     (*this)[inc::sck::increment::in].bind(in);
      85           0 :     (*this)[inc::sck::increment::out].bind(out);
      86           0 :     (*this)[inc::tsk::increment].exec(frame_id, managed_memory);
      87           0 : }
      88             : 
      89             : template<typename T>
      90             : void
      91     2282763 : Incrementer<T>::_increment(const T* in, T* out, const size_t /*frame_id*/)
      92             : {
      93     2282763 :     std::chrono::time_point<std::chrono::steady_clock> t_start;
      94     2282763 :     if (this->ns) t_start = std::chrono::steady_clock::now();
      95             : 
      96  1365259043 :     for (size_t e = 0; e < this->n_elmts; e++)
      97  1362897914 :         out[e] = in[e] + 1;
      98             : 
      99     2361129 :     if (this->ns)
     100             :     {
     101     2331712 :         std::chrono::nanoseconds duration = std::chrono::steady_clock::now() - t_start;
     102     6868519 :         while ((size_t)duration.count() < this->ns) // active waiting
     103     4483561 :             duration = std::chrono::steady_clock::now() - t_start;
     104             :     }
     105     2484974 : }
     106             : 
     107             : // ==================================================================================== explicit template instantiation
     108             : template class spu::module::Incrementer<int8_t>;
     109             : template class spu::module::Incrementer<uint8_t>;
     110             : template class spu::module::Incrementer<int16_t>;
     111             : template class spu::module::Incrementer<uint16_t>;
     112             : template class spu::module::Incrementer<int32_t>;
     113             : template class spu::module::Incrementer<uint32_t>;
     114             : template class spu::module::Incrementer<int64_t>;
     115             : template class spu::module::Incrementer<uint64_t>;
     116             : template class spu::module::Incrementer<float>;
     117             : template class spu::module::Incrementer<double>;
     118             : // ==================================================================================== explicit template instantiation

Generated by: LCOV version 1.14