Files
pytorch/torch/csrc/jit/passes/annotate_warns.cpp
Yanan Cao d150d3e276 Make sure each warnings.warn only executes once inside TorchScript. (#45382)
Summary:
* Add a pass at end of runCleanupPasses to annotate `aten::warn` so that each has its unique id
* Enhanced interpreter so that it tracks which `aten::warn` has been executed before and skip them
* Improved insertInstruction so that it correctly checks for overflow

Fixes https://github.com/pytorch/pytorch/issues/45108

Pull Request resolved: https://github.com/pytorch/pytorch/pull/45382

Reviewed By: mrshenli

Differential Revision: D24060677

Pulled By: gmagogsfm

fbshipit-source-id: 9221bc55b9ce36b374bdf614da3fe47496b481c1
2020-10-02 14:55:10 -07:00

30 lines
524 B
C++

#include <torch/csrc/jit/passes/annotate_warns.h>
#include <atomic>
namespace torch {
namespace jit {
void AnnotateWarns(Block* b) {
static std::atomic<int64_t> idx(0);
for (Node* n : b->nodes()) {
for (Block* child_b : n->blocks()) {
AnnotateWarns(child_b);
}
if (n->kind() != aten::warn) {
continue;
}
n->i_(attr::warn_id, idx);
idx++;
}
}
void AnnotateWarns(const std::shared_ptr<Graph>& graph) {
AnnotateWarns(graph->block());
}
} // namespace jit
} // namespace torch