@@ -144,10 +144,12 @@ class BackendDelegate final {
144
144
CompileSpec** out_spec) {
145
145
auto number_of_compile_specs = compile_specs_in_program->size ();
146
146
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
+ }
151
153
152
154
// Initialize the spec list for each method spec
153
155
for (size_t j = 0 ; j < number_of_compile_specs; j++) {
@@ -226,8 +228,10 @@ Result<InstructionArgs> gen_instruction_arguments(
226
228
EValue* values,
227
229
size_t num_args,
228
230
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
+ }
231
235
for (size_t i = 0 ; i < num_args; ++i) {
232
236
int32_t arg_idx = arg_idxs[i];
233
237
ET_CHECK_OR_RETURN_ERROR (
@@ -287,8 +291,10 @@ Error Method::parse_values() {
287
291
ET_CHECK_OR_RETURN_ERROR (
288
292
flatbuffer_values != nullptr , InvalidProgram, " Missing values" );
289
293
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
+ }
292
298
293
299
// n_value_ counts the number of successfully-initialized values for ~Method()
294
300
// to clean up, and is incremented at the bottom of the loop. This makes it
@@ -510,17 +516,23 @@ Error Method::resolve_operator(
510
516
511
517
// resolve tensor meta
512
518
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
+
515
524
size_t count = 0 ;
516
525
for (size_t i = 0 ; i < n_args; i++) {
517
526
EValue* eval = args[i];
518
527
// handle tensor list as well
519
528
if (eval->isTensor ()) {
520
529
auto tensor = eval->toTensor ();
521
530
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
+ }
524
536
size_t size = tensor.dim ();
525
537
err = get_dim_order (tensor, dim_order_ptr, size);
526
538
ET_CHECK_OR_RETURN_ERROR (
@@ -554,8 +566,11 @@ Result<Method> Method::load(
554
566
MemoryAllocator* temp_allocator = memory_manager->temp_allocator ();
555
567
if (temp_allocator == nullptr ) {
556
568
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
+ }
559
574
new (platform_allocator) PlatformMemoryAllocator ();
560
575
temp_allocator = platform_allocator;
561
576
}
@@ -599,8 +614,10 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
599
614
ET_CHECK_OR_RETURN_ERROR (
600
615
delegates != nullptr , InvalidProgram, " Missing delegates field" );
601
616
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
+ }
604
621
605
622
// n_delegate_ counts the number of successfully-initialized delegates for
606
623
// ~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) {
628
645
ET_CHECK_OR_RETURN_ERROR (
629
646
chains != nullptr && chains->size () > 0 , InvalidProgram, " No chains" );
630
647
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
+ }
633
652
634
653
// Try resolving all operators before failing, to make it easier to debug
635
654
// multiple problems at once.
@@ -644,10 +663,16 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
644
663
" Missing instructions in chain %zu" ,
645
664
i);
646
665
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
+ }
651
676
652
677
// Set up the argument lists ahead of time and store pointers to them to
653
678
// use when the instructions are called
0 commit comments