Line data Source code
1 : #include "Module/Adaptor/Adaptor.hpp" 2 : 3 : using namespace spu; 4 : using namespace spu::module; 5 : 6 7922 : Adaptor::~Adaptor() 7 : { 8 1270777 : for (auto b : this->buffer_to_free) 9 1266816 : delete[] b; 10 : 11 3961 : (*this->buffer)[this->id].clear(); 12 3961 : (*this->first)[this->id] = 0; 13 3961 : (*this->last)[this->id] = 0; 14 3961 : } 15 : 16 : Adaptor* 17 0 : Adaptor::clone() const 18 : { 19 0 : throw tools::unimplemented_error(__FILE__, __LINE__, __func__); 20 : } 21 : 22 : void 23 3776 : Adaptor::deep_copy(const Adaptor& m) 24 : { 25 3776 : Module::deep_copy(m); 26 : 27 3776 : int id = -1; 28 89882 : for (size_t i = 0; i < this->buffer->size(); i++) 29 86106 : if ((*this->buffer)[i].size() == 0) id = (int)i; 30 : 31 3776 : if (id == -1) 32 : { 33 3776 : this->id = this->buffer->size(); 34 7552 : this->buffer->push_back( 35 7552 : std::vector<std::vector<int8_t*>>(this->n_sockets, std::vector<int8_t*>(this->buffer_size))); 36 : } 37 : else 38 : { 39 0 : this->id = (size_t)id; 40 0 : (*this->buffer)[this->id].resize(this->n_sockets, std::vector<int8_t*>(this->buffer_size)); 41 : } 42 : 43 3776 : this->buffer_to_free.clear(); 44 11708 : for (size_t s = 0; s < this->n_sockets; s++) 45 1223721 : for (size_t b = 0; b < this->buffer_size; b++) 46 : { 47 1215789 : (*this->buffer)[this->id][s][b] = new int8_t[this->n_frames * this->n_bytes[s]]; 48 1215789 : this->buffer_to_free.push_back((*this->buffer)[this->id][s][b]); 49 : } 50 : 51 3776 : 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 3776 : this->waiting_canceled.reset(new std::atomic<bool>(m.waiting_canceled->load())); 60 3776 : } 61 : 62 : void 63 7917 : Adaptor::send_cancel_signal() 64 : { 65 7917 : *this->waiting_canceled = true; 66 7917 : } 67 : 68 : void 69 3961 : Adaptor::reset() 70 : { 71 3961 : *this->waiting_canceled = false; 72 3964961 : for (auto& a : *this->first.get()) 73 3961000 : a = 0; 74 3964961 : for (auto& a : *this->last.get()) 75 3961000 : a = 0; 76 3961 : this->cur_id = 0; 77 3961 : this->reset_buffer(); 78 3961 : } 79 : 80 : void 81 4145 : Adaptor::set_no_copy_pull(const bool no_copy_pull) 82 : { 83 4145 : this->no_copy_pull = no_copy_pull; 84 4145 : } 85 : 86 : void 87 4146 : Adaptor::set_no_copy_push(const bool no_copy_push) 88 : { 89 4146 : this->no_copy_push = no_copy_push; 90 4146 : } 91 : 92 : bool 93 57992 : Adaptor::is_no_copy_pull() 94 : { 95 57992 : return this->no_copy_pull; 96 : } 97 : 98 : bool 99 80724 : Adaptor::is_no_copy_push() 100 : { 101 80724 : return this->no_copy_push; 102 : } 103 : 104 : void 105 8107 : Adaptor::reset_buffer() 106 : { 107 8107 : size_t id_buff = 0; 108 24955 : for (size_t s = 0; s < this->n_sockets; s++) 109 2601507 : for (size_t b = 0; b < this->buffer_size; b++) 110 2584659 : (*this->buffer)[this->id][s][b] = buffer_to_free[id_buff++]; 111 8107 : } 112 : 113 : void 114 9250 : Adaptor::set_n_frames(const size_t n_frames) 115 : { 116 9250 : const auto old_n_frames = this->get_n_frames(); 117 9250 : 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 9250 : }