@@ -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
0 commit comments