19 #ifndef TVM_SCRIPT_PRINTER_TRACED_OBJECT_FUNCTOR_H_ 20 #define TVM_SCRIPT_PRINTER_TRACED_OBJECT_FUNCTOR_H_ 23 #include <tvm/runtime/logging.h> 28 #include <type_traits> 29 #include <unordered_map> 41 using DispatchTable = std::unordered_map<std::string, std::vector<runtime::PackedFunc>>;
52 const String& token, uint32_t type_index);
81 template <
typename R,
typename... Args>
86 template <
class TObjectRef,
class TCallable>
87 using IsDispatchFunction =
88 typename std::is_convertible<TCallable, std::function<R(TracedObject<TObjectRef>, Args...)>>;
102 template <
class TObjectRef>
106 return dispatch_function(traced_object.
Get(), traced_object.
GetPath(), args...);
130 template <
typename TObjectRef,
typename TCallable,
131 typename = std::enable_if_t<IsDispatchFunction<TObjectRef, TCallable>::value>>
135 TObjectRef::ContainerType::RuntimeTypeIndex(),
137 [f = std::move(f)](TObjectRef
object,
ObjectPath path, Args... args) -> R {
138 return f(MakeTraced(object, path), args...);
150 template <
typename TObjectRef,
typename TCallable,
151 typename = std::enable_if_t<IsDispatchFunction<TObjectRef, TCallable>::value>>
175 #endif // TVM_SCRIPT_PRINTER_TRACED_OBJECT_FUNCTOR_H_ Traced wrapper for regular (non-container) TVM objects.
Definition: traced_object.h:39
Definitions and helper macros for IR/AST nodes.
TSelf & set_dispatch(TCallable &&f)
Set the default dispatch function.
Definition: traced_object_functor.h:152
const runtime::PackedFunc & GetDispatchFunction(const DispatchTable &dispatch_table, const String &token, uint32_t type_index)
Get function from dispatch table.
std::unordered_map< std::string, std::vector< runtime::PackedFunc > > DispatchTable
Definition: traced_object_functor.h:41
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
void RemoveDispatchFunction(DispatchTable *dispatch_table, const String &token, uint32_t type_index)
Remove function from dispatch table.
void remove_dispatch(String token, uint32_t type_index)
Remove dispatch function.
Definition: traced_object_functor.h:164
const RefT & Get() const
Access the wrapped object.
Definition: traced_object.h:115
Dynamic dispatch functor based on TracedObject.
Definition: traced_object_functor.h:82
TSelf & set_dispatch(String token, uint32_t type_index, runtime::PackedFunc f)
Set the dispatch function.
Definition: traced_object_functor.h:118
TSelf & set_dispatch(String token, TCallable f)
Set the dispatch function.
Definition: traced_object_functor.h:132
Reference to string objects.
Definition: string.h:97
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
const ObjectPath & GetPath() const
Get the path of the wrapped object.
Definition: traced_object.h:157
constexpr const char * kDefaultDispatchToken
Definition: traced_object_functor.h:73
Definition: object_path.h:122
void SetDispatchFunction(DispatchTable *dispatch_table, const String &token, uint32_t type_index, runtime::PackedFunc f)
Set function in dispatch table.
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:138
R operator()(const String &token, TracedObject< TObjectRef > traced_object, Args... args) const
Call the dispatch function.
Definition: traced_object_functor.h:103
Type-erased function used across TVM API.