tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Namespaces | Macros | Functions
utils.h File Reference
#include <tvm/tir/block_scope.h>
#include <tvm/tir/stmt.h>
#include <unordered_map>
Include dependency graph for utils.h:

Go to the source code of this file.

Namespaces

 tvm
 Performance counters for profiling via the PAPI library.
 
 tvm::tir
 

Macros

#define TVM_SREF_AS_OR_ERR(Result, SRef, Type)
 A helper macro to convert an sref to the statement it points to, then check if the downcasting succeeded. More...
 
#define TVM_SREF_TO_BLOCK(SRef)
 A helper macro to convert an sref to the block it points to,. More...
 
#define TVM_SREF_TO_FOR(SRef)
 A helper macro to convert an sref to the for-loop it points to. More...
 
#define TVM_TYPE_AS_OR_ERR(Result, From, Type)
 Downcast a TVM ObjectRef to its corresponding container using ObjectRef::as<Type>, then check if the downcasting succeeded. More...
 
#define TVM_TYPE_AS(From, Type)
 Downcast a TVM ObjectRef to its corresponding container using ObjectRef::as<Type>, throwing an internal error if downcast fails. More...
 

Functions

void tvm::tir::SetSeqIndex (std::unordered_map< const StmtNode *, StmtSRef > &stmt2ref, const Stmt &stmt, int seq_index, bool include_loops=true)
 Set the StmtSRefNode::seq_index field for stmt. More...
 
void tvm::tir::SetSeqIndexInChildren (std::unordered_map< const StmtNode *, StmtSRef > &stmt2ref, const SeqStmtNode *seq_stmt, bool include_loops=true)
 Update seq_index of the children of a SeqStmt. More...
 

Macro Definition Documentation

◆ TVM_SREF_AS_OR_ERR

#define TVM_SREF_AS_OR_ERR (   Result,
  SRef,
  Type 
)
Value:
SRef->StmtAs<Type>(); \
ICHECK(Result)

A helper macro to convert an sref to the statement it points to, then check if the downcasting succeeded.

Parameters
ResultThe result variable, used for checking
SRefThe SRef to be cast
TypeThe type to be cast to, can be Block or For

◆ TVM_SREF_TO_BLOCK

#define TVM_SREF_TO_BLOCK (   SRef)
Value:
[&]() { \
auto result = TVM_SREF_AS_OR_ERR(result, (SRef), ::tvm::tir::BlockNode) \
<< "TypeError: Expects StmtSRef `" << #SRef << "` points to `Block`, but gets: " \
<< ((SRef)->stmt ? (SRef)->stmt->GetTypeKey() : "None"); \
return result; \
}()
A block is a basic schedule unit in TIR.
Definition: stmt.h:1258
#define TVM_SREF_AS_OR_ERR(Result, SRef, Type)
A helper macro to convert an sref to the statement it points to, then check if the downcasting succee...
Definition: utils.h:37

A helper macro to convert an sref to the block it points to,.

Throws an internal error if downcasting fails. The variable name in the parent scope is used for the error message.

Parameters
SRefThe SRef to be cast

◆ TVM_SREF_TO_FOR

#define TVM_SREF_TO_FOR (   SRef)
Value:
[&]() { \
auto result = TVM_SREF_AS_OR_ERR(result, (SRef), ::tvm::tir::ForNode) \
<< "TypeError: Expects StmtSRef `" << #SRef << "` points to `Loop`, but gets: " \
<< ((SRef)->stmt ? (SRef)->stmt->GetTypeKey() : "None"); \
return result; \
}()
A for loop, with possible type annotations.
Definition: stmt.h:967

A helper macro to convert an sref to the for-loop it points to.

Throws an internal error if downcasting fails. The variable name in the parent scope is used for the error message.

Parameters
SRefThe SRef to be cast

◆ TVM_TYPE_AS

#define TVM_TYPE_AS (   From,
  Type 
)
Value:
[&]() { \
auto result = TVM_TYPE_AS_OR_ERR(result, (From), Type) \
<< "TypeError: Expects `" << #From << "` to have type `" << Type::_type_key \
<< "`, but gets: " << ((From).defined() ? (From)->GetTypeKey() : "None"); \
return result; \
}()
#define TVM_TYPE_AS_OR_ERR(Result, From, Type)
Downcast a TVM ObjectRef to its corresponding container using ObjectRef::as<Type>,...
Definition: utils.h:80

Downcast a TVM ObjectRef to its corresponding container using ObjectRef::as<Type>, throwing an internal error if downcast fails.

Parameters
FromThe ObjectRef to be downcast
TypeThe type to be downcast to

◆ TVM_TYPE_AS_OR_ERR

#define TVM_TYPE_AS_OR_ERR (   Result,
  From,
  Type 
)
Value:
From.as<Type>(); \
ICHECK(Result)

Downcast a TVM ObjectRef to its corresponding container using ObjectRef::as<Type>, then check if the downcasting succeeded.

Parameters
ResultThe result variable, used for checking
FromThe ObjectRef to be downcast
TypeThe type to be downcast to