tvm
config.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  */
27 #ifndef TVM_SCRIPT_PRINTER_CONFIG_H_
28 #define TVM_SCRIPT_PRINTER_CONFIG_H_
29 
30 #include <tvm/ffi/any.h>
31 #include <tvm/ffi/container/array.h>
32 #include <tvm/ffi/container/map.h>
33 #include <tvm/ffi/dtype.h>
34 #include <tvm/ffi/reflection/access_path.h>
35 #include <tvm/ffi/reflection/registry.h>
36 #include <tvm/ffi/string.h>
37 #include <tvm/runtime/base.h>
38 
39 #include <string>
40 
41 namespace tvm {
42 
43 class PrinterConfigNode : public ffi::Object {
44  public:
46  ffi::Array<ffi::String> binding_names = {};
48  bool show_meta = false;
50  ffi::String ir_prefix = "I";
55  ffi::String module_alias = "cls";
57  DLDataType buffer_dtype = DLDataType{kDLFloat, 32, 1};
59  DLDataType int_dtype = DLDataType{kDLInt, 32, 1};
65  DLDataType float_dtype = DLDataType{kDLOpaqueHandle, 0, 0};
67  bool verbose_expr = false;
69  int indent_spaces = 4;
71  bool print_line_numbers = false;
75  bool syntax_sugar = true;
77  bool show_object_address = false;
78 
81 
82  /* \brief ffi::Object path to be underlined */
83  ffi::Array<ffi::reflection::AccessPath> path_to_underline;
85  ffi::Map<ffi::reflection::AccessPath, ffi::String> path_to_annotate;
87  ffi::Array<ffi::ObjectRef> obj_to_underline = ffi::Array<ffi::ObjectRef>();
89  ffi::Map<ffi::ObjectRef, ffi::String> obj_to_annotate = ffi::Map<ffi::ObjectRef, ffi::String>();
90 
101  ffi::Map<ffi::String, ffi::Any> extra_config;
102 
109  template <typename T>
110  T GetExtraConfig(const ffi::String& key, T fallback) const {
111  auto it = extra_config.find(key);
112  if (it == extra_config.end()) return fallback;
113  return (*it).second.as_or_throw<T>();
114  }
115 
116  static void RegisterReflection() {
117  namespace refl = tvm::ffi::reflection;
118  refl::ObjectDef<PrinterConfigNode>()
119  .def_ro("binding_names", &PrinterConfigNode::binding_names)
120  .def_ro("show_meta", &PrinterConfigNode::show_meta)
121  .def_ro("ir_prefix", &PrinterConfigNode::ir_prefix)
122  .def_ro("module_alias", &PrinterConfigNode::module_alias)
123  .def_ro("buffer_dtype", &PrinterConfigNode::buffer_dtype)
124  .def_ro("int_dtype", &PrinterConfigNode::int_dtype)
125  .def_ro("float_dtype", &PrinterConfigNode::float_dtype)
126  .def_ro("verbose_expr", &PrinterConfigNode::verbose_expr)
127  .def_ro("indent_spaces", &PrinterConfigNode::indent_spaces)
128  .def_ro("print_line_numbers", &PrinterConfigNode::print_line_numbers)
129  .def_ro("num_context_lines", &PrinterConfigNode::num_context_lines)
130  .def_ro("syntax_sugar", &PrinterConfigNode::syntax_sugar)
131  .def_ro("show_object_address", &PrinterConfigNode::show_object_address)
132  .def_ro("render_invisible_path_info", &PrinterConfigNode::render_invisible_path_info)
133  .def_ro("path_to_underline", &PrinterConfigNode::path_to_underline)
134  .def_ro("path_to_annotate", &PrinterConfigNode::path_to_annotate)
135  .def_ro("obj_to_underline", &PrinterConfigNode::obj_to_underline)
136  .def_ro("obj_to_annotate", &PrinterConfigNode::obj_to_annotate)
137  .def_ro("extra_config", &PrinterConfigNode::extra_config);
138  }
139 
140  ffi::Array<ffi::String> GetBuiltinKeywords();
141 
142  static constexpr const bool _type_mutable = true;
143  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.PrinterConfig", PrinterConfigNode, ffi::Object);
144 };
145 
146 class TVM_DLL PrinterConfig : public ffi::ObjectRef {
147  public:
148  explicit PrinterConfig(
149  ffi::Map<ffi::String, ffi::Any> config_dict = ffi::Map<ffi::String, ffi::Any>());
150 
152 };
153 
161 TVM_DLL std::string RedirectedReprPrinterMethod(const ffi::ObjectRef& obj);
162 
163 } // namespace tvm
164 #endif // TVM_SCRIPT_PRINTER_CONFIG_H_
Definition: config.h:43
DLDataType int_dtype
Default data type of integer literals.
Definition: config.h:59
ffi::String ir_prefix
The prefix of IR nodes.
Definition: config.h:50
static constexpr const bool _type_mutable
Definition: config.h:142
ffi::Array< ffi::String > binding_names
A stack that tracks the names of the binding hierarchy.
Definition: config.h:46
ffi::Array< ffi::ObjectRef > obj_to_underline
ffi::Object to be underlined.
Definition: config.h:87
bool print_line_numbers
Whether to print line numbers.
Definition: config.h:71
bool render_invisible_path_info
Whether to render access-path context for invisible underlined paths. Defaults true.
Definition: config.h:80
bool verbose_expr
Whether or not to verbose print expressions.
Definition: config.h:67
bool syntax_sugar
Whether to output with syntax sugar, set false for complete printing.
Definition: config.h:75
DLDataType float_dtype
Default data type of float literals. Right now we always print out the explicit type of floating poin...
Definition: config.h:65
ffi::Map< ffi::reflection::AccessPath, ffi::String > path_to_annotate
ffi::Object path to be annotated.
Definition: config.h:85
ffi::Map< ffi::ObjectRef, ffi::String > obj_to_annotate
ffi::Object to be annotated.
Definition: config.h:89
bool show_object_address
Whether variable names should include the object's address.
Definition: config.h:77
int indent_spaces
Number of spaces used for indentation.
Definition: config.h:69
int num_context_lines
Number of context lines to print around the underlined text.
Definition: config.h:73
ffi::Map< ffi::String, ffi::Any > extra_config
Generic extension map for dialect-specific config knobs.
Definition: config.h:101
bool show_meta
Whether or not to show metadata.
Definition: config.h:48
ffi::Array< ffi::reflection::AccessPath > path_to_underline
Definition: config.h:83
ffi::Array< ffi::String > GetBuiltinKeywords()
T GetExtraConfig(const ffi::String &key, T fallback) const
Look up a value in extra_config with type cast and fallback.
Definition: config.h:110
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.PrinterConfig", PrinterConfigNode, ffi::Object)
DLDataType buffer_dtype
Default buffer dtype.
Definition: config.h:57
ffi::String module_alias
The alias of the current module at cross-function call.
Definition: config.h:55
static void RegisterReflection()
Definition: config.h:116
Definition: config.h:146
PrinterConfig(ffi::Map< ffi::String, ffi::Any > config_dict=ffi::Map< ffi::String, ffi::Any >())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(PrinterConfig, ffi::ObjectRef, PrinterConfigNode)
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
std::string RedirectedReprPrinterMethod(const ffi::ObjectRef &obj)
The fallback body used by TVM_REGISTER_SCRIPT_AS_REPR (defined in printer.h).