@@ -114,33 +114,27 @@ int main(int argc, char** argv) {
114
114
MemoryAllocator (kRuntimeMemorySize , runtime_pool)};
115
115
runtime_allocator.enable_profiling (" runtime allocator" );
116
116
117
- // The non-const allocator is used to provide the memory-planned buffers that
118
- // back mutable tensors. Since it was planned ahead of time, the Program knows
119
- // how big each of the allocators needs to be .
117
+ // The non-const buffers will back the mutable tensors used by the method. The
118
+ // sizes of these buffers were determined ahead of time during the
119
+ // memory-planning pasees .
120
120
//
121
- // These buffers correspond to different hardware memory banks. Most mobile
122
- // environments will only have a single buffer. Some embedded environments may
123
- // have more than one for, e.g., slow/large DRAM and fast/small SRAM.
121
+ // Each buffer typically corresponds to a different hardware memory bank. Most
122
+ // mobile environments will only have a single buffer. Some embedded
123
+ // environments may have more than one for, e.g., slow/large DRAM and
124
+ // fast/small SRAM, or for memory associated with particular cores.
124
125
std::vector<std::unique_ptr<uint8_t []>> non_const_buffers;
125
- std::vector<MemoryAllocator> non_const_allocators ;
126
+ std::vector<Span< uint8_t >> non_const_spans ;
126
127
size_t num_non_const_buffers = method_meta->num_non_const_buffers ();
127
128
for (size_t id = 0 ; id < num_non_const_buffers; ++id) {
128
- auto buffer_size = method_meta->non_const_buffer_size (id);
129
- ET_CHECK_MSG (
130
- buffer_size.ok (),
131
- " Failed to get size of non-const buffer %zu for method %s: 0x%x" ,
132
- id,
133
- method_name,
134
- (unsigned int )buffer_size.error ());
135
- ET_LOG (
136
- Info, " Setting up non-const buffer %zu, size %zu." , id, *buffer_size);
137
- non_const_buffers.push_back (std::make_unique<uint8_t []>(*buffer_size));
138
- non_const_allocators.push_back (
139
- MemoryAllocator (*buffer_size, non_const_buffers.back ().get ()));
140
- non_const_allocators.back ().enable_profiling (" non_const_allocators" );
129
+ // .get() will always succeed because id < num_non_const_buffers.
130
+ size_t buffer_size =
131
+ static_cast <size_t >(method_meta->non_const_buffer_size (id).get ());
132
+ ET_LOG (Info, " Setting up non-const buffer %zu, size %zu." , id, buffer_size);
133
+ non_const_buffers.push_back (std::make_unique<uint8_t []>(buffer_size));
134
+ non_const_spans.push_back ({non_const_buffers.back ().get (), buffer_size});
141
135
}
142
136
HierarchicalAllocator non_const_allocator (
143
- non_const_allocators. size (), non_const_allocators. data () );
137
+ {non_const_spans. data (), non_const_spans. size ()} );
144
138
145
139
// The constant allocator is not currently used. Please initialize with a
146
140
// zero-sized allocator.
0 commit comments