@@ -236,6 +236,14 @@ int main(int argc, char** argv) {
236
236
}
237
237
ET_LOG (Info, " Running method %s" , method_name);
238
238
239
+ // MethodMeta describes the memory requirements of the method.
240
+ Result<MethodMeta> method_meta = program->method_meta (method_name);
241
+ ET_CHECK_MSG (
242
+ method_meta.ok (),
243
+ " Failed to get method_meta for %s: 0x%x" ,
244
+ method_name,
245
+ (unsigned int )method_meta.error ());
246
+
239
247
//
240
248
// The runtime does not use malloc/new; it allocates all memory using the
241
249
// MemoryManger provided by the client. Clients are responsible for allocating
@@ -265,35 +273,13 @@ int main(int argc, char** argv) {
265
273
// have more than one for, e.g., slow/large DRAM and fast/small SRAM.
266
274
std::vector<std::unique_ptr<uint8_t []>> non_const_buffers;
267
275
std::vector<MemoryAllocator> non_const_allocators;
268
- size_t num_non_const_buffers = 0 ;
269
- {
270
- auto result = program->num_non_const_buffers (method_name);
271
- ET_CHECK_MSG (
272
- result.ok (),
273
- " Failed to get number of non-const buffers for method %s: 0x%x" ,
274
- method_name,
275
- (unsigned int )result.error ());
276
- num_non_const_buffers = *result;
277
- }
278
- // Note that this loop starts at ID 1, because ID 0 is reserved. But, the
279
- // HierarchicalAllocator indices are zero-based, so it's later adjusted by -1.
280
- // TODO(T142455629): Make HierarchicalAllocator ID-based to avoid this
281
- // memory_id-1.
282
- for (size_t id = 1 ; id < num_non_const_buffers; ++id) {
283
- auto buffer_size = program->get_non_const_buffer_size (id, method_name);
284
- ET_CHECK_MSG (
285
- buffer_size.ok (),
286
- " Failed to get size of non-const buffer %zu for method %s: 0x%x" ,
287
- id,
288
- method_name,
289
- (unsigned int )buffer_size.error ());
290
- ET_LOG (
291
- Info, " Setting up non-const buffer %zu, size %zu." , id, *buffer_size);
292
- non_const_buffers.push_back (std::make_unique<uint8_t []>(*buffer_size));
293
- // Since the list of allocators began empty, buffer ID N will live at index
294
- // N-1.
276
+ size_t num_non_const_buffers = method_meta->num_non_const_buffers ();
277
+ for (size_t id = 0 ; id < num_non_const_buffers; ++id) {
278
+ size_t buffer_size = method_meta->non_const_buffer_size (id).get ();
279
+ ET_LOG (Info, " Setting up non-const buffer %zu, size %zu." , id, buffer_size);
280
+ non_const_buffers.push_back (std::make_unique<uint8_t []>(buffer_size));
295
281
non_const_allocators.push_back (
296
- MemoryAllocator (* buffer_size, non_const_buffers.back ().get ()));
282
+ MemoryAllocator (buffer_size, non_const_buffers.back ().get ()));
297
283
non_const_allocators.back ().enable_profiling (" non_const_allocators" );
298
284
}
299
285
HierarchicalAllocator non_const_allocator (
0 commit comments