56 #ifndef TVM_IR_TRANSFORM_H_
57 #define TVM_IR_TRANSFORM_H_
116 template <
typename TObjectRef>
119 static_assert(std::is_base_of<ObjectRef, TObjectRef>::value,
120 "Can only call GetAttr with ObjectRef types.");
121 if (!
config.defined())
return default_value;
122 auto it =
config.find(key);
124 return Downcast<Optional<TObjectRef>>((*it).second);
126 return default_value;
130 template <
typename TObjectRef>
140 v->Visit(
"config", &
config);
151 ICHECK(
GetTraceStackSize()) <<
"Trace stack is currently empty. Please double check.";
156 ICHECK(
GetTraceStackSize()) <<
"Trace stack is currently empty. Please double check.";
164 static constexpr
const char*
_type_key =
"transform.PassContext";
191 ICHECK(
get() !=
nullptr);
199 ICHECK(
get() !=
nullptr);
269 template <
typename ValueType>
271 using ValueNodeType =
typename ValueType::ContainerType;
273 uint32_t tindex = ValueNodeType::_GetOrAllocRuntimeTypeIndex();
293 ValueType legalized =
ret;
295 }
catch (Error& err) {
296 LOG(FATAL) <<
"AttributeError: expect config " << key <<
" to have type " << type_key
297 <<
", but received error when converting to this type.\n"
313 TVM_DLL
void EnterWithScope();
315 TVM_DLL
void ExitWithScope();
325 #define TVM_PASS_CTX_CONFIG_VAR_DEF static TVM_ATTRIBUTE_UNUSED uint32_t __make_PassContext_tid
333 #define TVM_REGISTER_PASS_CONFIG_OPTION(Key, ValueType) \
334 TVM_STR_CONCAT(TVM_PASS_CTX_CONFIG_VAR_DEF, __COUNTER__) = \
335 ::tvm::transform::PassContext::RegisterConfigOption<ValueType>(Key)
359 v->Visit(
"name", &
name);
364 static constexpr
const char*
_type_key =
"transform.PassInfo";
422 static constexpr
const char*
_type_key =
"transform.Pass";
480 v->Visit(
"passes", &
passes);
513 static constexpr
const char*
_type_key =
"transform.Sequential";
581 bool error_if_no_function_matches_regex =
false);
Runtime Array container types.
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 class to IRModuleNode.
Definition: module.h:366
static ReflectionVTable * Global()
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition: with.h:58
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Shared content of all specializations of hash map.
Definition: map.h:174
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
A custom smart pointer for Object.
Definition: object.h:362
Base class of all object reference.
Definition: object.h:519
friend SubRef Downcast(BaseRef ref)
Downcast a base reference type to a more specific type.
Definition: object.h:936
ObjectRef()=default
default constructor
const Object * get() const
Definition: object.h:554
Object * get_mutable() const
Definition: object.h:607
base class of all object containers.
Definition: object.h:171
static std::string TypeIndex2Key(uint32_t tindex)
Get the type key of the corresponding index from runtime.
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to string objects.
Definition: string.h:98
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:946
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
PassContextNode contains the information that a pass can rely on, such as analysis results.
Definition: transform.h:77
Array< String > required_pass
The list of required passes.
Definition: transform.h:83
Optional< ObjectRef > tuning_api_database
Database for tuning API.
Definition: transform.h:102
Array< ObjectRef > trace_stack
Trace stack for relax pass infra.
Definition: transform.h:96
static constexpr bool _type_has_method_sequal_reduce
Definition: transform.h:165
Array< ObjectRef > GetTraceStack()
Definition: transform.h:148
Optional< TObjectRef > GetConfig(const std::string &key, TObjectRef default_value) const
Definition: transform.h:131
void PopTrace()
Definition: transform.h:150
Optional< Map< String, Bool > > make_traceable
List of passes to be traced. If not defined, make every pass traceable.
Definition: transform.h:98
TVM_DECLARE_FINAL_OBJECT_INFO(PassContextNode, Object)
void SetNumEvals(int _num_evals)
Definition: transform.h:159
void PushTrace(ObjectRef new_trace)
Definition: transform.h:149
Optional< ObjectRef > GetTuningAPIDatabase()
Definition: transform.h:162
void IncNumEvals(int _num_evals)
Definition: transform.h:160
Optional< DiagnosticContext > diag_ctx
The diagnostic context.
Definition: transform.h:87
PassContextNode()=default
Optional< TObjectRef > GetConfig(const std::string &key, Optional< TObjectRef > default_value=Optional< TObjectRef >(nullptr)) const
Get a config value from the pass context.
Definition: transform.h:117
int num_evals
Number of evaluations conducted in the pass pipeline.
Definition: transform.h:100
void VisitAttrs(AttrVisitor *v)
Definition: transform.h:135
Array< String > disabled_pass
The list of disabled passes.
Definition: transform.h:85
int GetTraceStackSize()
Definition: transform.h:154
Array< instrument::PassInstrument > instruments
A list of pass instrument implementations.
Definition: transform.h:92
static constexpr const char * _type_key
Definition: transform.h:164
int opt_level
The default optimization level.
Definition: transform.h:80
Map< String, ObjectRef > config
Pass specific configurations.
Definition: transform.h:89
ObjectRef GetCurrentTrace()
Definition: transform.h:155
PassContext that is used to configure the pass behavior.
Definition: transform.h:182
static Map< String, Map< String, String > > ListConfigs()
Get all supported configuration names and metadata, registered within the PassContext.
const PassContextNode * operator->() const
const accessor.
Definition: transform.h:190
static PassContext Current()
Get the default pass context in the current scope.
bool PassEnabled(const PassInfo &info) const
Check whether a pass is enabled.
static uint32_t RegisterConfigOption(const char *key)
Register a valid configuration option and its ValueType for validation.
Definition: transform.h:270
friend class Internal
Definition: transform.h:321
PassContext(ObjectPtr< Object > n)
Definition: transform.h:185
PassContext()
Definition: transform.h:184
static PassContext Create()
Construct a PassContext containing the default configurations.
PassContextNode * operator->()
mutable accessor.
Definition: transform.h:198
void InstrumentEnterPassContext()
Call instrument implementations' callbacks when entering PassContext. The callbacks are called in ord...
void InstrumentExitPassContext()
Call instrument implementations' callbacks when exiting PassContext. The callbacks are called in orde...
bool InstrumentBeforePass(const IRModule &mod, const PassInfo &info) const
Call instrument implementations' callbacks before a pass run. The callbacks are called in order,...
void InstrumentAfterPass(const IRModule &mod, const PassInfo &info) const
Call instrument implementations callbacks after a pass run. The callbacks are called in order,...
A new diagnostic interface for TVM error reporting.
IRModule that holds the functions and type definitions.
IRModuleFrame IRModule()
The IRModule declaration statement.
Definition: module.h:359
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
PrimExpr ret(PrimExpr value, Span span=Span())
Return the value.
Runtime String container types.
RAII wrapper function to enter and exit a context object similar to python's with syntax.