Line data Source code
1 : #include "Module/Stateful/Adaptor/Adaptor.hpp" 2 : 3 : using namespace spu; 4 : using namespace spu::module; 5 : 6 8796 : Adaptor::~Adaptor() 7 : { 8 1374070 : for (auto b : this->buffer_to_free) 9 1369672 : delete[] b; 10 : 11 4398 : (*this->buffer)[this->id].clear(); 12 4398 : (*this->first)[this->id] = 0; 13 4398 : (*this->last)[this->id] = 0; 14 4398 : } 15 : 16 : Adaptor* 17 0 : Adaptor::clone() const 18 : { 19 0 : throw tools::unimplemented_error(__FILE__, __LINE__, __func__); 20 : } 21 : 22 : void 23 4196 : Adaptor::deep_copy(const Adaptor& m) 24 : { 25 4196 : Stateful::deep_copy(m); 26 : 27 4196 : int id = -1; 28 91112 : for (size_t i = 0; i < this->buffer->size(); i++) 29 86916 : if ((*this->buffer)[i].size() == 0) id = (int)i; 30 : 31 4196 : if (id == -1) 32 : { 33 3818 : this->id = this->buffer->size(); 34 7636 : this->buffer->push_back( 35 7636 : std::vector<std::vector<int8_t*>>(this->n_sockets, std::vector<int8_t*>(this->buffer_size))); 36 : } 37 : else 38 : { 39 378 : this->id = (size_t)id; 40 378 : (*this->buffer)[this->id].resize(this->n_sockets, std::vector<int8_t*>(this->buffer_size)); 41 : } 42 : 43 4196 : this->buffer_to_free.clear(); 44 12845 : for (size_t s = 0; s < this->n_sockets; s++) 45 1327093 : for (size_t b = 0; b < this->buffer_size; b++) 46 : { 47 1318444 : (*this->buffer)[this->id][s][b] = new int8_t[this->n_frames * this->n_bytes[s]]; 48 1318444 : this->buffer_to_free.push_back((*this->buffer)[this->id][s][b]); 49 : } 50 : 51 4196 : if (this->id >= this->first->size()) 52 : { 53 0 : std::stringstream message; 54 0 : message << "'id' can't be higher than 'first->size()' ('id' = " << this->id 55 0 : << ", 'first->size()' = " << this->first->size() << ")."; 56 0 : throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str()); 57 0 : } 58 : 59 4196 : this->waiting_canceled.reset(new std::atomic<bool>(m.waiting_canceled->load())); 60 4196 : } 61 : 62 : void 63 7983 : Adaptor::send_cancel_signal() 64 : { 65 7983 : *this->waiting_canceled = true; 66 7984 : } 67 : 68 : void 69 3994 : Adaptor::reset() 70 : { 71 3994 : *this->waiting_canceled = false; 72 3997994 : for (auto& a : *this->first.get()) 73 3994000 : a = 0; 74 3997994 : for (auto& a : *this->last.get()) 75 3994000 : a = 0; 76 3994 : this->cur_id = 0; 77 3994 : this->reset_buffer(); 78 3994 : } 79 : 80 : void 81 4195 : Adaptor::set_no_copy_pull(const bool no_copy_pull) 82 : { 83 4195 : this->no_copy_pull = no_copy_pull; 84 4195 : } 85 : 86 : void 87 4196 : Adaptor::set_no_copy_push(const bool no_copy_push) 88 : { 89 4196 : this->no_copy_push = no_copy_push; 90 4196 : } 91 : 92 : bool 93 537879 : Adaptor::is_no_copy_pull() 94 : { 95 537879 : return this->no_copy_pull; 96 : } 97 : 98 : bool 99 553529 : Adaptor::is_no_copy_push() 100 : { 101 553529 : return this->no_copy_push; 102 : } 103 : 104 : void 105 8190 : Adaptor::reset_buffer() 106 : { 107 8190 : size_t id_buff = 0; 108 25139 : for (size_t s = 0; s < this->n_sockets; s++) 109 2602609 : for (size_t b = 0; b < this->buffer_size; b++) 110 2585660 : (*this->buffer)[this->id][s][b] = buffer_to_free[id_buff++]; 111 8190 : } 112 : 113 : void 114 9350 : Adaptor::set_n_frames(const size_t n_frames) 115 : { 116 9350 : const auto old_n_frames = this->get_n_frames(); 117 9350 : if (old_n_frames != n_frames) 118 : { 119 1964 : Module::set_n_frames(n_frames); 120 5950 : for (size_t s = 0; s < (*this->buffer)[this->id].size(); s++) 121 97338 : for (size_t b = 0; b < (*this->buffer)[this->id][s].size(); b++) 122 : { 123 93352 : auto old_ptr = (*this->buffer)[this->id][s][b]; 124 93352 : (*this->buffer)[this->id][s][b] = new int8_t[this->n_bytes[s] * n_frames]; 125 : 126 93352 : bool found = false; 127 3892308 : for (size_t bf = 0; bf < this->buffer_to_free.size(); bf++) 128 3892308 : if (this->buffer_to_free[bf] == old_ptr) 129 : { 130 93352 : delete[] this->buffer_to_free[bf]; 131 93352 : this->buffer_to_free[bf] = (*this->buffer)[this->id][s][b]; 132 93352 : found = true; 133 93352 : break; 134 : } 135 : 136 93352 : if (found == false) 137 : { 138 0 : std::stringstream message; 139 0 : message << "This should never happen."; 140 0 : throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); 141 0 : } 142 : } 143 : } 144 9350 : }