Skip to content

Commit c16eab9

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

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ 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 = executorch::extension::prepare_input_tensors(*method_);
299+
ASSERT_EQ(inputs_cleanup.error(), Error::Ok);
300+
auto input_err = method_->set_input(executorch::runtime::EValue(1.0), 2);
301+
ASSERT_EQ(input_err, Error::Ok);
302+
297303
// Calling it again bumps the count.
298304
err = method_->execute();
299305
EXPECT_EQ(err, Error::Ok);
@@ -336,6 +342,12 @@ TEST_F(KernelIntegrationTest, DefaultPlatformMemoryAllocator) {
336342
EXPECT_EQ(control_->call_count, 1);
337343
EXPECT_EQ(control_->total_allocated_size, 4);
338344

345+
// Set up inputs again.
346+
auto inputs_cleanup = executorch::extension::prepare_input_tensors(*method_);
347+
ASSERT_EQ(inputs_cleanup.error(), Error::Ok);
348+
auto input_err = method_->set_input(executorch::runtime::EValue(1.0), 2);
349+
ASSERT_EQ(input_err, Error::Ok);
350+
339351
control_->temp_memory_size = 8;
340352
// This is not a simulation. This actually allocates memory, using the
341353
// default platform memory allocator.
@@ -371,6 +383,12 @@ TEST_F(KernelTempMemoryAllocatorIntegrationTest, UsingTempMemoryAllocator) {
371383
EXPECT_EQ(temp_allocator_->number_of_resets, 1);
372384
EXPECT_EQ(temp_allocator_->currently_allocated_size, 0);
373385

386+
// Set up inputs again.
387+
auto inputs_cleanup = executorch::extension::prepare_input_tensors(*method_);
388+
ASSERT_EQ(inputs_cleanup.error(), Error::Ok);
389+
auto input_err = method_->set_input(executorch::runtime::EValue(1.0), 2);
390+
ASSERT_EQ(input_err, Error::Ok);
391+
374392
control_->temp_memory_size = 8;
375393
err = method_->execute();
376394
EXPECT_EQ(err, Error::Ok);

runtime/executor/test/method_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ 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 = method->set_input(executorch::runtime::EValue(1.0), 2);
121+
ASSERT_EQ(input_err, Error::Ok);
122+
117123
// Move into a new Method.
118124
Method new_method(std::move(method.get()));
119125

0 commit comments

Comments
 (0)