MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / AddCallback

Method AddCallback

paddle/phi/backends/callback_manager.cc:27–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25 : stream_(stream), thread_pool_(new ::ThreadPool(1)) {}
26
27void CallbackManager::AddCallback(std::function<void()> callback) const {
28 auto *callback_func = new std::function<void()>(std::move(callback));
29 auto *func = new std::function<void()>([this, callback_func] {
30 std::lock_guard<std::mutex> lock(mtx_);
31 last_future_ = thread_pool_->enqueue([callback_func] {
32 std::unique_ptr<std::function<void()>> releaser(callback_func);
33 (*callback_func)();
34 });
35 });
36 phi::DeviceGuard guard(stream_->GetPlace());
37 DeviceManager::GetDeviceWithPlace(stream_->GetPlace())
38 ->AddCallback(stream_, func);
39}
40
41void CallbackManager::Wait() const {
42 phi::DeviceGuard guard(stream_->GetPlace());

Callers

nothing calls this directly

Calls 2

enqueueMethod · 0.45
GetPlaceMethod · 0.45

Tested by

no test coverage detected