@@ -249,18 +249,24 @@ int main(int argc, char** argv) {
249
249
(uint32_t )method.error ());
250
250
ET_LOG (Info, " Method loaded." );
251
251
252
- // Allocate input tensors and set all of their elements to 1. The `inputs`
253
- // variable owns the allocated memory and must live past the last call to
254
- // `execute()`.
255
- auto inputs = executorch::extension::prepare_input_tensors (*method);
256
- ET_CHECK_MSG (
257
- inputs.ok (),
258
- " Could not prepare inputs: 0x%" PRIx32,
259
- (uint32_t )inputs.error ());
260
- ET_LOG (Info, " Inputs prepared." );
261
-
262
252
// Run the model.
263
253
for (uint32_t i = 0 ; i < FLAGS_num_executions; i++) {
254
+ ET_LOG (Info, " Preparing inputs." );
255
+ // Allocate input tensors and set all of their elements to 1. The `inputs`
256
+ // variable owns the allocated memory and must live past the last call to
257
+ // `execute()`.
258
+ //
259
+ // NOTE: we have to re-prepare input tensors on every execution
260
+ // because inputs whose space gets reused by memory planning (if
261
+ // any such inputs exist) will not be preserved for the next
262
+ // execution.
263
+ auto inputs = executorch::extension::prepare_input_tensors (*method);
264
+ ET_CHECK_MSG (
265
+ inputs.ok (),
266
+ " Could not prepare inputs: 0x%" PRIx32,
267
+ (uint32_t )inputs.error ());
268
+ ET_LOG (Info, " Inputs prepared." );
269
+
264
270
Error status = method->execute ();
265
271
ET_CHECK_MSG (
266
272
status == Error::Ok,
0 commit comments