tvm
global_var_supply.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_IR_GLOBAL_VAR_SUPPLY_H_
25 #define TVM_IR_GLOBAL_VAR_SUPPLY_H_
26 
27 #include <string>
28 #include <unordered_map>
29 
30 #include "tvm/ir/expr.h"
31 #include "tvm/ir/module.h"
32 #include "tvm/ir/name_supply.h"
33 
34 namespace tvm {
35 
39 class GlobalVarSupplyNode : public Object {
40  public:
45 
51  explicit GlobalVarSupplyNode(NameSupply name_supply,
52  std::unordered_map<std::string, GlobalVar> name_to_var_map = {});
53 
60  GlobalVar FreshGlobal(String name, bool add_prefix = true);
61 
69  GlobalVar UniqueGlobalFor(const String& name, bool add_prefix = true);
70 
76  void ReserveGlobalVar(const GlobalVar& var, bool allow_conflict = false);
77 
78  void VisitAttrs(AttrVisitor* v) {}
79 
82 
83  static constexpr const char* _type_key = "GlobalVarSupply";
84  static constexpr const bool _type_has_method_sequal_reduce = false;
85  static constexpr const bool _type_has_method_shash_reduce = false;
87 
88  private:
89  std::unordered_map<std::string, GlobalVar> name_to_var_map_;
90 };
91 
96 class GlobalVarSupply : public ObjectRef {
97  public:
103  TVM_DLL explicit GlobalVarSupply(const NameSupply& name_supply = NameSupply(),
104  std::unordered_map<std::string, GlobalVar> name_to_var_map = {});
105 
111  TVM_DLL explicit GlobalVarSupply(const Array<IRModule>& modules);
112 
118  TVM_DLL explicit GlobalVarSupply(const IRModule module);
119 
122 };
123 
124 } // namespace tvm
125 
126 #endif // TVM_IR_GLOBAL_VAR_SUPPLY_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
GlobalVarSupply can be used to generate unique GlobalVars.
Definition: global_var_supply.h:39
void ReserveGlobalVar(const GlobalVar &var, bool allow_conflict=false)
Reserves an existing GlobalVar with this supply.
static constexpr const char * _type_key
Definition: global_var_supply.h:83
static constexpr const bool _type_has_method_sequal_reduce
Definition: global_var_supply.h:84
TVM_DECLARE_FINAL_OBJECT_INFO(GlobalVarSupplyNode, Object)
NameSupply name_supply_
The NameSupply used to generate unique name hints to GlobalVars.
Definition: global_var_supply.h:81
static constexpr const bool _type_has_method_shash_reduce
Definition: global_var_supply.h:85
void VisitAttrs(AttrVisitor *v)
Definition: global_var_supply.h:78
GlobalVar FreshGlobal(String name, bool add_prefix=true)
Generates a unique GlobalVar from this supply.
GlobalVarSupplyNode()
Empty constructor. Will use an empty NameSupply.
Definition: global_var_supply.h:44
GlobalVar UniqueGlobalFor(const String &name, bool add_prefix=true)
Looks up for a GlobalVar with the given name in this supply. If no entry is found,...
GlobalVarSupplyNode(NameSupply name_supply, std::unordered_map< std::string, GlobalVar > name_to_var_map={})
Constructor.
Managed reference class to GlobalVarSupplyNode.
Definition: global_var_supply.h:96
GlobalVarSupply(const Array< IRModule > &modules)
Constructs a supply from an array of IRModules. GlobalVars generated by this supply are guaranteed no...
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(GlobalVarSupply, ObjectRef, GlobalVarSupplyNode)
GlobalVarSupply(const IRModule module)
Constructs a GlobalVarSupply from an IRModule. GlobalVars generated by this supply are guaranteed not...
GlobalVarSupply(const NameSupply &name_supply=NameSupply(), std::unordered_map< std::string, GlobalVar > name_to_var_map={})
Constructor.
Managed reference to GlobalVarNode.
Definition: expr.h:487
Managed reference class to IRModuleNode.
Definition: module.h:366
Managed reference class to NameSupplyNode.
Definition: name_supply.h:112
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
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
Base expr nodes in TVM.
IRModule that holds the functions and type definitions.
NameSupply that can be used to generate unique variable names.
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36