tvm
base.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  */
19 
24 #ifndef TVM_RELAY_BASE_H_
25 #define TVM_RELAY_BASE_H_
26 
27 #include <tvm/ir/source_map.h>
28 #include <tvm/node/node.h>
29 #include <tvm/tir/expr.h>
30 
31 #include <string>
32 #include <vector>
33 
34 namespace tvm {
43 namespace relay {
44 
45 #define RELAY_DEBUG(...) \
46  { \
47  auto fdebug = runtime::Registry::Get("relay.debug"); \
48  ICHECK(fdebug) << "Could not find Relay Python debugger function."; \
49  (*fdebug)("RELAY_DEBUG", __FILE__, __LINE__, __VA_ARGS__); \
50  }
51 
52 #define RELAY_DEBUG_INTERP(...) \
53  { \
54  auto fdebug = runtime::Registry::Get("relay.debug_interp"); \
55  ICHECK(fdebug) << "Could not find Relay Python debugger function."; \
56  (*fdebug)("RELAY_DEBUG", __FILE__, __LINE__, __VA_ARGS__); \
57  }
58 
63 
65 using Span = tvm::Span;
67 
71 class RelayNode : public Object {
72  public:
75  mutable Span span;
76 
77  static constexpr const char* _type_key = "relay.Node";
79 };
80 
89 class IdNode : public Object {
90  public:
97 
98  void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("name_hint", &name_hint); }
99 
100  bool SEqualReduce(const IdNode* other, SEqualReducer equal) const {
101  return equal.FreeVarEqualImpl(this, other);
102  }
103 
104  void SHashReduce(SHashReducer hash_reduce) const { hash_reduce.FreeVarHashImpl(this); }
105 
106  static constexpr const char* _type_key = "relay.Id";
107  static constexpr const bool _type_has_method_sequal_reduce = true;
108  static constexpr const bool _type_has_method_shash_reduce = true;
110 };
111 
112 class Id : public ObjectRef {
113  public:
118  TVM_DLL explicit Id(String name_hint);
119 
121 };
122 
132 TVM_DLL String PrettyPrint(const ObjectRef& node);
133 
148 TVM_DLL String AsText(const ObjectRef& node, bool show_meta_data = true,
149  runtime::TypedPackedFunc<String(ObjectRef)> annotate = nullptr);
150 
151 } // namespace relay
152 } // namespace tvm
153 
154 #endif // TVM_RELAY_BASE_H_
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
Reference to PrimExprNode.
Definition: expr.h:115
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:137
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:121
void FreeVarHashImpl(const runtime::Object *var) const
Implementation for hash for a free var.
Definition: structural_hash.h:203
The source name of a file span.
Definition: source_map.h:67
Stores locations in frontend source that generated a node.
Definition: source_map.h:87
Definition: source_map.h:120
The unique identifier of variables.
Definition: base.h:89
static constexpr const char * _type_key
Definition: base.h:106
bool SEqualReduce(const IdNode *other, SEqualReducer equal) const
Definition: base.h:100
void VisitAttrs(tvm::AttrVisitor *v)
Definition: base.h:98
static constexpr const bool _type_has_method_shash_reduce
Definition: base.h:108
TVM_DECLARE_FINAL_OBJECT_INFO(IdNode, Object)
static constexpr const bool _type_has_method_sequal_reduce
Definition: base.h:107
String name_hint
The name of the variable, this only acts as a hint to the user, and is not used for equality.
Definition: base.h:96
void SHashReduce(SHashReducer hash_reduce) const
Definition: base.h:104
Definition: base.h:112
Id(String name_hint)
The constructor.
TVM_DEFINE_OBJECT_REF_METHODS(Id, ObjectRef, IdNode)
This is the base node container of all relay structures.
Definition: base.h:71
static constexpr const char * _type_key
Definition: base.h:77
Span span
The location of the program in a SourceFragment can be null, check with span.defined()
Definition: base.h:75
TVM_DECLARE_BASE_OBJECT_INFO(RelayNode, Object)
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Reference to string objects.
Definition: string.h:98
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
tvm::SourceName SourceName
Definition: base.h:64
String PrettyPrint(const ObjectRef &node)
Pretty print a node for debug purposes.
tvm::SpanNode SpanNode
Definition: base.h:66
tvm::Span Span
Definition: base.h:65
String AsText(const ObjectRef &node, bool show_meta_data=true, runtime::TypedPackedFunc< String(ObjectRef)> annotate=nullptr)
Render the node as a string in the text format.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
Definitions and helper macros for IR/AST nodes.
A map from source names to source code.
TIR expressions.