@@ -52,7 +52,7 @@ class BackendDelegate final {
52
52
static Error Init (
53
53
const executorch_flatbuffer::BackendDelegate& delegate,
54
54
const Program* program,
55
- MemoryAllocator* runtime_allocator ,
55
+ BackendInitContext& backend_init_context ,
56
56
BackendDelegate* out) {
57
57
// Look up the backend.
58
58
const char * backend_id = delegate.id ()->c_str ();
@@ -78,7 +78,7 @@ class BackendDelegate final {
78
78
// Parse compilation specs from program
79
79
CompileSpec* compile_specs;
80
80
Error err = PopulateCompileSpecs (
81
- delegate.compile_specs (), runtime_allocator , &compile_specs);
81
+ delegate.compile_specs (), backend_init_context , &compile_specs);
82
82
if (err != Error::Ok) {
83
83
ET_LOG (Error, " Failed to get compile specs for backend %s" , backend_id);
84
84
return err;
@@ -93,9 +93,9 @@ class BackendDelegate final {
93
93
94
94
// Initialize the delegate.
95
95
Result<DelegateHandle*> handle = backend->init (
96
+ backend_init_context,
96
97
&out->segment_ ,
97
- ArrayRef<CompileSpec>(compile_specs, num_compile_specs),
98
- runtime_allocator);
98
+ ArrayRef<CompileSpec>(compile_specs, num_compile_specs));
99
99
if (!handle.ok ()) {
100
100
ET_LOG (
101
101
Error,
@@ -135,12 +135,14 @@ class BackendDelegate final {
135
135
static Error PopulateCompileSpecs (
136
136
const flatbuffers::Vector<flatbuffers::Offset<
137
137
executorch_flatbuffer::CompileSpec>>* compile_specs_in_program,
138
- torch::executor::MemoryAllocator* runtime_allocator ,
138
+ BackendInitContext& backend_init_context ,
139
139
CompileSpec** out_spec) {
140
140
auto number_of_compile_specs = compile_specs_in_program->size ();
141
141
142
142
CompileSpec* compile_specs_list = ET_ALLOCATE_LIST_OR_RETURN_ERROR (
143
- runtime_allocator, CompileSpec, number_of_compile_specs);
143
+ backend_init_context.get_runtime_allocator (),
144
+ CompileSpec,
145
+ number_of_compile_specs);
144
146
145
147
// Initialize the spec list for each method spec
146
148
for (size_t j = 0 ; j < number_of_compile_specs; j++) {
@@ -537,14 +539,15 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
537
539
538
540
for (size_t i = 0 ; i < n_delegate; ++i) {
539
541
const auto & delegate = *delegates->Get (i);
542
+ BackendInitContext backend_init_context (runtime_allocator);
540
543
Error err = BackendDelegate::Init (
541
- delegate, program_, runtime_allocator , &delegates_[i]);
544
+ delegate, program_, backend_init_context , &delegates_[i]);
542
545
if (err != Error::Ok) {
543
546
return err;
544
547
}
545
548
// ~Method() will try to clean up n_delegate_ entries in the delegates_
546
- // array. Only increment this once we know the entry is valid, so that we
547
- // don't try to clean up an uninitialized entry.
549
+ // array. Only increment this once we know the entry is valid, so that
550
+ // we don't try to clean up an uninitialized entry.
548
551
n_delegate_ = i + 1 ;
549
552
}
550
553
}
@@ -1035,8 +1038,8 @@ Error Method::execute() {
1035
1038
NotSupported,
1036
1039
" Cannot execute until method has been initialized." );
1037
1040
1038
- // Chains are executed sequentially today, but future async designs may branch
1039
- // and run many in parallel or out of order.
1041
+ // Chains are executed sequentially today, but future async designs may
1042
+ // branch and run many in parallel or out of order.
1040
1043
for (step_state_.chain_idx = 0 ; step_state_.chain_idx < n_chains_;
1041
1044
++step_state_.chain_idx ) {
1042
1045
Chain& chain = chains_[step_state_.chain_idx ];
0 commit comments