Skip to content

Commit 07a7687

Browse files
JakeStevensfacebook-github-bot
authored andcommitted
Use temp allocator for kernel registry (pytorch#13012)
Summary: Pull Request resolved: pytorch#13012 When indexing to the registry to get the op, memory is allocated from the method allocator to instantiate some TensorMeta and included objects. This memory is only used for that purpose and is not needed for the entire lifetime of the Method. Thus, we can instead use temp allocator which can later be reset and free up memory as needed. Differential Revision: D79285675
1 parent d4c78ab commit 07a7687

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

runtime/executor/method.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ Error Method::resolve_operator(
670670
size_t kernel_index,
671671
InstructionArgs args,
672672
size_t n_args) {
673-
// TODO(T153505381, T153506819) Investigate optimizing this function for both
673+
// TODO(T153506819) Investigate optimizing this function for both
674674
// space and time.
675675

676676
// resolve name
@@ -691,8 +691,11 @@ Error Method::resolve_operator(
691691
}
692692

693693
// resolve tensor meta
694-
auto method_allocator = memory_manager_->method_allocator();
695-
TensorMeta* meta = method_allocator->allocateList<TensorMeta>(n_args);
694+
auto allocator = memory_manager_->temp_allocator();
695+
if (allocator->size() == 0) {
696+
allocator = memory_manager_->method_allocator();
697+
}
698+
TensorMeta* meta = allocator->allocateList<TensorMeta>(n_args);
696699
if (meta == nullptr) {
697700
return Error::MemoryAllocationFailed;
698701
}
@@ -705,8 +708,7 @@ Error Method::resolve_operator(
705708
auto tensor = eval->toTensor();
706709
meta[count].dtype_ = tensor.scalar_type();
707710
executorch::aten::DimOrderType* dim_order_ptr =
708-
method_allocator->allocateList<executorch::aten::DimOrderType>(
709-
tensor.dim());
711+
allocator->allocateList<executorch::aten::DimOrderType>(tensor.dim());
710712
if (dim_order_ptr == nullptr) {
711713
return Error::MemoryAllocationFailed;
712714
}

0 commit comments

Comments
 (0)