@@ -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 (
@@ -553,9 +565,10 @@ Result<Method> Method::load(
553565 EventTracer* event_tracer) {
554566 MemoryAllocator* temp_allocator = memory_manager->temp_allocator ();
555567 if (temp_allocator == nullptr ) {
556- PlatformMemoryAllocator* platform_allocator =
557- ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR (
558- memory_manager->method_allocator (), PlatformMemoryAllocator);
568+ PlatformMemoryAllocator* platform_allocator = memory_manager->method_allocator ()->allocateInstance <PlatformMemoryAllocator>();
569+ if (platform_allocator == nullptr ) {
570+ return Error::MemoryAllocationFailed;
571+ }
559572 new (platform_allocator) PlatformMemoryAllocator ();
560573 temp_allocator = platform_allocator;
561574 }
@@ -599,8 +612,10 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
599612 ET_CHECK_OR_RETURN_ERROR (
600613 delegates != nullptr , InvalidProgram, " Missing delegates field" );
601614 size_t n_delegate = delegates->size ();
602- delegates_ = ET_ALLOCATE_LIST_OR_RETURN_ERROR (
603- method_allocator, BackendDelegate, n_delegate);
615+ delegates_ = method_allocator->allocateList <BackendDelegate>(n_delegate);
616+ if (delegates_ == nullptr ) {
617+ return Error::MemoryAllocationFailed;
618+ }
604619
605620 // n_delegate_ counts the number of successfully-initialized delegates for
606621 // ~Method() to clean up, and is incremented at the bottom of the loop. This
@@ -628,8 +643,10 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
628643 ET_CHECK_OR_RETURN_ERROR (
629644 chains != nullptr && chains->size () > 0 , InvalidProgram, " No chains" );
630645 n_chains_ = chains->size ();
631- chains_ =
632- ET_ALLOCATE_LIST_OR_RETURN_ERROR (method_allocator, Chain, n_chains_);
646+ chains_ = method_allocator->allocateList <Chain>(n_chains_);
647+ if (chains_ == nullptr ) {
648+ return Error::MemoryAllocationFailed;
649+ }
633650
634651 // Try resolving all operators before failing, to make it easier to debug
635652 // multiple problems at once.
@@ -644,10 +661,16 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
644661 " Missing instructions in chain %zu" ,
645662 i);
646663 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);
664+ auto chain_instruction_kernels =
665+ method_allocator->allocateList <OpFunction>(num_instructions);
666+ if (chain_instruction_kernels == nullptr ) {
667+ return Error::MemoryAllocationFailed;
668+ }
669+ auto chain_instruction_arg_lists =
670+ method_allocator->allocateList <InstructionArgs>(num_instructions);
671+ if (chain_instruction_arg_lists == nullptr ) {
672+ return Error::MemoryAllocationFailed;
673+ }
651674
652675 // Set up the argument lists ahead of time and store pointers to them to
653676 // use when the instructions are called
0 commit comments