tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
script_printer.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
23 #ifndef TVM_NODE_SCRIPT_PRINTER_H_
24 #define TVM_NODE_SCRIPT_PRINTER_H_
25 
26 #include <tvm/node/functor.h>
27 #include <tvm/node/object_path.h>
28 #include <tvm/node/reflection.h>
29 #include <tvm/runtime/data_type.h>
30 
31 #include <iostream>
32 #include <string>
33 
34 namespace tvm {
35 
36 class PrinterConfigNode : public Object {
37  public:
41  bool show_meta = false;
43  std::string ir_prefix = "I";
45  std::string tir_prefix = "T";
57  bool verbose_expr = false;
59  int indent_spaces = 4;
61  bool print_line_numbers = false;
65  bool syntax_sugar = true;
66  /* \brief Object path to be underlined */
74 
76  v->Visit("binding_names", &binding_names);
77  v->Visit("show_meta", &show_meta);
78  v->Visit("ir_prefix", &ir_prefix);
79  v->Visit("buffer_dtype", &buffer_dtype);
80  v->Visit("int_dtype", &int_dtype);
81  v->Visit("float_dtype", &float_dtype);
82  v->Visit("verbose_expr", &verbose_expr);
83  v->Visit("indent_spaces", &indent_spaces);
84  v->Visit("print_line_numbers", &print_line_numbers);
85  v->Visit("num_context_lines", &num_context_lines);
86  v->Visit("syntax_sugar", &syntax_sugar);
87  v->Visit("path_to_underline", &path_to_underline);
88  v->Visit("path_to_annotate", &path_to_annotate);
89  v->Visit("obj_to_underline", &obj_to_underline);
90  v->Visit("obj_to_annotate", &obj_to_annotate);
91  }
92 
93  static constexpr const char* _type_key = "node.PrinterConfig";
95 };
96 
97 class PrinterConfig : public ObjectRef {
98  public:
100 
103 };
104 
107  public:
108  /* Convert the object to TVMScript format */
109  static std::string Script(const ObjectRef& node, const Optional<PrinterConfig>& cfg);
110  // Allow registration to be printer.
112  TVM_DLL static FType& vtable();
113 };
114 
115 #define TVM_OBJECT_ENABLE_SCRIPT_PRINTER() \
116  std::string Script(const Optional<PrinterConfig>& config = NullOpt) const { \
117  return TVMScriptPrinter::Script(GetRef<ObjectRef>(this), config.value_or(PrinterConfig())); \
118  }
119 
120 } // namespace tvm
121 #endif // TVM_NODE_SCRIPT_PRINTER_H_
A dynamically dispatched functor on the type of the first argument.
Definition: functor.h:64
int num_context_lines
Number of context lines to print around the underlined text.
Definition: script_printer.h:63
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:758
std::string tir_prefix
The prefix of TIR nodes.
Definition: script_printer.h:45
Definition: script_printer.h:36
int indent_spaces
Number of spaces used for indentation.
Definition: script_printer.h:59
static DataType Void()
Construct a Void type.
Definition: data_type.h:203
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
DataType float_dtype
Default data type of float literals. Right now we always print out the explicit type of floating poin...
Definition: script_printer.h:55
DataType int_dtype
Default data type of integer literals.
Definition: script_printer.h:49
Map< ObjectPath, String > path_to_annotate
Object path to be annotated.
Definition: script_printer.h:69
base class of all object containers.
Definition: object.h:167
bool print_line_numbers
Whether to print line numbers.
Definition: script_printer.h:61
Array< ObjectPath > path_to_underline
Definition: script_printer.h:67
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
Map< ObjectRef, String > obj_to_annotate
Object to be annotated.
Definition: script_printer.h:73
static constexpr const char * _type_key
Definition: script_printer.h:93
bool verbose_expr
Whether or not to verbose print expressions.
Definition: script_printer.h:57
Runtime primitive data type.
Definition: data_type.h:41
static DataType Float(int bits, int lanes=1)
Construct an float type.
Definition: data_type.h:178
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
TVM_DECLARE_FINAL_OBJECT_INFO(PrinterConfigNode, Object)
Legacy behavior of ReprPrinter.
Definition: script_printer.h:106
bool syntax_sugar
Whether to output with syntax sugar, set false for complete printing.
Definition: script_printer.h:65
bool show_meta
Whether or not to show metadata.
Definition: script_printer.h:41
void VisitAttrs(AttrVisitor *v)
Definition: script_printer.h:75
Defines the Functor data structures.
Base class of all object reference.
Definition: object.h:511
Array< String > binding_names
A stack that tracks the names of the binding hierarchy.
Definition: script_printer.h:39
Array< ObjectRef > obj_to_underline
Object to be underlined.
Definition: script_printer.h:71
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reflection and serialization of compiler IR/AST nodes.
Definition: script_printer.h:97
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:164
std::string ir_prefix
The prefix of IR nodes.
Definition: script_printer.h:43
DataType buffer_dtype
Default data type of TIR buffer.
Definition: script_printer.h:47