tvm
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 
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_
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
Managed reference to ConstructorNode.
Definition: adt.h:88
Managed reference class to IRModuleNode.
Definition: module.h:366
Managed reference to RelayExprNode.
Definition: expr.h:442
Managed reference class to TargetNode.
Definition: target.h:200
Definition: interpreter.h:140
TVM_DEFINE_OBJECT_REF_METHODS(ConstructorValue, ObjectRef, ConstructorValueObj)
ConstructorValue(int32_t tag, tvm::Array< ObjectRef > fields, Constructor construtor={})
Managed reference to FunctionNode.
Definition: function.h:105
The container type of Closures used by the interpreter.
Definition: interpreter.h:49
tvm::Map< Var, ObjectRef > env
The set of free variables in the closure.
Definition: interpreter.h:56
Function func
The function which implements the closure.
Definition: interpreter.h:61
TVM_DECLARE_FINAL_OBJECT_INFO(InterpreterClosureObj, runtime::ClosureObj)
static constexpr const char * _type_key
Definition: interpreter.h:70
void VisitAttrs(tvm::AttrVisitor *v)
Definition: interpreter.h:65
InterpreterClosureObj()
Definition: interpreter.h:63
Definition: interpreter.h:74
TVM_DEFINE_OBJECT_REF_METHODS(InterpreterClosure, runtime::Closure, InterpreterClosureObj)
InterpreterClosure(tvm::Map< Var, ObjectRef > env, Function func)
The container type of RecClosure.
Definition: interpreter.h:81
void VisitAttrs(tvm::AttrVisitor *v)
Definition: interpreter.h:90
TVM_DECLARE_FINAL_OBJECT_INFO(RecClosureObj, Object)
static constexpr const char * _type_key
Definition: interpreter.h:95
InterpreterClosure clos
The closure.
Definition: interpreter.h:84
RecClosureObj()
Definition: interpreter.h:88
Var bind
variable the closure bind to.
Definition: interpreter.h:86
Definition: interpreter.h:99
TVM_DEFINE_OBJECT_REF_METHODS(RecClosure, ObjectRef, RecClosureObj)
RecClosure(InterpreterClosure clos, Var bind)
Definition: interpreter.h:116
RefValue(ObjectRef val)
TVM_DEFINE_OBJECT_REF_METHODS(RefValue, ObjectRef, RefValueObj)
Definition: expr.h:234
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
An object representing a closure. This object is used by both the Relay VM and interpreter.
Definition: closure.h:36
reference to closure.
Definition: closure.h:44
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
Runtime Closure container types.
IRModule that holds the functions and type definitions.
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,...
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.
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
DLDevice Device
Definition: ndarray.h:43
A managed object in the TVM runtime.
Relay expression language.
Definition: interpreter.h:122
TVM_DECLARE_FINAL_OBJECT_INFO(ConstructorValueObj, Object)
int32_t tag
Definition: interpreter.h:123
static constexpr const char * _type_key
Definition: interpreter.h:136
tvm::Array< ObjectRef > fields
Definition: interpreter.h:125
Constructor constructor
Optional field tracking ADT constructor.
Definition: interpreter.h:128
void VisitAttrs(tvm::AttrVisitor *v)
Definition: interpreter.h:130
Definition: interpreter.h:105
void VisitAttrs(tvm::AttrVisitor *v)
Definition: interpreter.h:110
ObjectRef value
Definition: interpreter.h:106
TVM_DECLARE_FINAL_OBJECT_INFO(RefValueObj, Object)
RefValueObj()
Definition: interpreter.h:108
static constexpr const char * _type_key
Definition: interpreter.h:112
Compilation target object.