Skip to content

Commit a404e28

Browse files
dbortfacebook-github-bot
authored andcommitted
Make sdk/executor_runner use MethodMeta interface and adjust non-const indices (#317)
Summary: Pull Request resolved: #317 The new MethodMeta interface avoids the need to adjust non-const buffer indices by 1. Reviewed By: JacobSzwejbka Differential Revision: D49208017 fbshipit-source-id: 27e630023df82069792a9297769ce69f5c2be1bd
1 parent 04d5c24 commit a404e28

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

sdk/runners/executor_runner.cpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ int main(int argc, char** argv) {
236236
}
237237
ET_LOG(Info, "Running method %s", method_name);
238238

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+
239247
//
240248
// The runtime does not use malloc/new; it allocates all memory using the
241249
// MemoryManger provided by the client. Clients are responsible for allocating
@@ -265,35 +273,13 @@ int main(int argc, char** argv) {
265273
// have more than one for, e.g., slow/large DRAM and fast/small SRAM.
266274
std::vector<std::unique_ptr<uint8_t[]>> non_const_buffers;
267275
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));
295281
non_const_allocators.push_back(
296-
MemoryAllocator(*buffer_size, non_const_buffers.back().get()));
282+
MemoryAllocator(buffer_size, non_const_buffers.back().get()));
297283
non_const_allocators.back().enable_profiling("non_const_allocators");
298284
}
299285
HierarchicalAllocator non_const_allocator(

0 commit comments

Comments
 (0)