| 157 | } |
| 158 | |
| 159 | void |
| 160 | StreamManager::sync () { |
| 161 | decltype(m_free_wait_list) new_empty_wait_list{}; |
| 162 | |
| 163 | { |
| 164 | // lock mutex before accessing and modifying member variables |
| 165 | std::lock_guard<std::mutex> lock(m_mutex); |
| 166 | m_free_wait_list.swap(new_empty_wait_list); |
| 167 | } |
| 168 | // unlock mutex before stream sync and memory free |
| 169 | // to avoid deadlocks from the CArena mutex |
| 170 | |
| 171 | // actual stream sync |
| 172 | #ifdef AMREX_USE_SYCL |
| 173 | try { |
| 174 | m_stream.queue->wait_and_throw(); |
| 175 | } catch (sycl::exception const& ex) { |
| 176 | for (auto [arena, mem] : new_empty_wait_list) { |
| 177 | arena->free(mem); |
| 178 | } |
| 179 | new_empty_wait_list.clear(); |
| 180 | amrex::Abort(std::string("streamSynchronize: ")+ex.what()+"!!!!!"); |
| 181 | } |
| 182 | #else |
| 183 | AMREX_HIP_OR_CUDA( AMREX_HIP_SAFE_CALL(hipStreamSynchronize(m_stream));, |
| 184 | AMREX_CUDA_SAFE_CALL(cudaStreamSynchronize(m_stream)); ) |
| 185 | #endif |
| 186 | |
| 187 | // synconizing the stream may have taken a long time and |
| 188 | // there may be new kernels launched already, so we free memory |
| 189 | // according to the state from before the stream was synced |
| 190 | |
| 191 | for (auto [arena, mem] : new_empty_wait_list) { |
| 192 | arena->free(mem); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | StreamManager::free_async (Arena* arena, void* mem) { |
no test coverage detected