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 <tvm/ffi/reflection/registry.h>
28 #include <tvm/ir/expr.h>
29 #include <tvm/ir/module.h>
30 #include <tvm/ir/name_supply.h>
31 
32 #include <string>
33 #include <unordered_map>
34 
35 namespace tvm {
36 
40 class GlobalVarSupplyNode : public Object {
41  public:
46 
52  explicit GlobalVarSupplyNode(NameSupply name_supply,
53  std::unordered_map<std::string, GlobalVar> name_to_var_map = {});
54 
61  GlobalVar FreshGlobal(ffi::String name, bool add_prefix = true);
62 
70  GlobalVar UniqueGlobalFor(const ffi::String& name, bool add_prefix = true);
71 
77  void ReserveGlobalVar(const GlobalVar& var, bool allow_conflict = false);
78 
79  static void RegisterReflection() {
80  namespace refl = tvm::ffi::reflection;
81  refl::ObjectDef<GlobalVarSupplyNode>();
82  }
83 
86 
87  static constexpr const bool _type_mutable = true;
89 
90  private:
91  std::unordered_map<std::string, GlobalVar> name_to_var_map_;
92 };
93 
98 class GlobalVarSupply : public ObjectRef {
99  public:
105  TVM_DLL explicit GlobalVarSupply(const NameSupply& name_supply = NameSupply(),
106  std::unordered_map<std::string, GlobalVar> name_to_var_map = {});
107 
113  TVM_DLL explicit GlobalVarSupply(const ffi::Array<IRModule>& modules);
114 
120  TVM_DLL explicit GlobalVarSupply(const IRModule module);
121 
123 };
124 
125 } // namespace tvm
126 
127 #endif // TVM_IR_GLOBAL_VAR_SUPPLY_H_
GlobalVarSupply can be used to generate unique GlobalVars.
Definition: global_var_supply.h:40
void ReserveGlobalVar(const GlobalVar &var, bool allow_conflict=false)
Reserves an existing GlobalVar with this supply.
GlobalVar UniqueGlobalFor(const ffi::String &name, bool add_prefix=true)
Looks up for a GlobalVar with the given name in this supply. If no entry is found,...
NameSupply name_supply_
The NameSupply used to generate unique name hints to GlobalVars.
Definition: global_var_supply.h:85
static void RegisterReflection()
Definition: global_var_supply.h:79
GlobalVar FreshGlobal(ffi::String name, bool add_prefix=true)
Generates a unique GlobalVar from this supply.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.GlobalVarSupply", GlobalVarSupplyNode, Object)
static constexpr const bool _type_mutable
Definition: global_var_supply.h:87
GlobalVarSupplyNode()
Empty constructor. Will use an empty NameSupply.
Definition: global_var_supply.h:45
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:98
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(GlobalVarSupply, ObjectRef, GlobalVarSupplyNode)
GlobalVarSupply(const ffi::Array< IRModule > &modules)
Constructs a supply from an array of IRModules. GlobalVars generated by this supply are guaranteed no...
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:481
Managed reference class to IRModuleNode.
Definition: module.h:256
Managed reference class to NameSupplyNode.
Definition: name_supply.h:111
Base expr nodes in TVM.
IRModule that holds the functions and type definitions.
NameSupply that can be used to generate unique variable names.
Definition: repr_printer.h:91
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37