Skip to content

Commit 10aeb56

Browse files
authored
Remove ET_ALLOCATE_LIST_OR_RETURN_ERROR from all core code for MSVC windows
Differential Revision: D64952858 Pull Request resolved: #6502
1 parent 2080877 commit 10aeb56

File tree

3 files changed

+68
-33
lines changed

3 files changed

+68
-33
lines changed

runtime/executor/method.cpp

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ class BackendDelegate final {
144144
CompileSpec** out_spec) {
145145
auto number_of_compile_specs = compile_specs_in_program->size();
146146

147-
CompileSpec* compile_specs_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
148-
backend_init_context.get_runtime_allocator(),
149-
CompileSpec,
150-
number_of_compile_specs);
147+
CompileSpec* compile_specs_list =
148+
backend_init_context.get_runtime_allocator()->allocateList<CompileSpec>(
149+
number_of_compile_specs);
150+
if (compile_specs_list == nullptr) {
151+
return Error::MemoryAllocationFailed;
152+
}
151153

152154
// Initialize the spec list for each method spec
153155
for (size_t j = 0; j < number_of_compile_specs; j++) {
@@ -226,8 +228,10 @@ Result<InstructionArgs> gen_instruction_arguments(
226228
EValue* values,
227229
size_t num_args,
228230
const int32_t* arg_idxs) {
229-
EValue** arg_list =
230-
ET_ALLOCATE_LIST_OR_RETURN_ERROR(method_allocator, EValue*, num_args);
231+
EValue** arg_list = method_allocator->allocateList<EValue*>(num_args);
232+
if (arg_list == nullptr) {
233+
return Error::MemoryAllocationFailed;
234+
}
231235
for (size_t i = 0; i < num_args; ++i) {
232236
int32_t arg_idx = arg_idxs[i];
233237
ET_CHECK_OR_RETURN_ERROR(
@@ -287,8 +291,10 @@ Error Method::parse_values() {
287291
ET_CHECK_OR_RETURN_ERROR(
288292
flatbuffer_values != nullptr, InvalidProgram, "Missing values");
289293
size_t n_value = flatbuffer_values->size();
290-
values_ = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
291-
memory_manager_->method_allocator(), EValue, n_value);
294+
values_ = memory_manager_->method_allocator()->allocateList<EValue>(n_value);
295+
if (values_ == nullptr) {
296+
return Error::MemoryAllocationFailed;
297+
}
292298

293299
// n_value_ counts the number of successfully-initialized values for ~Method()
294300
// to clean up, and is incremented at the bottom of the loop. This makes it
@@ -510,17 +516,23 @@ Error Method::resolve_operator(
510516

511517
// resolve tensor meta
512518
auto method_allocator = memory_manager_->method_allocator();
513-
TensorMeta* meta =
514-
ET_ALLOCATE_LIST_OR_RETURN_ERROR(method_allocator, TensorMeta, n_args);
519+
TensorMeta* meta = method_allocator->allocateList<TensorMeta>(n_args);
520+
if (meta == nullptr) {
521+
return Error::MemoryAllocationFailed;
522+
}
523+
515524
size_t count = 0;
516525
for (size_t i = 0; i < n_args; i++) {
517526
EValue* eval = args[i];
518527
// handle tensor list as well
519528
if (eval->isTensor()) {
520529
auto tensor = eval->toTensor();
521530
meta[count].dtype_ = tensor.scalar_type();
522-
exec_aten::DimOrderType* dim_order_ptr = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
523-
method_allocator, exec_aten::DimOrderType, tensor.dim());
531+
exec_aten::DimOrderType* dim_order_ptr =
532+
method_allocator->allocateList<exec_aten::DimOrderType>(tensor.dim());
533+
if (dim_order_ptr == nullptr) {
534+
return Error::MemoryAllocationFailed;
535+
}
524536
size_t size = tensor.dim();
525537
err = get_dim_order(tensor, dim_order_ptr, size);
526538
ET_CHECK_OR_RETURN_ERROR(
@@ -554,8 +566,11 @@ Result<Method> Method::load(
554566
MemoryAllocator* temp_allocator = memory_manager->temp_allocator();
555567
if (temp_allocator == nullptr) {
556568
PlatformMemoryAllocator* platform_allocator =
557-
ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(
558-
memory_manager->method_allocator(), PlatformMemoryAllocator);
569+
memory_manager->method_allocator()
570+
->allocateInstance<PlatformMemoryAllocator>();
571+
if (platform_allocator == nullptr) {
572+
return Error::MemoryAllocationFailed;
573+
}
559574
new (platform_allocator) PlatformMemoryAllocator();
560575
temp_allocator = platform_allocator;
561576
}
@@ -599,8 +614,10 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
599614
ET_CHECK_OR_RETURN_ERROR(
600615
delegates != nullptr, InvalidProgram, "Missing delegates field");
601616
size_t n_delegate = delegates->size();
602-
delegates_ = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
603-
method_allocator, BackendDelegate, n_delegate);
617+
delegates_ = method_allocator->allocateList<BackendDelegate>(n_delegate);
618+
if (delegates_ == nullptr) {
619+
return Error::MemoryAllocationFailed;
620+
}
604621

605622
// n_delegate_ counts the number of successfully-initialized delegates for
606623
// ~Method() to clean up, and is incremented at the bottom of the loop. This
@@ -628,8 +645,10 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
628645
ET_CHECK_OR_RETURN_ERROR(
629646
chains != nullptr && chains->size() > 0, InvalidProgram, "No chains");
630647
n_chains_ = chains->size();
631-
chains_ =
632-
ET_ALLOCATE_LIST_OR_RETURN_ERROR(method_allocator, Chain, n_chains_);
648+
chains_ = method_allocator->allocateList<Chain>(n_chains_);
649+
if (chains_ == nullptr) {
650+
return Error::MemoryAllocationFailed;
651+
}
633652

634653
// Try resolving all operators before failing, to make it easier to debug
635654
// multiple problems at once.
@@ -644,10 +663,16 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
644663
"Missing instructions in chain %zu",
645664
i);
646665
auto num_instructions = s_instructions->size();
647-
auto chain_instruction_kernels = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
648-
method_allocator, OpFunction, num_instructions);
649-
auto chain_instruction_arg_lists = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
650-
method_allocator, InstructionArgs, num_instructions);
666+
auto chain_instruction_kernels =
667+
method_allocator->allocateList<OpFunction>(num_instructions);
668+
if (chain_instruction_kernels == nullptr) {
669+
return Error::MemoryAllocationFailed;
670+
}
671+
auto chain_instruction_arg_lists =
672+
method_allocator->allocateList<InstructionArgs>(num_instructions);
673+
if (chain_instruction_arg_lists == nullptr) {
674+
return Error::MemoryAllocationFailed;
675+
}
651676

652677
// Set up the argument lists ahead of time and store pointers to them to
653678
// use when the instructions are called

runtime/executor/tensor_parser.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ parseListOptionalType(
3737
const flatbuffers::Vector<int32_t>* value_indices,
3838
EValue* values_,
3939
MemoryManager* memory_manager) {
40-
auto* evalp_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
41-
memory_manager->method_allocator(), EValue*, value_indices->size());
42-
43-
auto* optional_tensor_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
44-
memory_manager->method_allocator(),
45-
executorch::aten::optional<T>,
40+
auto* evalp_list = memory_manager->method_allocator()->allocateList<EValue*>(
4641
value_indices->size());
42+
if (evalp_list == nullptr) {
43+
return Error::MemoryAllocationFailed;
44+
}
45+
46+
auto* optional_tensor_list =
47+
memory_manager->method_allocator()
48+
->allocateList<executorch::aten::optional<T>>(value_indices->size());
49+
if (optional_tensor_list == nullptr) {
50+
return Error::MemoryAllocationFailed;
51+
}
4752

4853
size_t output_idx = 0;
4954
// For each index look up the corresponding EValue (which has been

runtime/executor/tensor_parser_exec_aten.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ ET_NODISCARD Result<BoxedEvalueList<exec_aten::Tensor>> parseTensorList(
7474
MemoryManager* memory_manager) {
7575
EXECUTORCH_SCOPE_PROF("TensorParser::parseTensorList");
7676

77-
auto* tensor_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
78-
memory_manager->method_allocator(),
79-
exec_aten::Tensor,
77+
auto* tensor_list =
78+
memory_manager->method_allocator()->allocateList<exec_aten::Tensor>(
79+
tensor_indices->size());
80+
if (tensor_list == nullptr) {
81+
return Error::MemoryAllocationFailed;
82+
}
83+
auto* evalp_list = memory_manager->method_allocator()->allocateList<EValue*>(
8084
tensor_indices->size());
81-
auto* evalp_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR(
82-
memory_manager->method_allocator(), EValue*, tensor_indices->size());
85+
if (evalp_list == nullptr) {
86+
return Error::MemoryAllocationFailed;
87+
}
8388

8489
// For each tensor index look up the corresponding Tensor (which has been
8590
// already allocated) and stick it in the list.

0 commit comments

Comments
 (0)