MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / sync

Method sync

Src/Base/AMReX_GpuDevice.cpp:159–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159void
160StreamManager::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
196void
197StreamManager::free_async (Arena* arena, void* mem) {

Callers 4

resetExternalStreamMethod · 0.80
streamSynchronizeMethod · 0.80
streamSynchronizeAllMethod · 0.80
clearFreeAsyncBufferMethod · 0.80

Calls 4

AbortFunction · 0.85
swapMethod · 0.45
freeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected