@@ -44,7 +44,8 @@ class BackendDelegate final {
44
44
*
45
45
* @param[in] delegate The serialized backend delegate to load.
46
46
* @param[in] program The serialized program to load from.
47
- * @param[in] runtime_allocator Allocator for creating runtime C++ objects.
47
+ * @param[in] backend_init_context The context pointer to pass to the
48
+ * backend's init() method.
48
49
* @param[out] out The BackendDelegate to initialize.
49
50
*
50
51
* @returns Error::Ok if the initialization succeeded, or an error otherwise.
@@ -212,12 +213,12 @@ struct Chain {
212
213
namespace {
213
214
214
215
Result<InstructionArgs> gen_instruction_arguments (
215
- MemoryAllocator* runtime_allocator ,
216
+ MemoryAllocator* method_allocator ,
216
217
EValue* values,
217
218
size_t num_args,
218
219
const int32_t * arg_idxs) {
219
220
EValue** arg_list =
220
- ET_ALLOCATE_LIST_OR_RETURN_ERROR (runtime_allocator , EValue*, num_args);
221
+ ET_ALLOCATE_LIST_OR_RETURN_ERROR (method_allocator , EValue*, num_args);
221
222
for (size_t i = 0 ; i < num_args; ++i) {
222
223
arg_list[i] = &values[arg_idxs[i]];
223
224
}
@@ -267,7 +268,7 @@ Error Method::parse_values() {
267
268
ET_CHECK (flatbuffer_values != nullptr );
268
269
size_t n_value = flatbuffer_values->size ();
269
270
values_ = ET_ALLOCATE_LIST_OR_RETURN_ERROR (
270
- memory_manager_->get_runtime_allocator (), EValue, n_value);
271
+ memory_manager_->method_allocator (), EValue, n_value);
271
272
272
273
// n_value_ counts the number of successfully-initialized values for ~Method()
273
274
// to clean up, and is incremented at the bottom of the loop. This makes it
@@ -299,10 +300,10 @@ Error Method::parse_values() {
299
300
// Allocate space for boxed and unboxed list representations using
300
301
// values_ as source of truth
301
302
auto * evalp_list =
302
- memory_manager_->get_runtime_allocator ()->allocateList <EValue*>(
303
+ memory_manager_->method_allocator ()->allocateList <EValue*>(
303
304
items->size ());
304
305
auto * int_list =
305
- memory_manager_->get_runtime_allocator ()->allocateList <int64_t >(
306
+ memory_manager_->method_allocator ()->allocateList <int64_t >(
306
307
items->size ());
307
308
308
309
// initialize boxed list
@@ -452,9 +453,9 @@ Error Method::resolve_operator(
452
453
populateOperatorName (op, kTempBufferSizeForName , operator_name);
453
454
454
455
// resolve tensor meta
455
- auto runtime_allocator = memory_manager_->get_runtime_allocator ();
456
+ auto method_allocator = memory_manager_->method_allocator ();
456
457
TensorMeta* meta =
457
- ET_ALLOCATE_LIST_OR_RETURN_ERROR (runtime_allocator , TensorMeta, n_args);
458
+ ET_ALLOCATE_LIST_OR_RETURN_ERROR (method_allocator , TensorMeta, n_args);
458
459
size_t count = 0 ;
459
460
for (size_t i = 0 ; i < n_args; i++) {
460
461
EValue* eval = args[i];
@@ -463,7 +464,7 @@ Error Method::resolve_operator(
463
464
auto tensor = eval->toTensor ();
464
465
meta[count].dtype_ = tensor.scalar_type ();
465
466
exec_aten::DimOrderType* dim_order_ptr = ET_ALLOCATE_LIST_OR_RETURN_ERROR (
466
- runtime_allocator , exec_aten::DimOrderType, tensor.dim ());
467
+ method_allocator , exec_aten::DimOrderType, tensor.dim ());
467
468
size_t size = tensor.dim ();
468
469
Error err = get_dim_order (tensor, dim_order_ptr, size);
469
470
ET_CHECK_OR_RETURN_ERROR (
@@ -514,7 +515,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
514
515
init_state_ =
515
516
InitializationState::InitializationFailed; // Until proven otherwise
516
517
serialization_plan_ = s_plan;
517
- auto runtime_allocator = memory_manager_->get_runtime_allocator ();
518
+ auto method_allocator = memory_manager_->method_allocator ();
518
519
519
520
{
520
521
// Parse the elements of the values_ array.
@@ -530,7 +531,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
530
531
ET_CHECK (delegates != nullptr );
531
532
size_t n_delegate = delegates->size ();
532
533
delegates_ = ET_ALLOCATE_LIST_OR_RETURN_ERROR (
533
- runtime_allocator , BackendDelegate, n_delegate);
534
+ method_allocator , BackendDelegate, n_delegate);
534
535
535
536
// n_delegate_ counts the number of successfully-initialized delegates for
536
537
// ~Method() to clean up, and is incremented at the bottom of the loop. This
@@ -539,7 +540,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
539
540
540
541
for (size_t i = 0 ; i < n_delegate; ++i) {
541
542
const auto & delegate = *delegates->Get (i);
542
- BackendInitContext backend_init_context (runtime_allocator );
543
+ BackendInitContext backend_init_context (method_allocator );
543
544
Error err = BackendDelegate::Init (
544
545
delegate, program_, backend_init_context, &delegates_[i]);
545
546
if (err != Error::Ok) {
@@ -559,15 +560,15 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
559
560
n_chains_ = chains->size ();
560
561
561
562
chains_ =
562
- ET_ALLOCATE_LIST_OR_RETURN_ERROR (runtime_allocator , Chain, n_chains_);
563
+ ET_ALLOCATE_LIST_OR_RETURN_ERROR (method_allocator , Chain, n_chains_);
563
564
int32_t num_instructions_missing_op = 0 ;
564
565
for (size_t i = 0 ; i < n_chains_; ++i) {
565
566
auto s_chain = chains->Get (i);
566
567
auto num_instructions = s_chain->instructions ()->size ();
567
568
auto chain_instruction_kernels = ET_ALLOCATE_LIST_OR_RETURN_ERROR (
568
- runtime_allocator , OpFunction, num_instructions);
569
+ method_allocator , OpFunction, num_instructions);
569
570
auto chain_instruction_arg_lists = ET_ALLOCATE_LIST_OR_RETURN_ERROR (
570
- runtime_allocator , InstructionArgs, num_instructions);
571
+ method_allocator , InstructionArgs, num_instructions);
571
572
572
573
// Set up the argument lists ahead of time and store pointers to them to
573
574
// use when the instructions are called
@@ -579,7 +580,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
579
580
const auto arg_idxs =
580
581
instruction->instr_args_as_KernelCall ()->args ();
581
582
auto res = gen_instruction_arguments (
582
- runtime_allocator , values_, arg_idxs->size (), arg_idxs->data ());
583
+ method_allocator , values_, arg_idxs->size (), arg_idxs->data ());
583
584
if (!res.ok ()) {
584
585
return res.error ();
585
586
}
@@ -600,7 +601,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
600
601
const auto arg_idxs =
601
602
instruction->instr_args_as_DelegateCall ()->args ();
602
603
auto res = gen_instruction_arguments (
603
- runtime_allocator , values_, arg_idxs->size (), arg_idxs->data ());
604
+ method_allocator , values_, arg_idxs->size (), arg_idxs->data ());
604
605
if (!res.ok ()) {
605
606
return res.error ();
606
607
}
0 commit comments