25 #ifndef TVM_TIR_USMP_UTILS_H_
26 #define TVM_TIR_USMP_UTILS_H_
91 v->Visit(
"kind", &
kind);
115 static constexpr
const char*
_type_key =
"tir.usmp.BufferInfo";
189 static constexpr
const char*
_type_key =
"tir.usmp.PoolAllocation";
227 static constexpr
const char*
_type_key =
"ir.AllocatedPoolInfo";
257 static constexpr
const char* kPoolCandidatesAllocateAttr =
"candidate_memory_pools";
263 static constexpr
const char* kInputTensorAllocate =
"input_tensor";
269 static constexpr
const char* kOutputTensorAllocate =
"output_tensor";
313 static constexpr
const char* kPoolArgs =
"pool_args";
319 static constexpr
const char* kIOTensorPoolAllocations =
"io_tensor_pool_allocations";
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:348
Container of constant int that adds more constructors.
Definition: expr.h:622
Base class for WorkspacePoolInfo and ConstantPoolInfo.
Definition: memory_pools.h:133
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:110
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Base class of all object reference.
Definition: object.h:515
base class of all object containers.
Definition: object.h:167
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to string objects.
Definition: string.h:98
Allocate a buffer that can be used in body.
Definition: stmt.h:537
Allocate a buffer that can be used in body.
Definition: stmt.h:455
AllocatedPoolInfo(PoolInfo pool_info, Integer allocated_size, Integer pool_var_idx=Integer())
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(AllocatedPoolInfo, ObjectRef, AllocatedPoolInfoNode)
BufferInfoAnalysis(Map< BufferInfo, tir::Stmt > buffer_info_stmts, Integer memory_pressure)
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(BufferInfoAnalysis, ObjectRef, BufferInfoAnalysisNode)
BufferInfo(String name_hint, Integer size_bytes, Array< PoolInfo > pool_candidates, Integer alignment=runtime::kDefaultWorkspaceAlignment, BufferInfoKind kind=BufferInfoKind::kIntermediate)
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(BufferInfo, ObjectRef, BufferInfoNode)
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(PoolAllocation, ObjectRef, PoolAllocationNode)
PoolAllocation(PoolInfo pool_info, Integer byte_offset)
Abstract device memory management API.
The object definition for relay.build argument type of memory pools.
constexpr int kDefaultWorkspaceAlignment
Number of bytes each allocation must align to by default in the workspace buffer to service intermedi...
Definition: device_api.h:73
Array< BufferInfo > ConvertToArrayOfBufferInfo(const Map< BufferInfo, Stmt > &buffer_info_map)
Convert the IR-bound BufferInfo map to an array of BufferInfo.
Integer CalculateModuleWorkspaceSize(const IRModule &mod)
Calculate workspace required to execute a IRModule with main expressed in TIR.
Map< Stmt, PoolAllocation > AssignStmtPoolAllocations(const Map< BufferInfo, Stmt > &buffer_info_to_stmt, const Map< BufferInfo, PoolAllocation > &buffer_info_to_pool_allocation)
Joins the Stmt nodes with PoolAllocation objects.
Integer CalculateExtentsSize(const AllocateNode *op)
Calculate the size of the extents in bytes.
BufferInfoKind
A special kind to distinguish between I/O tensors to the model and intermediate tensors of the model.
Definition: utils.h:60
Map< String, PoolAllocation > GetIOPoolAllocations(const Map< BufferInfo, PoolAllocation > &buffer_info_to_pool_allocation)
Obtains I/O tensor names to their PoolAllocation objects.
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 equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
constexpr const char * kUSMPUseWorkspaceIO
PassContext option to enable placing I/O tensors in the workspace.
Definition: utils.h:47
constexpr const char * kUSMPCustomAlgorithmOption
PassContext option to specify a custom memory planning algorithm in USMP. The algorithm should be pro...
Definition: utils.h:52
constexpr const char * kUSMPAlgorithmOption
PassContext option to select the memory planning algorithm in USMP.
Definition: utils.h:43
constexpr const char * kUSMPEnableOption
PassContext option to enable the USMP.
Definition: utils.h:39
This object contains information post-allocation for PoolInfo objects.
Definition: utils.h:202
Optional< Integer > pool_var_idx
An optional associated pool Var index of PrimFunc params.
Definition: utils.h:208
void SHashReduce(SHashReducer hash_reduce) const
Definition: utils.h:221
TVM_DECLARE_FINAL_OBJECT_INFO(AllocatedPoolInfoNode, Object)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: utils.h:210
bool SEqualReduce(const AllocatedPoolInfoNode *other, SEqualReducer equal) const
Definition: utils.h:216
static constexpr const char * _type_key
Definition: utils.h:227
Integer allocated_size
The allocated size into this pool.
Definition: utils.h:206
PoolInfo pool_info
The assigned PoolInfo object.
Definition: utils.h:204
This is a composite node that is produced by extract_buffer_info analysis pass that contains useful g...
Definition: utils.h:132
bool SEqualReduce(const BufferInfoAnalysisNode *other, SEqualReducer equal) const
Definition: utils.h:149
Map< BufferInfo, tir::Stmt > buffer_info_stmts
The BufferInfo object and its associated TIR statement.
Definition: utils.h:134
void VisitAttrs(tvm::AttrVisitor *v)
Definition: utils.h:144
void SHashReduce(SHashReducer hash_reduce) const
Definition: utils.h:154
Integer memory_pressure
This represent maximum amount of memory being used at any point of time in the inference....
Definition: utils.h:142
Describes an abstract memory buffer that will get allocated inside a pool. The actual memory buffer i...
Definition: utils.h:71
Integer size_bytes
The size in terms of bytes.
Definition: utils.h:75
TVM_DECLARE_FINAL_OBJECT_INFO(BufferInfoNode, Object)
static constexpr const char * _type_key
Definition: utils.h:115
BufferInfoKind kind
Whether BufferInfo object retains info about IO tensors or intermediaries.
Definition: utils.h:83
Array< PoolInfo > pool_candidates
The pool candidates that this buffer can get pooled to.
Definition: utils.h:77
Integer alignment
The byte alignment required for buffers that will placed within the pool.
Definition: utils.h:79
Array< ObjectRef > conflicts
The liveness conflicting other buffer info objects.
Definition: utils.h:81
void SetConflicts(Array< ObjectRef > conflicting_buffer_info_objs)
Set the liveness conflicts of this BufferInfo.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: utils.h:85
String name_hint
The name of the buffer var.
Definition: utils.h:73
bool SEqualReduce(const BufferInfoNode *other, SEqualReducer equal) const
Definition: utils.h:94
void SHashReduce(SHashReducer hash_reduce) const
Definition: utils.h:100
The pool allocation produced after the USMP algorithm.
Definition: utils.h:169
static constexpr const char * _type_key
Definition: utils.h:189
void VisitAttrs(tvm::AttrVisitor *v)
Definition: utils.h:175
void SHashReduce(SHashReducer hash_reduce) const
Definition: utils.h:184
Integer byte_offset
The byte offset within the pool.
Definition: utils.h:173
TVM_DECLARE_FINAL_OBJECT_INFO(PoolAllocationNode, Object)
bool SEqualReduce(const PoolAllocationNode *other, SEqualReducer equal) const
Definition: utils.h:180
PoolInfo pool_info
The assigned WorkspacePoolInfo or ConstantPoolInfo object.
Definition: utils.h:171
Compilation target object.