Skip to content

re-initialize inputs on each execution in executor_runner #9340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions examples/portable/executor_runner/executor_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,24 @@ int main(int argc, char** argv) {
(uint32_t)method.error());
ET_LOG(Info, "Method loaded.");

// Allocate input tensors and set all of their elements to 1. The `inputs`
// variable owns the allocated memory and must live past the last call to
// `execute()`.
auto inputs = executorch::extension::prepare_input_tensors(*method);
ET_CHECK_MSG(
inputs.ok(),
"Could not prepare inputs: 0x%" PRIx32,
(uint32_t)inputs.error());
ET_LOG(Info, "Inputs prepared.");

// Run the model.
for (uint32_t i = 0; i < FLAGS_num_executions; i++) {
ET_LOG(Debug, "Preparing inputs.");
// Allocate input tensors and set all of their elements to 1. The `inputs`
// variable owns the allocated memory and must live past the last call to
// `execute()`.
//
// NOTE: we have to re-prepare input tensors on every execution
// because inputs whose space gets reused by memory planning (if
// any such inputs exist) will not be preserved for the next
// execution.
auto inputs = executorch::extension::prepare_input_tensors(*method);
ET_CHECK_MSG(
inputs.ok(),
"Could not prepare inputs: 0x%" PRIx32,
(uint32_t)inputs.error());
ET_LOG(Debug, "Inputs prepared.");

Error status = method->execute();
ET_CHECK_MSG(
status == Error::Ok,
Expand Down
Loading