xref: /aosp_15_r20/external/pytorch/torch/csrc/lazy/core/ir_metadata.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 
3 #include <c10/macros/Macros.h>
4 
5 #include <string>
6 #include <vector>
7 
8 namespace torch {
9 namespace lazy {
10 struct SourceLocation {
11   std::string file;
12   std::string function;
13   int line = -1;
14 };
15 
16 TORCH_API void EmitShortFrameInfo(
17     std::ostream& stream,
18     const std::vector<SourceLocation>& frames);
19 
20 TORCH_API std::ostream& operator<<(
21     std::ostream& stream,
22     const std::vector<SourceLocation>& frames);
23 
24 // The base class for user defined metadata which is possible to attach to IR
25 // nodes.
26 struct TORCH_API UserMetaData {
27   virtual ~UserMetaData() = default;
28 };
29 
30 struct TORCH_API MetaData {
31   std::string scope;
32   std::vector<SourceLocation> frame_info;
33 };
34 
35 // TODO(whc) is this going to be used outside of in IR decompositions?
36 // RAII data structure to be used a stack variable to enter a new IR scope. IR
37 // scope names will appear in the IR and will help identifying the source of the
38 // single IR nodes.
39 struct TORCH_API ScopePusher {
40   explicit ScopePusher(const std::string& name);
41   ~ScopePusher();
42 
43   static void ResetScopes();
44 };
45 
46 TORCH_API MetaData GetMetaDataIfDebugging();
47 
48 } // namespace lazy
49 } // namespace torch
50