Skip to content

Commit 6002e09

Browse files
cmt0facebook-github-bot
authored andcommitted
Reset temp allocator before instruction
Summary: If the temp allocator is defined, then it now (after some more recent changes) has objects allocated after 'init'. It doesn't seem to be cleared before the first instruction. Our temp allocator was very precisely bound to the size of a resource being allocated in our delegate and the leftover state in the temp allocator caused a failure to allocate. We'll just clear this allocator wherever it's used. Reviewed By: abhiag-git, JacobSzwejbka Differential Revision: D80191057
1 parent 8e208ad commit 6002e09

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

runtime/executor/method.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,12 @@ Error Method::resolve_operator(
754754
return op_function.error();
755755
}
756756
kernels[kernel_index] = op_function.get();
757+
758+
// If we used the temp allocator here, reset it.
759+
if (allocator == memory_manager_->temp_allocator()) {
760+
memory_manager_->temp_allocator()->reset();
761+
}
762+
757763
return Error::Ok;
758764
}
759765

@@ -1547,6 +1553,9 @@ Error Method::execute() {
15471553
i);
15481554
}
15491555
ET_LOG(Debug, "Executing method: %s.", method_meta().name());
1556+
if (temp_allocator_ != nullptr) {
1557+
temp_allocator_->reset();
1558+
}
15501559

15511560
// Chains are executed sequentially today, but future async designs may
15521561
// branch and run many in parallel or out of order.

runtime/executor/test/kernel_integration_test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,9 @@ TEST_F(KernelTempMemoryAllocatorIntegrationTest, UsingTempMemoryAllocator) {
367367
EXPECT_EQ(control_->total_allocated_size, 4);
368368
EXPECT_EQ(temp_allocator_->number_of_allocations, 1);
369369
EXPECT_EQ(temp_allocator_->total_allocated_size, 4);
370-
// The temp allocator should have been reset after the execution.
371-
EXPECT_EQ(temp_allocator_->number_of_resets, 1);
370+
// The temp allocator should have been reset after the execution and before
371+
// method execution.
372+
EXPECT_EQ(temp_allocator_->number_of_resets, 2);
372373
EXPECT_EQ(temp_allocator_->currently_allocated_size, 0);
373374

374375
control_->temp_memory_size = 8;
@@ -379,6 +380,6 @@ TEST_F(KernelTempMemoryAllocatorIntegrationTest, UsingTempMemoryAllocator) {
379380
EXPECT_EQ(temp_allocator_->number_of_allocations, 2);
380381
EXPECT_EQ(temp_allocator_->total_allocated_size, 12);
381382
// The temp allocator should have been reset after the execution.
382-
EXPECT_EQ(temp_allocator_->number_of_resets, 2);
383+
EXPECT_EQ(temp_allocator_->number_of_resets, 4);
383384
EXPECT_EQ(temp_allocator_->currently_allocated_size, 0);
384385
}

0 commit comments

Comments
 (0)