xref: /aosp_15_r20/external/pytorch/torch/csrc/autograd/utils/warnings.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #include <torch/csrc/autograd/utils/warnings.h>
2 
3 namespace torch::autograd::utils {
4 
process(const c10::Warning & warning)5 void DelayWarningHandler::process(const c10::Warning& warning) {
6   std::lock_guard<std::mutex> lock(mutex_);
7   warnings_.push_back(warning);
8 }
9 
replay_warnings()10 void DelayWarningHandler::replay_warnings() {
11   std::lock_guard<std::mutex> lock(mutex_);
12   TORCH_INTERNAL_ASSERT(
13       c10::WarningUtils::get_warning_handler() != this,
14       "DelayWarningHandler cannot replay warnings into itself, this will cause a deadlock");
15   for (const auto& warning : warnings_) {
16     c10::warn(warning);
17   }
18 }
19 
20 } // namespace torch::autograd::utils
21