1 #include <torch/csrc/autograd/function.h> 3 #include <torch/csrc/autograd/engine.h> 4 #include <torch/csrc/autograd/variable.h> 5 #include <torch/csrc/jit/ir.h> 18 namespace torch {
namespace autograd {
22 thread_local uint64_t Function_next_sequence_nr_ = 0;
24 uint64_t Function::peek_at_next_sequence_nr() {
25 return Function_next_sequence_nr_;
28 uint64_t& Function::get_next_sequence_nr() {
29 return Function_next_sequence_nr_;
32 auto Function::name() const ->
std::
string {
36 AnomalyMetadata* Function::metadata() noexcept {
37 if (!anomaly_metadata_) {
40 return anomaly_metadata_.get();
43 static void gatherFunctions(
45 std::vector<std::shared_ptr<Function>>& stack) {
46 func->release_variables();
48 for (
auto& edge : func->next_edges()) {
49 if (edge.function.use_count() == 1) {
50 stack.emplace_back(std::move(edge.function));
52 edge.function.reset();
77 void deleteFunction(Function*
function) {
81 function->release_variables();
82 std::vector<std::shared_ptr<Function>> stack;
83 gatherFunctions(
function, stack);
86 while (!stack.empty()) {
87 auto func = std::move(stack.back());
89 gatherFunctions(func.get(), stack);
static Engine & get_default_engine()
Returns a reference to a static Engine instance.
std::string demangle(const char *name)
Utility to demangle a C++ symbol name.