From 67aa6c04c6fd6a46280e7226795801bc388ea169 Mon Sep 17 00:00:00 2001 From: Regan Stehle Date: Thu, 16 Jul 2026 08:47:44 -0700 Subject: [PATCH] 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 --- runtime/executor/method.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/executor/method.cpp b/runtime/executor/method.cpp index 8eb48480463..2a9859f8d47 100644 --- a/runtime/executor/method.cpp +++ b/runtime/executor/method.cpp @@ -761,7 +761,7 @@ Error Method::resolve_operator( // However, it does not have to be provided, so if it // is not provided (or an empty one is provided), we // fall back to the method allocator. - if (allocator == nullptr || allocator->size() == 0) { + if (allocator == nullptr || allocator->size() == 0 || allocator->size() < (sizeof(TensorMeta) * n_args) + (sizeof(executorch::aten::DimOrderType) * kTensorDimensionLimit * n_args)) { allocator = memory_manager_->method_allocator(); } TensorMeta* meta = allocator->allocateList(n_args); @@ -769,7 +769,7 @@ Error Method::resolve_operator( if (allocator == memory_manager_->temp_allocator()) { memory_manager_->temp_allocator()->reset(); } - return Error::MemoryAllocationFailed; + return Error::MemoryAllocationFailed; } size_t count = 0;