25 #ifndef TVM_TIR_USMP_UTILS_H_ 26 #define TVM_TIR_USMP_UTILS_H_ 86 v->Visit(
"name_hint", &name_hint);
87 v->Visit(
"size_bytes", &size_bytes);
88 v->Visit(
"pool_candidates", &pool_candidates);
89 v->Visit(
"alignment", &alignment);
90 v->Visit(
"conflicts", &conflicts);
91 v->Visit(
"kind", &kind);
101 hash_reduce(name_hint);
102 hash_reduce(size_bytes);
103 hash_reduce(alignment);
104 hash_reduce(conflicts);
105 hash_reduce(pool_candidates);
115 static constexpr
const char* _type_key =
"tir.usmp.BufferInfo";
145 v->Visit(
"buffer_info_stmts", &buffer_info_stmts);
146 v->Visit(
"memory_pressure", &memory_pressure);
155 hash_reduce(buffer_info_stmts);
156 hash_reduce(memory_pressure);
176 v->Visit(
"pool_info", &pool_info);
177 v->Visit(
"byte_offset", &byte_offset);
185 hash_reduce(pool_info);
186 hash_reduce(byte_offset);
189 static constexpr
const char* _type_key =
"tir.usmp.PoolAllocation";
211 v->Visit(
"pool_info", &pool_info);
212 v->Visit(
"allocated_size", &allocated_size);
213 v->Visit(
"pool_var_idx", &pool_var_idx);
222 hash_reduce(pool_info);
223 hash_reduce(allocated_size);
224 hash_reduce(pool_var_idx);
227 static constexpr
const char* _type_key =
"tir.usmp.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";
325 #endif // TVM_TIR_USMP_UTILS_H_ Integer alignment
The byte alignment required for buffers that will placed within the pool.
Definition: utils.h:79
BufferInfoKind
A special kind to distinguish between I/O tensors to the model and intermediate tensors of the model...
Definition: utils.h:60
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.
constexpr const char * kUSMPCustomAlgorithmOption
PassContext option to specify a custom memory planning algorithm in USMP. The algorithm should be pro...
Definition: utils.h:52
Array< ObjectRef > conflicts
The liveness conflicting other buffer info objects.
Definition: utils.h:81
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
bool SEqualReduce(const AllocatedPoolInfoNode *other, SEqualReducer equal) const
Definition: utils.h:216
Map< String, PoolAllocation > GetIOPoolAllocations(const Map< BufferInfo, PoolAllocation > &buffer_info_to_pool_allocation)
Obtains I/O tensor names to their PoolAllocation objects.
This object contains information post-allocation for PoolInfo objects.
Definition: utils.h:202
void SHashReduce(SHashReducer hash_reduce) const
Definition: utils.h:184
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
Integer byte_offset
The byte offset within the pool.
Definition: utils.h:173
The object definition for relay.build argument type of memory pools.
bool SEqualReduce(const BufferInfoAnalysisNode *other, SEqualReducer equal) const
Definition: utils.h:149
void VisitAttrs(tvm::AttrVisitor *v)
Definition: utils.h:144
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:110
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
void VisitAttrs(tvm::AttrVisitor *v)
Definition: utils.h:175
Base class for WorkspacePoolInfo and ConstantPoolInfo.
Definition: memory_pools.h:133
Optional< Integer > pool_var_idx
An optional associated pool Var index of PrimFunc params.
Definition: utils.h:208
Integer allocated_size
The allocated size into this pool.
Definition: utils.h:206
base class of all object containers.
Definition: object.h:167
PoolInfo pool_info
The assigned PoolInfo object.
Definition: utils.h:204
#define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:744
bool SEqualReduce(const PoolAllocationNode *other, SEqualReducer equal) const
Definition: utils.h:180
Integer memory_pressure
This represent maximum amount of memory being used at any point of time in the inference. This value is largely the best allocation an algorithm could achieve. Due to the complexities of conflict graphs, it would not be feasible to achieve this value, practically. However, it can be useful for iterative algorithms to know this value to define termination criteria.
Definition: utils.h:142
String name_hint
The name of the buffer var.
Definition: utils.h:73
Map< BufferInfo, tir::Stmt > buffer_info_stmts
The BufferInfo object and its associated TIR statement.
Definition: utils.h:134
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
This is a composite node that is produced by extract_buffer_info analysis pass that contains useful g...
Definition: utils.h:132
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Integer CalculateModuleWorkspaceSize(const IRModule &mod)
Calculate workspace required to execute a IRModule with main expressed in TIR.
void SHashReduce(SHashReducer hash_reduce) const
Definition: utils.h:100
Reference to string objects.
Definition: string.h:98
Abstract device memory management API.
Allocate a buffer that can be used in body.
Definition: stmt.h:455
constexpr const char * kUSMPUseWorkspaceIO
PassContext option to enable placing I/O tensors in the workspace.
Definition: utils.h:47
Array< PoolInfo > pool_candidates
The pool candidates that this buffer can get pooled to.
Definition: utils.h:77
Allocate a buffer that can be used in body.
Definition: stmt.h:537
Base class of all object reference.
Definition: object.h:511
The pool allocation produced after the USMP algorithm.
Definition: utils.h:169
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
PoolInfo pool_info
The assigned WorkspacePoolInfo or ConstantPoolInfo object.
Definition: utils.h:171
Integer CalculateExtentsSize(const AllocateNode *op)
Calculate the size of the extents in bytes.
Managed reference class to IRModuleNode.
Definition: module.h:348
Compilation target object.
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
constexpr const char * kUSMPEnableOption
PassContext option to enable the USMP.
Definition: utils.h:39
BufferInfoKind kind
Whether BufferInfo object retains info about IO tensors or intermediaries.
Definition: utils.h:83
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Integer size_bytes
The size in terms of bytes.
Definition: utils.h:75
bool SEqualReduce(const BufferInfoNode *other, SEqualReducer equal) const
Definition: utils.h:94
void VisitAttrs(tvm::AttrVisitor *v)
Definition: utils.h:85
Describes an abstract memory buffer that will get allocated inside a pool. The actual memory buffer i...
Definition: utils.h:71
Array< BufferInfo > ConvertToArrayOfBufferInfo(const Map< BufferInfo, Stmt > &buffer_info_map)
Convert the IR-bound BufferInfo map to an array of BufferInfo.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: utils.h:210
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
constexpr const char * kUSMPAlgorithmOption
PassContext option to select the memory planning algorithm in USMP.
Definition: utils.h:43
void SHashReduce(SHashReducer hash_reduce) const
Definition: utils.h:221
void SHashReduce(SHashReducer hash_reduce) const
Definition: utils.h:154
Container of constant int that adds more constructors.
Definition: expr.h:622