2727#include < tvm/runtime/registry.h>
2828#include < tvm/target/target.h>
2929
30+ struct TVMConstantInfo ;
3031namespace tvm {
3132
3233/* !
3334 * \brief Describes a pool of memory accessible by one or more targets.
3435 */
3536struct PoolInfoNode : public Object {
37+ public:
3638 /* ! \brief The name of the memory pool */
3739 String pool_name;
3840 /* ! \brief The expected size hint to be used by the allocator.
3941 * The size_hint_bytes is set to kUnrestrictedPoolSizeHint
4042 * to indicate the pool is not size restricted.
4143 */
4244 Integer size_hint_bytes;
43- /* ! \brief The accessibility from each Target */
44- Map<Target, String> target_access; // 'rw' or 'ro'
4545 /* ! \brief The clock frequency of the memory in Hz */
4646 Integer clock_frequency_hz;
4747 /* ! \brief The read bandwidth in bytes/cycle */
@@ -60,10 +60,12 @@ struct PoolInfoNode : public Object {
6060 */
6161 bool is_internal = false ;
6262
63+ /* ! \brief The targets linked to the pool */
64+ Array<Target> targets;
65+
6366 void VisitAttrs (tvm::AttrVisitor* v) {
6467 v->Visit (" pool_name" , &pool_name);
6568 v->Visit (" size_hint_bytes" , &size_hint_bytes);
66- v->Visit (" target_access" , &target_access);
6769 v->Visit (" clock_frequency_hz" , &clock_frequency_hz);
6870 v->Visit (" read_bandwidth_bytes_per_cycle" , &read_bandwidth_bytes_per_cycle);
6971 v->Visit (" write_bandwidth_bytes_per_cycle" , &write_bandwidth_bytes_per_cycle);
@@ -75,8 +77,6 @@ struct PoolInfoNode : public Object {
7577
7678 bool SEqualReduce (const PoolInfoNode* other, SEqualReducer equal) const {
7779 return equal (pool_name, other->pool_name ) && equal (size_hint_bytes, other->size_hint_bytes ) &&
78- equal (target_access, other->target_access ) &&
79- equal (target_access, other->target_access ) &&
8080 equal (clock_frequency_hz, other->clock_frequency_hz ) &&
8181 equal (read_bandwidth_bytes_per_cycle, other->read_bandwidth_bytes_per_cycle ) &&
8282 equal (write_bandwidth_bytes_per_cycle, other->write_bandwidth_bytes_per_cycle ) &&
@@ -89,7 +89,6 @@ struct PoolInfoNode : public Object {
8989 void SHashReduce (SHashReducer hash_reduce) const {
9090 hash_reduce (pool_name);
9191 hash_reduce (size_hint_bytes);
92- hash_reduce (target_access);
9392 hash_reduce (clock_frequency_hz);
9493 hash_reduce (read_bandwidth_bytes_per_cycle);
9594 hash_reduce (write_bandwidth_bytes_per_cycle);
@@ -100,7 +99,7 @@ struct PoolInfoNode : public Object {
10099 }
101100
102101 static constexpr const char * _type_key = " ir.PoolInfo" ;
103- TVM_DECLARE_FINAL_OBJECT_INFO (PoolInfoNode, Object);
102+ TVM_DECLARE_BASE_OBJECT_INFO (PoolInfoNode, Object);
104103};
105104
106105/* !
@@ -129,18 +128,166 @@ static const int kUnknownReadBandwidth = -1;
129128/* ! \brief The write bandwidth is not known */
130129static const int kUnknownWriteBandwidth = -1 ;
131130
131+ /* ! \brief Base class for WorkspacePoolInfo and ConstantPoolInfo */
132132class PoolInfo : public ObjectRef {
133- public:
134- TVM_DLL PoolInfo (String pool_name, Map<Target, String> target_access,
135- Integer size_hint_bytes = kUnrestrictedPoolSizeHint ,
133+ protected:
134+ TVM_DLL PoolInfo (String pool_name, Integer size_hint_bytes = kUnrestrictedPoolSizeHint ,
136135 Integer clock_frequency_hz = kUnknownClockFrequency ,
137136 Integer read_bandwidth_bytes_per_cycle = kUnknownReadBandwidth ,
138137 Integer write_bandwidth_bytes_per_cycle = kUnknownWriteBandwidth ,
139138 Integer read_latency_cycles = 0 , Integer write_latency_cycles = 0 ,
140139 Map<Target, Integer> target_burst_bytes = {}, Bool is_internal = Bool(false ));
141- TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS (PoolInfo, ObjectRef, PoolInfoNode);
140+
141+ public:
142+ TVM_DEFINE_OBJECT_REF_METHODS (PoolInfo, ObjectRef, PoolInfoNode);
143+ };
144+
145+ /* !
146+ * \brief Describes a pool of memory properties
147+ */
148+ struct PoolInfoPropertiesNode : public Object {
149+ /* ! \brief The expected size hint to be used by the allocator.
150+ * The size_hint_bytes is set to kUnrestrictedPoolSizeHint
151+ * to indicate the pool is not size restricted.
152+ */
153+ Integer size_hint_bytes = kUnrestrictedPoolSizeHint ;
154+ /* ! \brief The clock frequency of the memory in Hz */
155+ Integer clock_frequency_hz = kUnknownClockFrequency ;
156+ /* ! \brief The read bandwidth in bytes/cycle */
157+ Integer read_bandwidth_bytes_per_cycle = kUnknownReadBandwidth ;
158+ /* ! \brief The write bandwidth in bytes/cycle */
159+ Integer write_bandwidth_bytes_per_cycle = kUnknownWriteBandwidth ;
160+ /* ! \brief The read latency in cycles */
161+ Integer read_latency_cycles = 0 ;
162+ /* ! \brief The write latency in cycles */
163+ Integer write_latency_cycles = 0 ;
164+ /* ! \brief The burst length in bytes for each Target */
165+ Map<Target, Integer> target_burst_bytes{};
166+ /* ! \brief Whether pool is internally generated.
167+ * The internal pools will be generated as part of
168+ * the entry point code generation of the executor
169+ */
170+ bool is_internal = false ;
171+
172+ void VisitAttrs (tvm::AttrVisitor* v) {
173+ v->Visit (" size_hint_bytes" , &size_hint_bytes);
174+ v->Visit (" clock_frequency_hz" , &clock_frequency_hz);
175+ v->Visit (" read_bandwidth_bytes_per_cycle" , &read_bandwidth_bytes_per_cycle);
176+ v->Visit (" write_bandwidth_bytes_per_cycle" , &write_bandwidth_bytes_per_cycle);
177+ v->Visit (" read_latency_cycles" , &read_latency_cycles);
178+ v->Visit (" write_latency_cycles" , &write_latency_cycles);
179+ v->Visit (" target_burst_bytes" , &target_burst_bytes);
180+ v->Visit (" is_internal" , &is_internal);
181+ }
182+
183+ bool SEqualReduce (const PoolInfoPropertiesNode* other, SEqualReducer equal) const {
184+ return equal (size_hint_bytes, other->size_hint_bytes ) &&
185+ equal (clock_frequency_hz, other->clock_frequency_hz ) &&
186+ equal (read_bandwidth_bytes_per_cycle, other->read_bandwidth_bytes_per_cycle ) &&
187+ equal (write_bandwidth_bytes_per_cycle, other->write_bandwidth_bytes_per_cycle ) &&
188+ equal (read_latency_cycles, other->read_latency_cycles ) &&
189+ equal (write_latency_cycles, other->write_latency_cycles ) &&
190+ equal (target_burst_bytes, other->target_burst_bytes ) &&
191+ equal (is_internal, other->is_internal );
192+ }
193+
194+ void SHashReduce (SHashReducer hash_reduce) const {
195+ hash_reduce (size_hint_bytes);
196+ hash_reduce (clock_frequency_hz);
197+ hash_reduce (read_bandwidth_bytes_per_cycle);
198+ hash_reduce (write_bandwidth_bytes_per_cycle);
199+ hash_reduce (read_latency_cycles);
200+ hash_reduce (write_latency_cycles);
201+ hash_reduce (target_burst_bytes);
202+ hash_reduce (is_internal);
203+ }
204+
205+ static constexpr const char * _type_key = " ir.PoolInfoProperties" ;
206+ TVM_DECLARE_FINAL_OBJECT_INFO (PoolInfoPropertiesNode, Object);
142207};
143208
209+ class PoolInfoProperties : public ObjectRef {
210+ public:
211+ TVM_DLL PoolInfoProperties (Integer size_hint_bytes,
212+ Integer clock_frequency_hz = kUnknownClockFrequency ,
213+ Integer read_bandwidth_bytes_per_cycle = kUnknownReadBandwidth ,
214+ Integer write_bandwidth_bytes_per_cycle = kUnknownWriteBandwidth ,
215+ Integer read_latency_cycles = 0 , Integer write_latency_cycles = 0 ,
216+ Map<Target, Integer> target_burst_bytes = {},
217+ Bool is_internal = Bool(false ));
218+ TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS (PoolInfoProperties, ObjectRef, PoolInfoPropertiesNode);
219+ };
220+
221+ /* \brief Represents RW memory area */
222+ struct WorkspacePoolInfoNode : public PoolInfoNode {
223+ static constexpr const char * _type_key = " ir.WorkspacePoolInfo" ;
224+ TVM_DECLARE_FINAL_OBJECT_INFO (WorkspacePoolInfoNode, PoolInfoNode);
225+ };
226+
227+ class WorkspacePoolInfo : public PoolInfo {
228+ public:
229+ TVM_DLL WorkspacePoolInfo (
230+ String pool_name, Array<Target> targets,
231+ PoolInfoProperties properties = PoolInfoProperties(kUnrestrictedPoolSizeHint ));
232+ TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS (WorkspacePoolInfo, PoolInfo, WorkspacePoolInfoNode);
233+ };
234+
235+ /*
236+ * \brief The ConstantInfoNode contains numeric literal in RO pool
237+ * Used to initialise RO memory in ConstantPoolInfo
238+ */
239+ struct ConstantInfoNode : public Object {
240+ String name_hint;
241+ Integer byte_offset;
242+ runtime::NDArray data;
243+
244+ void VisitAttrs (tvm::AttrVisitor* v) {
245+ v->Visit (" name_hint" , &name_hint);
246+ v->Visit (" byte_offset" , &byte_offset);
247+ v->Visit (" data" , &data);
248+ }
249+
250+ bool SEqualReduce (const ConstantInfoNode* other, SEqualReducer equal) const {
251+ return equal (name_hint, other->name_hint ) && equal (byte_offset, other->byte_offset ) &&
252+ equal (data, other->data );
253+ }
254+
255+ void SHashReduce (SHashReducer hash_reduce) const {
256+ hash_reduce (name_hint);
257+ hash_reduce (byte_offset);
258+ hash_reduce (data);
259+ }
260+
261+ static constexpr const char * _type_key = " ir.ConstantInfo" ;
262+ static constexpr bool _type_has_method_sequal_reduce = true ;
263+ static constexpr bool _type_has_method_shash_reduce = true ;
264+ TVM_DECLARE_FINAL_OBJECT_INFO (ConstantInfoNode, Object);
265+ };
266+
267+ class ConstantInfo : public ObjectRef {
268+ public:
269+ TVM_DLL ConstantInfo (const struct ::TVMConstantInfo* data);
270+ ConstantInfo (String name, Integer byte_offset, runtime::NDArray data);
271+ TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS (ConstantInfo, ObjectRef, ConstantInfoNode);
272+ };
273+
274+ /* \brief ConstantPoolInfoNode represents an RO memory area initialized with
275+ * data from constant_info_array */
276+ struct ConstantPoolInfoNode : public PoolInfoNode {
277+ Array<ConstantInfo> constant_info_array;
278+ static constexpr const char * _type_key = " ir.ConstantPoolInfo" ;
279+ TVM_DECLARE_FINAL_OBJECT_INFO (ConstantPoolInfoNode, PoolInfoNode);
280+ };
281+
282+ class ConstantPoolInfo : public PoolInfo {
283+ public:
284+ TVM_DLL ConstantPoolInfo (
285+ String pool_name, Array<Target> targets, Array<ConstantInfo> constant_info_array,
286+ PoolInfoProperties properties = PoolInfoProperties(kUnrestrictedPoolSizeHint ));
287+ TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS (ConstantPoolInfo, PoolInfo, ConstantPoolInfoNode);
288+ };
289+
290+ /* \brief A container for WorkspacePoolInfo objects */
144291struct WorkspaceMemoryPoolsNode : public Object {
145292 Array<PoolInfo> pools;
146293
@@ -162,6 +309,28 @@ class WorkspaceMemoryPools : public ObjectRef {
162309 TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS (WorkspaceMemoryPools, ObjectRef, WorkspaceMemoryPoolsNode);
163310};
164311
312+ /* \brief A container for ConstantPoolInfo objects */
313+ struct ConstantMemoryPoolsNode : public Object {
314+ Array<ConstantPoolInfo> pools;
315+
316+ void VisitAttrs (tvm::AttrVisitor* v) { v->Visit (" pools" , &pools); }
317+
318+ bool SEqualReduce (const ConstantMemoryPoolsNode* other, SEqualReducer equal) const {
319+ return equal (pools, other->pools );
320+ }
321+
322+ void SHashReduce (SHashReducer hash_reduce) const { hash_reduce (pools); }
323+
324+ static constexpr const char * _type_key = " ir.ConstantMemoryPools" ;
325+ TVM_DECLARE_FINAL_OBJECT_INFO (ConstantMemoryPoolsNode, Object);
326+ };
327+
328+ class ConstantMemoryPools : public ObjectRef {
329+ public:
330+ TVM_DLL ConstantMemoryPools (Array<ConstantPoolInfo> pools);
331+ TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS (ConstantMemoryPools, ObjectRef, ConstantMemoryPoolsNode);
332+ };
333+
165334} // namespace tvm
166335
167336#endif // TVM_IR_MEMORY_POOLS_H_
0 commit comments