tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
interpreter.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 
34 #ifndef TVM_RELAY_INTERPRETER_H_
35 #define TVM_RELAY_INTERPRETER_H_
36 
37 #include <tvm/ir/module.h>
38 #include <tvm/relay/expr.h>
40 #include <tvm/runtime/object.h>
41 #include <tvm/target/target.h>
42 
43 #include <unordered_set>
44 
45 namespace tvm {
46 namespace relay {
47 
50  public:
62 
64 
66  v->Visit("env", &env);
67  v->Visit("func", &func);
68  }
69 
70  static constexpr const char* _type_key = "interpreter.Closure";
72 };
73 
75  public:
78 };
79 
81 class RecClosureObj : public Object {
82  public:
87 
89 
91  v->Visit("clos", &clos);
92  v->Visit("bind", &bind);
93  }
94 
95  static constexpr const char* _type_key = "interpreter.RecClosure";
97 };
98 
99 class RecClosure : public ObjectRef {
100  public:
101  TVM_DLL RecClosure(InterpreterClosure clos, Var bind);
103 };
104 
105 struct RefValueObj : Object {
106  mutable ObjectRef value;
107 
109 
110  void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("value", &value); }
111 
112  static constexpr const char* _type_key = "relay.RefValue";
114 };
115 
116 class RefValue : public ObjectRef {
117  public:
118  TVM_DLL RefValue(ObjectRef val);
120 };
121 
123  int32_t tag;
124 
126 
129 
131  v->Visit("tag", &tag);
132  v->Visit("fields", &fields);
133  v->Visit("constructor", &constructor);
134  }
135 
136  static constexpr const char* _type_key = "relay.ConstructorValue";
138 };
139 
140 class ConstructorValue : public ObjectRef {
141  public:
142  TVM_DLL ConstructorValue(int32_t tag, tvm::Array<ObjectRef> fields, Constructor construtor = {});
143 
145 };
146 
175  Target target);
176 
190 ObjectRef Eval(Expr expr, Map<GlobalTypeVar, TypeData> type_definitions,
191  std::unordered_set<String> import_set, Device device, Target target,
192  Map<String, ObjectRef> attrs = {});
193 
194 } // namespace relay
195 } // namespace tvm
196 
197 #endif // TVM_RELAY_INTERPRETER_H_
ObjectRef value
Definition: interpreter.h:106
TVM_DECLARE_FINAL_OBJECT_INFO(InterpreterClosureObj, runtime::ClosureObj)
int32_t tag
Definition: interpreter.h:123
Managed reference to FunctionNode.
Definition: function.h:105
RefValueObj()
Definition: interpreter.h:108
IRModule that holds the functions and type definitions.
Relay expression language.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Constructor constructor
Optional field tracking ADT constructor.
Definition: interpreter.h:128
Var bind
variable the closure bind to.
Definition: interpreter.h:86
Definition: interpreter.h:122
TypedPackedFunc< ObjectRef(Array< Expr >)> EvalFunction(IRModule mod, Expr expr, Device device, Target target)
Returns a packed function over Relay expressions which will evaluate expr applied to those arguments...
base class of all object containers.
Definition: object.h:167
tvm::Array< ObjectRef > fields
Definition: interpreter.h:125
Definition: interpreter.h:99
Runtime Closure container types.
Definition: interpreter.h:105
Managed reference to ConstructorNode.
Definition: adt.h:88
reference to closure.
Definition: closure.h:44
Definition: interpreter.h:74
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
Definition: interpreter.h:140
void VisitAttrs(tvm::AttrVisitor *v)
Definition: interpreter.h:65
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
InterpreterClosureObj()
Definition: interpreter.h:63
The container type of Closures used by the interpreter.
Definition: interpreter.h:49
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
Definition: interpreter.h:116
Managed reference to RelayExprNode.
Definition: expr.h:433
static constexpr const char * _type_key
Definition: interpreter.h:70
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:713
void VisitAttrs(tvm::AttrVisitor *v)
Definition: interpreter.h:110
DLDevice Device
Definition: ndarray.h:43
Managed reference class to TargetNode.
Definition: target.h:183
void VisitAttrs(tvm::AttrVisitor *v)
Definition: interpreter.h:130
Base class of all object reference.
Definition: object.h:511
An object representing a closure. This object is used by both the Relay VM and interpreter.
Definition: closure.h:36
A managed object in the TVM runtime.
Managed reference class to IRModuleNode.
Definition: module.h:348
ObjectRef Eval(Expr expr, Map< GlobalTypeVar, TypeData > type_definitions, std::unordered_set< String > import_set, Device device, Target target, Map< String, ObjectRef > attrs={})
Evaluates expr and returns its result.
Compilation target object.
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
InterpreterClosure clos
The closure.
Definition: interpreter.h:84
The container type of RecClosure.
Definition: interpreter.h:81
Definition: expr.h:234
void VisitAttrs(tvm::AttrVisitor *v)
Definition: interpreter.h:90
tvm::Map< Var, ObjectRef > env
The set of free variables in the closure.
Definition: interpreter.h:56
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
Function func
The function which implements the closure.
Definition: interpreter.h:61
RecClosureObj()
Definition: interpreter.h:88