24 #ifndef TVM_IR_ENV_FUNC_H_
25 #define TVM_IR_ENV_FUNC_H_
27 #include <tvm/ffi/function.h>
28 #include <tvm/ffi/reflection/registry.h>
55 refl::ObjectDef<EnvFuncNode>()
61 static constexpr
const char*
_type_key =
"ir.EnvFunc";
73 explicit EnvFunc(ObjectPtr<Object> n) : ObjectRef(n) {}
81 template <
typename... Args>
85 return n->
func(std::forward<Args>(args)...);
101 template <
typename FType>
113 template <
typename R,
typename... Args>
126 ObjectRef::operator=(other);
138 ICHECK(n !=
nullptr);
139 if constexpr (std::is_same_v<R, void>) {
140 n->
func(std::forward<Args>(args)...);
142 ffi::Any res = n->
func(std::forward<Args>(args)...);
143 if constexpr (std::is_same_v<R, ffi::Any>) {
146 return std::move(res).cast<R>();
A serializable function backed by TVM's global environment.
Definition: env_func.h:43
String name
Unique name of the global function.
Definition: env_func.h:46
static constexpr const char * _type_key
Definition: env_func.h:61
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: env_func.h:60
ffi::Function func
The internal packed function.
Definition: env_func.h:48
TVM_DECLARE_FINAL_OBJECT_INFO(EnvFuncNode, Object)
EnvFuncNode()
constructor
Definition: env_func.h:50
static void RegisterReflection()
Definition: env_func.h:52
Managed reference to EnvFuncNode.
Definition: env_func.h:70
EnvFunc(ObjectPtr< Object > n)
Definition: env_func.h:73
const EnvFuncNode * operator->() const
Definition: env_func.h:75
EnvFunc()
Definition: env_func.h:72
static EnvFunc Get(const String &name)
Get a global function based on the name.
ffi::Any operator()(Args &&... args) const
Invoke the function.
Definition: env_func.h:82
A typed version of EnvFunc. It is backed by a GlobalFuncNode internally.
Definition: env_func.h:114
TypedEnvFunc(ObjectPtr< Object > n)
Definition: env_func.h:119
TypedEnvFunc()
Definition: env_func.h:118
TSelf & operator=(const EnvFunc &other)
Assign global function to a TypedEnvFunc.
Definition: env_func.h:125
const EnvFuncNode * operator->() const
Definition: env_func.h:130
R operator()(Args... args) const
Invoke the function.
Definition: env_func.h:136
Please refer to TypedEnvFunc<R(Args..)>.
Definition: env_func.h:102
Definition: repr_printer.h:91
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
Definitions and helper macros for IR/AST nodes.