tvm
Loading...
Searching...
No Matches
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
41namespace tvm {
42
43class PrinterConfigObj : public ffi::Object {
44 public:
46 ffi::Array<ffi::String> binding_names = {};
48 bool show_meta = false;
50 bool verbose_expr = false;
54 bool print_line_numbers = false;
57
60
61 /* \brief ffi::Object path to be underlined */
62 ffi::Array<ffi::reflection::AccessPath> path_to_underline;
64 ffi::Map<ffi::reflection::AccessPath, ffi::String> path_to_annotate;
66 ffi::Array<ffi::ObjectRef> obj_to_underline = ffi::Array<ffi::ObjectRef>();
68 ffi::Map<ffi::ObjectRef, ffi::String> obj_to_annotate = ffi::Map<ffi::ObjectRef, ffi::String>();
69
81 ffi::Map<ffi::String, ffi::Any> extra_config;
82
89 template <typename T>
90 T GetExtraConfig(const ffi::String& key, T fallback) const {
91 auto it = extra_config.find(key);
92 if (it == extra_config.end()) return fallback;
93 return (*it).second.as_or_throw<T>();
94 }
95
96 static void RegisterReflection() {
97 namespace refl = tvm::ffi::reflection;
98 refl::ObjectDef<PrinterConfigObj>()
99 .def_ro("binding_names", &PrinterConfigObj::binding_names)
100 .def_ro("show_meta", &PrinterConfigObj::show_meta)
101 .def_ro("verbose_expr", &PrinterConfigObj::verbose_expr)
102 .def_ro("indent_spaces", &PrinterConfigObj::indent_spaces)
103 .def_ro("print_line_numbers", &PrinterConfigObj::print_line_numbers)
104 .def_ro("num_context_lines", &PrinterConfigObj::num_context_lines)
105 .def_ro("render_invisible_path_info", &PrinterConfigObj::render_invisible_path_info)
106 .def_ro("path_to_underline", &PrinterConfigObj::path_to_underline)
107 .def_ro("path_to_annotate", &PrinterConfigObj::path_to_annotate)
108 .def_ro("obj_to_underline", &PrinterConfigObj::obj_to_underline)
109 .def_ro("obj_to_annotate", &PrinterConfigObj::obj_to_annotate)
110 .def_ro("extra_config", &PrinterConfigObj::extra_config);
111 }
112
113 ffi::Array<ffi::String> GetBuiltinKeywords();
114
115 static constexpr const bool _type_mutable = true;
116 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.PrinterConfig", PrinterConfigObj, ffi::Object);
117};
118
119class TVM_TIRX_DLL PrinterConfig : public ffi::ObjectRef {
120 public:
122 ffi::Map<ffi::String, ffi::Any> config_dict = ffi::Map<ffi::String, ffi::Any>());
123
125};
126
134TVM_TIRX_DLL std::string RedirectedReprPrinterMethod(const ffi::ObjectRef& obj);
135
136} // namespace tvm
137#endif // TVM_SCRIPT_PRINTER_CONFIG_H_
Definition config.h:43
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.PrinterConfig", PrinterConfigObj, ffi::Object)
static void RegisterReflection()
Definition config.h:96
bool print_line_numbers
Whether to print line numbers.
Definition config.h:54
ffi::Array< ffi::reflection::AccessPath > path_to_underline
Definition config.h:62
bool show_meta
Whether or not to show metadata.
Definition config.h:48
ffi::Map< ffi::ObjectRef, ffi::String > obj_to_annotate
ffi::Object to be annotated.
Definition config.h:68
ffi::Map< ffi::reflection::AccessPath, ffi::String > path_to_annotate
ffi::Object path to be annotated.
Definition config.h:64
ffi::Array< ffi::ObjectRef > obj_to_underline
ffi::Object to be underlined.
Definition config.h:66
bool verbose_expr
Whether or not to verbose print expressions.
Definition config.h:50
bool render_invisible_path_info
Whether to render access-path context for invisible underlined paths. Defaults true.
Definition config.h:59
ffi::Map< ffi::String, ffi::Any > extra_config
Generic extension map for dialect-specific config knobs.
Definition config.h:81
int num_context_lines
Number of context lines to print around the underlined text.
Definition config.h:56
ffi::Array< ffi::String > binding_names
A stack that tracks the names of the binding hierarchy.
Definition config.h:46
static constexpr const bool _type_mutable
Definition config.h:115
T GetExtraConfig(const ffi::String &key, T fallback) const
Look up a value in extra_config with type cast and fallback.
Definition config.h:90
int indent_spaces
Number of spaces used for indentation.
Definition config.h:52
ffi::Array< ffi::String > GetBuiltinKeywords()
Definition config.h:119
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, PrinterConfigObj)
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
TVM_TIRX_DLL std::string RedirectedReprPrinterMethod(const ffi::ObjectRef &obj)
Render an IR object for its registered repr callback.
#define TVM_TIRX_DLL
Definition base.h:83