File: reconstruct_scopes.h

package info (click to toggle)
pytorch 1.7.1-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 80,340 kB
  • sloc: cpp: 670,830; python: 343,991; ansic: 67,845; asm: 5,503; sh: 2,924; java: 2,888; xml: 266; makefile: 244; ruby: 148; yacc: 144; objc: 51; lex: 44
file content (37 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/** \brief A pass to reconstruct scopes of nodes from their inline callstacks.
 *
 * The pass takes the root module and a graph and for every graph node with
 * non-empty inline call-stack it computes the scope from this callstack.
 *
 * Callstack can be thought of as a stack of pointers to Function, and Function
 * in a general case may not be a part of any module. That's why this pass
 * requires a root module to be passed in - we can traverse all methods of the
 * module and its submodules and then recognize these methods in callstacks.
 *
 * Scope can be thought of as a stack of strings, so we basically converting a
 * pointer to Function to a string, or in other words trying to find a name for
 * a function in this module hierarchy.
 *
 * The produced scopes look like:
 * top.submod1.function1/top.submod1.subsubmod1.function2
 *
 * 'top' is the name we use for the root module itself, and it can be customized
 * with an optional third argument of the pass.
 *
 * The pass would not change anything if inlining has not been run on the graph.
 */
#pragma once

#include <torch/csrc/jit/api/module.h>
#include <torch/csrc/jit/ir/ir.h>

namespace torch {
namespace jit {

TORCH_API void ReconstructScopes(
    const Module& module,
    Graph& g,
    const std::string& prefix);

} // namespace jit
} // namespace torch