pytorch/c10/core/impl/GPUTrace.cpp
Mateusz Sypniewski 916def84d4 CUDA trace Python hooks (#82824)
### Description
This adds Python hooks into PyTorch that allow the user to register their own callbacks for events such as tensor allocation, stream allocation, event record / wait etc.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/82824
Approved by: https://github.com/lw, https://github.com/ezyang, https://github.com/malfet
2022-08-11 10:21:40 +00:00

23 lines
468 B
C++

#include <mutex>
#include <c10/core/impl/GPUTrace.h>
#include <c10/util/CallOnce.h>
namespace c10 {
namespace impl {
std::atomic<const PyInterpreter*> GPUTrace::gpuTraceState{nullptr};
bool GPUTrace::haveState{false};
void GPUTrace::set_trace(const PyInterpreter* trace) {
static c10::once_flag flag;
c10::call_once(flag, [&]() {
gpuTraceState.store(trace, std::memory_order_release);
haveState = true;
});
}
} // namespace impl
} // namespace c10