File: backend_debug_info.h

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (65 lines) | stat: -rw-r--r-- 2,338 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once

#ifndef BUILD_LITE_INTERPRETER
#include <torch/csrc/jit/backends/backend_debug_handler.h>
#endif
#include <torch/custom_class.h>

namespace torch {
namespace jit {

constexpr static auto kBackendUtilsNamespace = "backendutils";
constexpr static auto kBackendDebugInfoClass = "BackendDebugInfo";

#ifndef BUILD_LITE_INTERPRETER
/*
 * Custom class for holding debug information in lowered modules, intended
 * purely for keeping this information to be later serialized outside of the
 * lowered module itself.
 * Its usage pattern is:
 * 1. LoweredModule declares an instance of this class in __backend_debug_info
 * 2. During serialization, __backend_debug_info is used to obtain the debug
 *    information.
 * 3. The contents of LoweredModule.__backend_debug_info are not serialized
 *    within the LoweredModule itself.
 */
class TORCH_API PyTorchBackendDebugInfo : public torch::CustomClassHolder {
 public:
  PyTorchBackendDebugInfo() = default;

  c10::optional<BackendDebugInfoMapType>& getDebugInfoMap() {
    return debug_info_map_;
  }

  void setDebugInfoMap(BackendDebugInfoMapType&& debug_info_map) {
    debug_info_map_ = std::move(debug_info_map);
  }

 private:
  c10::optional<BackendDebugInfoMapType> debug_info_map_;
};

#else

/*
 * Dummy instance exists for the following reason:
 * __backend_debug_info is of type BackendDebugInfo which is a torchbind'
 * class backed by cpp class PyTorchBackendDebugInfo.
 * PyTorchBackendDebugInfo, depends on ir.h., scope.h, source_range etc.
 * We dont include this on lite interpreter side. Thus on lite interpreter side
 * we cannot have valid definition of PyTorchBackendDebugInfo. However we do not
 * need valid instance of __backend_debug_info in lite interpreter anyway as we
 * dont serialize this info as part of LowerdModule as mentioned ealrier.
 * However since LoweredModule has registered attribute of __backend_debug_info
 * we still need to make sure that BackendDebugInfo is registered with
 * TorchScript. However in this instance it does not have to be backed by
 * PyTorchBackendDebugInfo, so we create a dummy PyTorchBackendDebugInfoDummy
 * just for this purpose.
 */
class PyTorchBackendDebugInfoDummy : public torch::CustomClassHolder {
 public:
  PyTorchBackendDebugInfoDummy() = default;
};
#endif
} // namespace jit
} // namespace torch