Skip to content

Commit 67aa6c0

Browse files
rstehlefacebook-github-bot
authored andcommitted
Resolve Operator fallback to method allocator if temp alloc fails (#20981)
Summary: Currently, the resolve_operator step during method_init will fall back to method allocator if temp allocator is zero or not present. This change adds logic to fallback to method allocator if temp allocator is present, but insufficient in size for the tensor meta. Reviewed By: Andrew-github-user, rascani Differential Revision: D109855815
1 parent 4f95191 commit 67aa6c0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

runtime/executor/method.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,15 +761,15 @@ Error Method::resolve_operator(
761761
// However, it does not have to be provided, so if it
762762
// is not provided (or an empty one is provided), we
763763
// fall back to the method allocator.
764-
if (allocator == nullptr || allocator->size() == 0) {
764+
if (allocator == nullptr || allocator->size() == 0 || allocator->size() < (sizeof(TensorMeta) * n_args) + (sizeof(executorch::aten::DimOrderType) * kTensorDimensionLimit * n_args)) {
765765
allocator = memory_manager_->method_allocator();
766766
}
767767
TensorMeta* meta = allocator->allocateList<TensorMeta>(n_args);
768768
if (meta == nullptr) {
769769
if (allocator == memory_manager_->temp_allocator()) {
770770
memory_manager_->temp_allocator()->reset();
771771
}
772-
return Error::MemoryAllocationFailed;
772+
return Error::MemoryAllocationFailed;
773773
}
774774

775775
size_t count = 0;

0 commit comments

Comments
 (0)