From 5cb625abcaf55c2145021cd098d41b45bb1ca184 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Mon, 17 Mar 2025 16:03:04 -0700 Subject: [PATCH 1/3] Update [ghstack-poisoned] --- .../executor_runner/executor_runner.cpp | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/portable/executor_runner/executor_runner.cpp b/examples/portable/executor_runner/executor_runner.cpp index 1e0241958b9..ad8c159a7be 100644 --- a/examples/portable/executor_runner/executor_runner.cpp +++ b/examples/portable/executor_runner/executor_runner.cpp @@ -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(Info, "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(Info, "Inputs prepared."); + Error status = method->execute(); ET_CHECK_MSG( status == Error::Ok, From ac789abf1d728bbc39690642a51904aa169b1269 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Mon, 17 Mar 2025 16:17:13 -0700 Subject: [PATCH 2/3] Update [ghstack-poisoned] --- examples/portable/executor_runner/executor_runner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/portable/executor_runner/executor_runner.cpp b/examples/portable/executor_runner/executor_runner.cpp index ad8c159a7be..08907d333c4 100644 --- a/examples/portable/executor_runner/executor_runner.cpp +++ b/examples/portable/executor_runner/executor_runner.cpp @@ -251,7 +251,7 @@ int main(int argc, char** argv) { // Run the model. for (uint32_t i = 0; i < FLAGS_num_executions; i++) { - ET_LOG(Info, "Preparing inputs."); + 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()`. @@ -265,7 +265,7 @@ int main(int argc, char** argv) { inputs.ok(), "Could not prepare inputs: 0x%" PRIx32, (uint32_t)inputs.error()); - ET_LOG(Info, "Inputs prepared."); + ET_LOG(Debug, "Inputs prepared."); Error status = method->execute(); ET_CHECK_MSG( From a9a9a1e2e096246d193fe684ab05664b4a5713b0 Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Mon, 17 Mar 2025 16:17:13 -0700 Subject: [PATCH 3/3] Update [ghstack-poisoned] --- .../portable/executor_runner/executor_runner.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/portable/executor_runner/executor_runner.cpp b/examples/portable/executor_runner/executor_runner.cpp index 08907d333c4..7c75c39f0a9 100644 --- a/examples/portable/executor_runner/executor_runner.cpp +++ b/examples/portable/executor_runner/executor_runner.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #ifdef ET_EVENT_TRACER_ENABLED #include @@ -249,6 +250,7 @@ int main(int argc, char** argv) { (uint32_t)method.error()); ET_LOG(Info, "Method loaded."); + et_timestamp_t time_spent_executing = 0; // Run the model. for (uint32_t i = 0; i < FLAGS_num_executions; i++) { ET_LOG(Debug, "Preparing inputs."); @@ -267,17 +269,24 @@ int main(int argc, char** argv) { (uint32_t)inputs.error()); ET_LOG(Debug, "Inputs prepared."); + const et_timestamp_t before_execute = et_pal_current_ticks(); Error status = method->execute(); + const et_timestamp_t after_execute = et_pal_current_ticks(); + time_spent_executing += after_execute - before_execute; ET_CHECK_MSG( status == Error::Ok, "Execution of method %s failed with status 0x%" PRIx32, method_name, (uint32_t)status); } + const auto tick_ratio = et_pal_ticks_to_ns_multiplier(); + constexpr auto NANOSECONDS_PER_MILLISECOND = 1000000; ET_LOG( Info, - "Model executed successfully %" PRIu32 " time(s).", - FLAGS_num_executions); + "Model executed successfully %" PRIu32 " time(s) in %f ms.", + FLAGS_num_executions, + static_cast(time_spent_executing) * tick_ratio.numerator / + tick_ratio.denominator / NANOSECONDS_PER_MILLISECOND); // Print the outputs. std::vector outputs(method->outputs_size());