pytorch / pytorch/executorch

I want to understand the allocations made on STM32s by Executorch

Open
#9,491 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module: runtime triaged
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

📚 The doc issue

@tarun292, @kimishpatel, yesterday's issue was closed, so I opened a new one.
So here is the continuing of the https://github.com/pytorch/executorch/issues/9447

There are two sections in the exeutor_runner.cpp that make heap allocations:

  1. m_method_allocator_pool = (uint8_t*)malloc(m_allocator_pool_size);
  2. planned_buffers.push_back(std::make_unique<uint8_t[]>(buffer_size));

The size for the second one is precise (33168). I get it from the execution plan.

executorch_program: exir.ExecutorchProgramManager = edge_program.to_executorch(
    ExecutorchBackendConfig(
        passes=[],  # User-defined passes
    )
)
print(executorch_program.executorch_program.execution_plan[0].non_const_buffer_sizes)

The first one is unclear yet. Since the CNN execution on the STM32 works with a m_allocator_pool_size of 8192 but not with a size of 4096, allocating 33168bytes is pointless since I want to save as much SRAM as possible.
I assume the method size is between 4096 and 8192, but where do I get the exact size? Since the error I get when I set `m_allocator_pool_size to 4096 is:

E executorch:memory_allocator.h:87] Memory allocation failed: 48B requested (adjusted for alignment), 44B available
I executorch:ModelExecutor.cpp:283] Loading of method forward failed with status 0x21

It happens in this code section:

Result<torch::executor::Method> method = program->load_method(method_name, &memory_manager);
if (!method.ok()) {
	ET_LOG(
		Info,
		"Loading of method %s failed with status 0x%" PRIx32,
		method_name,
		method.error());
}

Thank you for being so helpful in advance!
Christoph

cc @larryliu0820 @JacobSzwejbka

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read executor_runner.cpp, memory_allocator.h, and ModelExecutor.cpp, starting with the two allocation sites and the reported failure during load_method. Use the execution-plan output and the 4096/8192 STM32 results as evidence. Done means documenting where m_allocator_pool_size comes from and how to determine the required size for this model.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
embedded-iot, machine-learning
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.