Skip to content

Commit e6abe7a

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Reset inputs after each execution. (#13229)
Summary: . Reviewed By: JacobSzwejbka Differential Revision: D79850580
1 parent 2105cf8 commit e6abe7a

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

runtime/executor/method.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,10 @@ Error Method::reset_execution() {
14511451
InvalidState,
14521452
"Cannot reset until EndOfMethod has been reached.");
14531453
step_state_ = StepState{0, 0};
1454+
const auto n_input = inputs_size();
1455+
for (size_t i = 0; i < n_input; ++i) {
1456+
input_set_[i] = false;
1457+
}
14541458
return Error::Ok;
14551459
}
14561460

runtime/executor/test/kernel_integration_test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ TEST_F(KernelIntegrationTest, KernelHookIsCalled) {
294294
EXPECT_EQ(err, Error::Ok);
295295
EXPECT_EQ(control_->call_count, 1);
296296

297+
// Set up inputs again.
298+
auto inputs_cleanup =
299+
executorch::extension::prepare_input_tensors(*method_);
300+
ASSERT_EQ(inputs_cleanup.error(), Error::Ok);
301+
auto input_err =
302+
method_->set_input(executorch::runtime::EValue(1.0), 2);
303+
ASSERT_EQ(input_err, Error::Ok);
304+
297305
// Calling it again bumps the count.
298306
err = method_->execute();
299307
EXPECT_EQ(err, Error::Ok);
@@ -336,6 +344,14 @@ TEST_F(KernelIntegrationTest, DefaultPlatformMemoryAllocator) {
336344
EXPECT_EQ(control_->call_count, 1);
337345
EXPECT_EQ(control_->total_allocated_size, 4);
338346

347+
// Set up inputs again.
348+
auto inputs_cleanup =
349+
executorch::extension::prepare_input_tensors(*method_);
350+
ASSERT_EQ(inputs_cleanup.error(), Error::Ok);
351+
auto input_err =
352+
method_->set_input(executorch::runtime::EValue(1.0), 2);
353+
ASSERT_EQ(input_err, Error::Ok);
354+
339355
control_->temp_memory_size = 8;
340356
// This is not a simulation. This actually allocates memory, using the
341357
// default platform memory allocator.
@@ -371,6 +387,14 @@ TEST_F(KernelTempMemoryAllocatorIntegrationTest, UsingTempMemoryAllocator) {
371387
EXPECT_EQ(temp_allocator_->number_of_resets, 1);
372388
EXPECT_EQ(temp_allocator_->currently_allocated_size, 0);
373389

390+
// Set up inputs again.
391+
auto inputs_cleanup =
392+
executorch::extension::prepare_input_tensors(*method_);
393+
ASSERT_EQ(inputs_cleanup.error(), Error::Ok);
394+
auto input_err =
395+
method_->set_input(executorch::runtime::EValue(1.0), 2);
396+
ASSERT_EQ(input_err, Error::Ok);
397+
374398
control_->temp_memory_size = 8;
375399
err = method_->execute();
376400
EXPECT_EQ(err, Error::Ok);

runtime/executor/test/method_test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ TEST_F(MethodTest, MoveTest) {
114114
Error err = method->execute();
115115
ASSERT_EQ(err, Error::Ok);
116116

117+
// Set dummy inputs again.
118+
auto input_cleanup2 = prepare_input_tensors(*method);
119+
ASSERT_EQ(input_cleanup2.error(), Error::Ok);
120+
input_err =
121+
method->set_input(executorch::runtime::EValue(1.0), 2);
122+
ASSERT_EQ(input_err, Error::Ok);
123+
117124
// Move into a new Method.
118125
Method new_method(std::move(method.get()));
119126

0 commit comments

Comments
 (0)